Skip to content

Commit e43d966

Browse files
committed
feat(utils): add foreignKeys function
1 parent b125f14 commit e43d966

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/sqlite-utils/src/pragma.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ export async function checkIntegrity(db: Kysely<any>): Promise<boolean> {
1313
return rows[0].integrity_check === 'ok'
1414
}
1515

16+
/**
17+
* control whether to enable foreign keys
18+
*/
19+
export async function foreignKeys(db: Kysely<any>, enable: boolean): Promise<void> {
20+
await sql`PRAGMA foreign_keys = ${sql.raw(`${enable}`)}`.execute(db)
21+
}
22+
1623
/**
1724
* get or set user_version pragma
1825
*/

packages/sqlite-utils/src/precompile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Compilable, CompiledQuery, RootOperationNode } from 'kysely'
22

33
export type QueryBuilderOutput<QB> = QB extends Compilable<infer O> ? O : never
44

5-
type SetParam<O, T extends Record<string, any>> = {
5+
export type SetParamFn<O, T extends Record<string, any>> = {
66
/**
77
* query builder for setup params
88
*/
@@ -17,7 +17,7 @@ type SetParam<O, T extends Record<string, any>> = {
1717
* @param processRootOperatorNode process `query` in {@link CompiledQuery},
1818
* default is `(node) => ({ kind: node.kind })`
1919
*/
20-
type CompileFn<O, T extends Record<string, any>> = (
20+
export type CompileFn<O, T extends Record<string, any>> = (
2121
param: T,
2222
processRootOperatorNode?: ((node: RootOperationNode) => RootOperationNode)
2323
) => CompiledQuery<QueryBuilderOutput<O>>
@@ -57,7 +57,7 @@ export function precompileQuery<O>(
5757
* @returns function to {@link CompileFn compile}
5858
*/
5959
setParam: <T extends Record<string, any>>(
60-
paramBuilder: ({ param, qb }: SetParam<O, T>) => Compilable<O>,
60+
paramBuilder: ({ param, qb }: SetParamFn<O, T>) => Compilable<O>,
6161
): CompileFn<O, T> => {
6262
let compiled: CompiledQuery<Compilable<O>>
6363
return (param, processRootOperatorNode) => {

0 commit comments

Comments
 (0)