2024-07-01 03:36:34 -05:00
|
|
|
import { type CreateSubjectToken, SubjectTokens } from '@logto/schemas';
|
2024-06-21 21:31:27 -05:00
|
|
|
import type { CommonQueryMethods } from '@silverhand/slonik';
|
|
|
|
|
2024-07-01 03:36:34 -05:00
|
|
|
import { buildFindEntityByIdWithPool } from '#src/database/find-entity-by-id.js';
|
2024-06-21 21:31:27 -05:00
|
|
|
import { buildInsertIntoWithPool } from '#src/database/insert-into.js';
|
2024-07-01 03:36:34 -05:00
|
|
|
import { buildUpdateWhereWithPool } from '#src/database/update-where.js';
|
|
|
|
import { type OmitAutoSetFields } from '#src/utils/sql.js';
|
2024-06-21 21:31:27 -05:00
|
|
|
|
|
|
|
export const createSubjectTokenQueries = (pool: CommonQueryMethods) => {
|
|
|
|
const insertSubjectToken = buildInsertIntoWithPool(pool)(SubjectTokens, {
|
|
|
|
returning: true,
|
|
|
|
});
|
|
|
|
|
2024-07-01 03:36:34 -05:00
|
|
|
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' });
|
|
|
|
|
2024-06-21 21:31:27 -05:00
|
|
|
return {
|
|
|
|
insertSubjectToken,
|
2024-07-01 03:36:34 -05:00
|
|
|
findSubjectToken,
|
|
|
|
updateSubjectTokenById,
|
2024-06-21 21:31:27 -05:00
|
|
|
};
|
|
|
|
};
|