0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00
logto/packages/core/src/queries/roles.ts
simeng-li fb6a1dc236
test(core): add ut for queires (#287)
* test(core): add ut for queires

add ut for queries

* test(core): add user query ut

add user query ut

* fix(core): remove test code

remove console log
2022-02-28 14:30:27 +08:00

20 lines
599 B
TypeScript

import { Roles, Role } from '@logto/schemas';
import { sql } from 'slonik';
import pool from '@/database/pool';
import { convertToIdentifiers } from '@/database/utils';
const { table, fields } = convertToIdentifiers(Roles);
export const findAllRoles = async () =>
pool.any<Role>(sql`
select ${sql.join(Object.values(fields), sql`, `)}
from ${table}
`);
export const findRolesByRoleNames = async (roleNames: string[]) =>
pool.any<Role>(sql`
select ${sql.join(Object.values(fields), sql`, `)}
from ${table}
where ${fields.name} in (${sql.join(roleNames, sql`, `)})
`);