0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00
logto/packages/core/src/queries/subject-token.ts

28 lines
1 KiB
TypeScript

import { type CreateSubjectToken, SubjectTokens } from '@logto/schemas';
import type { CommonQueryMethods } from '@silverhand/slonik';
import { buildFindEntityByIdWithPool } from '#src/database/find-entity-by-id.js';
import { buildInsertIntoWithPool } from '#src/database/insert-into.js';
import { buildUpdateWhereWithPool } from '#src/database/update-where.js';
import { type OmitAutoSetFields } from '#src/utils/sql.js';
export const createSubjectTokenQueries = (pool: CommonQueryMethods) => {
const insertSubjectToken = buildInsertIntoWithPool(pool)(SubjectTokens, {
returning: true,
});
const findSubjectToken = buildFindEntityByIdWithPool(pool)(SubjectTokens);
const updateSubjectToken = buildUpdateWhereWithPool(pool)(SubjectTokens, true);
const updateSubjectTokenById = async (
id: string,
set: Partial<OmitAutoSetFields<CreateSubjectToken>>
) => updateSubjectToken({ set, where: { id }, jsonbMode: 'merge' });
return {
insertSubjectToken,
findSubjectToken,
updateSubjectTokenById,
};
};