@@ -36,7 +36,6 @@ type CompileFn<O, T extends Record<string, any>> = (
36
36
37
37
/**
38
38
* create precompiled query,
39
- * inspired by {@link https://github.com/jtlapp/kysely-params kysely-params},
40
39
* included in `SqliteBuilder`
41
40
* @param queryBuilder query builder without params
42
41
* @param serialize custom parameter value serializer
@@ -45,8 +44,8 @@ type CompileFn<O, T extends Record<string, any>> = (
45
44
* const query = precompileQuery(
46
45
* db.selectFrom('test').selectAll(),
47
46
* ).setParam<{ name: string }>((qb, param) =>
48
- * qb.where('name', '=', param('name')) ,
49
- * )
47
+ * qb.where('name', '=', param('name'),
48
+ * ))
50
49
* const compiledQuery = query({ name: 'test' })
51
50
* // {
52
51
* // sql: 'select * from "test" where "name" = ?',
@@ -83,9 +82,10 @@ export function precompileQuery<O>(
83
82
}
84
83
return {
85
84
...compiled ,
86
- parameters : compiled . parameters . map ( p => ( typeof p === 'string' && p . startsWith ( '__pre_' ) )
87
- ? serialize ( param [ p . slice ( 6 ) ] )
88
- : p ,
85
+ parameters : compiled . parameters . map ( p =>
86
+ ( typeof p === 'string' && p . startsWith ( '__pre_' ) )
87
+ ? serialize ( param [ p . slice ( 6 ) ] )
88
+ : p ,
89
89
) ,
90
90
}
91
91
}
@@ -97,9 +97,12 @@ export function precompileQuery<O>(
97
97
* check integrity_check pragma
98
98
*/
99
99
export async function checkIntegrity ( db : Kysely < any > ) : Promise < boolean > {
100
- const result = await sql `PRAGMA integrity_check` . execute ( db )
100
+ const { rows } = await sql `PRAGMA integrity_check` . execute ( db )
101
+ if ( ! rows . length ) {
102
+ throw new Error ( 'fail to check integrity' )
103
+ }
101
104
// @ts -expect-error result
102
- return result . rows [ 0 ] . integrity_check === 'ok'
105
+ return rows [ 0 ] . integrity_check === 'ok'
103
106
}
104
107
105
108
/**
@@ -113,9 +116,12 @@ export async function getOrSetDBVersion(
113
116
await sql `PRAGMA user_version = ${ sql . raw ( `${ version } ` ) } ` . execute ( db )
114
117
return version
115
118
}
116
- const result = await sql `PRAGMA user_version` . execute ( db )
117
- // @ts -expect-error result
118
- return result . rows [ 0 ] . user_version
119
+ const { rows } = await sql `PRAGMA user_version` . execute ( db )
120
+ if ( ! rows . length ) {
121
+ throw new Error ( 'fail to get DBVersion' )
122
+ }
123
+ // @ts -expect-error get user version
124
+ return rows [ 0 ] . user_version
119
125
}
120
126
121
127
export type SavePoint = {
0 commit comments