diff options
Diffstat (limited to 'lib/admin-users/repository.ts')
| -rw-r--r-- | lib/admin-users/repository.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/admin-users/repository.ts b/lib/admin-users/repository.ts index aff2da28..63e98b4e 100644 --- a/lib/admin-users/repository.ts +++ b/lib/admin-users/repository.ts @@ -49,6 +49,30 @@ export async function selectUsersWithCompanyAndRoles( return rows } +export async function selectUsers( + tx: PgTransaction<any, any, any>, + params: { + where?: any + orderBy?: (ReturnType<typeof asc> | ReturnType<typeof desc>)[] + offset?: number + limit?: number + } +) { + const { where, orderBy, offset = 0, limit = 10 } = params + + // 1) 쿼리 빌더 생성 + const queryBuilder = tx + .select() + .from(users) + .where(where) + .orderBy(...(orderBy ?? [])) + .offset(offset) + .limit(limit) + + const rows = await queryBuilder + return rows +} + /** 총 개수 count */ export async function countUsers( @@ -59,6 +83,14 @@ export async function countUsers( return res[0]?.count ?? 0; } +export async function countUsersSimple( + tx: PgTransaction<any, any, any>, + where?: any +) { + const res = await tx.select({ count: count() }).from(users).where(where); + return res[0]?.count ?? 0; +} + export async function groupByCompany( tx: PgTransaction<any, any, any>, ) { |
