kysely 0.19.12 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +2 -0
- package/dist/cjs/dialect/mysql/mysql-query-compiler.d.ts +5 -0
- package/dist/cjs/dialect/mysql/mysql-query-compiler.js +16 -0
- package/dist/cjs/dialect/postgres/postgres-introspector.js +7 -1
- package/dist/cjs/dialect/postgres/postgres-query-compiler.d.ts +1 -3
- package/dist/cjs/dialect/postgres/postgres-query-compiler.js +3 -8
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +2 -0
- package/dist/cjs/dialect/sqlite/sqlite-query-compiler.d.ts +3 -0
- package/dist/cjs/dialect/sqlite/sqlite-query-compiler.js +10 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/operation-node/create-table-node.d.ts +6 -1
- package/dist/cjs/operation-node/create-table-node.js +16 -0
- package/dist/cjs/operation-node/delete-query-node.d.ts +3 -0
- package/dist/cjs/operation-node/delete-query-node.js +6 -0
- package/dist/cjs/operation-node/explain-node.d.ts +16 -0
- package/dist/cjs/operation-node/explain-node.js +19 -0
- package/dist/cjs/operation-node/insert-query-node.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +14 -0
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/select-query-node.d.ts +3 -0
- package/dist/cjs/operation-node/select-query-node.js +6 -0
- package/dist/cjs/operation-node/update-query-node.d.ts +3 -0
- package/dist/cjs/operation-node/update-query-node.js +6 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +19 -1
- package/dist/cjs/query-builder/delete-query-builder.js +24 -0
- package/dist/cjs/query-builder/function-builder.d.ts +3 -3
- package/dist/cjs/query-builder/insert-query-builder.d.ts +20 -2
- package/dist/cjs/query-builder/insert-query-builder.js +26 -0
- package/dist/cjs/query-builder/select-query-builder.d.ts +38 -1
- package/dist/cjs/query-builder/select-query-builder.js +45 -2
- package/dist/cjs/query-builder/update-query-builder.d.ts +20 -1
- package/dist/cjs/query-builder/update-query-builder.js +25 -0
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +6 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +58 -3
- package/dist/cjs/raw-builder/sql.d.ts +96 -96
- package/dist/cjs/raw-builder/sql.js +0 -96
- package/dist/cjs/schema/create-table-builder.d.ts +54 -0
- package/dist/cjs/schema/create-table-builder.js +64 -0
- package/dist/cjs/util/explainable.d.ts +5 -0
- package/dist/cjs/util/explainable.js +2 -0
- package/dist/esm/dialect/mysql/mysql-introspector.js +2 -0
- package/dist/esm/dialect/mysql/mysql-query-compiler.d.ts +5 -0
- package/dist/esm/dialect/mysql/mysql-query-compiler.js +16 -0
- package/dist/esm/dialect/postgres/postgres-introspector.js +7 -1
- package/dist/esm/dialect/postgres/postgres-query-compiler.d.ts +1 -3
- package/dist/esm/dialect/postgres/postgres-query-compiler.js +3 -8
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +2 -0
- package/dist/esm/dialect/sqlite/sqlite-query-compiler.d.ts +3 -0
- package/dist/esm/dialect/sqlite/sqlite-query-compiler.js +10 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/operation-node/create-table-node.d.ts +6 -1
- package/dist/esm/operation-node/create-table-node.js +16 -0
- package/dist/esm/operation-node/delete-query-node.d.ts +3 -0
- package/dist/esm/operation-node/delete-query-node.js +6 -0
- package/dist/esm/operation-node/explain-node.d.ts +16 -0
- package/dist/esm/operation-node/explain-node.js +17 -0
- package/dist/esm/operation-node/insert-query-node.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +14 -0
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-visitor.js +1 -0
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/select-query-node.d.ts +3 -0
- package/dist/esm/operation-node/select-query-node.js +6 -0
- package/dist/esm/operation-node/update-query-node.d.ts +3 -0
- package/dist/esm/operation-node/update-query-node.js +6 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +19 -1
- package/dist/esm/query-builder/delete-query-builder.js +24 -0
- package/dist/esm/query-builder/function-builder.d.ts +3 -3
- package/dist/esm/query-builder/insert-query-builder.d.ts +20 -2
- package/dist/esm/query-builder/insert-query-builder.js +26 -0
- package/dist/esm/query-builder/select-query-builder.d.ts +38 -1
- package/dist/esm/query-builder/select-query-builder.js +45 -2
- package/dist/esm/query-builder/update-query-builder.d.ts +20 -1
- package/dist/esm/query-builder/update-query-builder.js +25 -0
- package/dist/esm/query-compiler/default-query-compiler.d.ts +6 -0
- package/dist/esm/query-compiler/default-query-compiler.js +58 -3
- package/dist/esm/raw-builder/sql.d.ts +96 -96
- package/dist/esm/raw-builder/sql.js +0 -96
- package/dist/esm/schema/create-table-builder.d.ts +54 -0
- package/dist/esm/schema/create-table-builder.js +64 -0
- package/dist/esm/util/explainable.d.ts +5 -0
- package/dist/esm/util/explainable.js +2 -0
- package/package.json +3 -1
|
@@ -1,5 +1,101 @@
|
|
|
1
1
|
import { RawBuilder } from './raw-builder.js';
|
|
2
2
|
export interface Sql {
|
|
3
|
+
/**
|
|
4
|
+
* Template tag for creating raw SQL snippets and queries.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { sql } from 'kysely'
|
|
8
|
+
*
|
|
9
|
+
* const id = 123
|
|
10
|
+
*
|
|
11
|
+
* const snippet = sql<Person[]>`select * from person where id = ${id}`
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Substitutions (the things inside `${}`) are automatically passed to the database
|
|
15
|
+
* as parameters and are NOT interpolated to the SQL string. There's no need to worry
|
|
16
|
+
* about SQL injection vulnerabilities.
|
|
17
|
+
*
|
|
18
|
+
* If you need your substitutions to be interpreted as identifiers, value literals or
|
|
19
|
+
* lists of things, see the {@link Sql.ref}, {@link Sql.table}, {@link Sql.id},
|
|
20
|
+
* {@link Sql.literal}, {@link Sql.raw} and {@link Sql.join} functions.
|
|
21
|
+
*
|
|
22
|
+
* You can pass sql snippets returned by the `sql` tag pretty much anywhere. Whenever
|
|
23
|
+
* something can't be done using the Kysely API, you should be able to drop down to
|
|
24
|
+
* raw SQL using the `sql` tag. Here's an example query that uses raw sql in a bunch
|
|
25
|
+
* of methods:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const persons = await db
|
|
29
|
+
* .selectFrom('person')
|
|
30
|
+
* .select(
|
|
31
|
+
* // If you use `sql` in a select statement, remember to call the `as`
|
|
32
|
+
* // method to give it an alias. Otherwise Kysely is not able to add
|
|
33
|
+
* // the column to the result type.
|
|
34
|
+
* sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
|
|
35
|
+
* )
|
|
36
|
+
* .where(sql`birthdate between ${date1} and ${date2}`)
|
|
37
|
+
* // Here we assume we have list of nicknames for the person
|
|
38
|
+
* // (a list of strings) and we use the PostgreSQL `@>` operator
|
|
39
|
+
* // to test if all of them are valid nicknames for the user.
|
|
40
|
+
* .where('nicknames', '@>', sql`ARRAY[${sql.join(nicknames)}]`)
|
|
41
|
+
* .orderBy(sql`concat(first_name, ' ', last_name)`)
|
|
42
|
+
* .execute()
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* The generated SQL (PostgreSQL):
|
|
46
|
+
*
|
|
47
|
+
* ```sql
|
|
48
|
+
* select concat(first_name, ' ', last_name) as "full_name"
|
|
49
|
+
* from "person"
|
|
50
|
+
* where birthdate between $1 and $2
|
|
51
|
+
* and "nicknames" @> ARRAY[$3, $4, $5, $6, $7, $8, $9, $10]
|
|
52
|
+
* order by concat(first_name, ' ', last_name)
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* SQL snippets can be executed by calling the `execute` method and passing a `Kysely`
|
|
56
|
+
* instance as the only argument:
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const result = await sql<Person[]>`select * from person`.execute(db)
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* You can merge other `sql` expressions and queries using substitutions:
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* const petName = db.selectFrom('pet').select('name').limit(1)
|
|
66
|
+
* const fullName = sql`concat(first_name, ' ', last_name)`
|
|
67
|
+
*
|
|
68
|
+
* sql`
|
|
69
|
+
* select ${fullName} as full_name, ${petName} as pet_name
|
|
70
|
+
* from person
|
|
71
|
+
* `
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* Substitutions also handle {@link ExpressionBuilder.ref},
|
|
75
|
+
* {@link DynamicModule.ref} and pretty much anything else you
|
|
76
|
+
* throw at it. Here's an example of calling a function in a
|
|
77
|
+
* type-safe way:
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* db.selectFrom('person')
|
|
81
|
+
* .select([
|
|
82
|
+
* 'first_name',
|
|
83
|
+
* 'last_name',
|
|
84
|
+
* (eb) => {
|
|
85
|
+
* // The `eb.ref` method is type-safe and only accepts
|
|
86
|
+
* // column references that are possible.
|
|
87
|
+
* const firstName = eb.ref('first_name')
|
|
88
|
+
* const lastName = eb.ref('last_name')
|
|
89
|
+
*
|
|
90
|
+
* const fullName = sql<string>`concat(${firstName}, ' ', ${lastName})`
|
|
91
|
+
* return fullName.as('full_name')
|
|
92
|
+
* }
|
|
93
|
+
* ])
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* don't know if that amount of ceremony is worth the small increase in
|
|
97
|
+
* type-safety though... But it's possible.
|
|
98
|
+
*/
|
|
3
99
|
<T = unknown>(sqlFragments: TemplateStringsArray, ...parameters: unknown[]): RawBuilder<T>;
|
|
4
100
|
/**
|
|
5
101
|
* This can be used to add runtime column references to SQL snippets.
|
|
@@ -232,100 +328,4 @@ export interface Sql {
|
|
|
232
328
|
*/
|
|
233
329
|
join(array: unknown[], separator?: RawBuilder<any>): RawBuilder<unknown>;
|
|
234
330
|
}
|
|
235
|
-
/**
|
|
236
|
-
* Template tag for creating raw SQL snippets and queries.
|
|
237
|
-
*
|
|
238
|
-
* ```ts
|
|
239
|
-
* import { sql } from 'kysely'
|
|
240
|
-
*
|
|
241
|
-
* const id = 123
|
|
242
|
-
*
|
|
243
|
-
* const snippet = sql<Person[]>`select * from person where id = ${id}`
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* Substitutions (the things inside `${}`) are automatically passed to the database
|
|
247
|
-
* as parameters and are NOT interpolated to the SQL string. There's no need to worry
|
|
248
|
-
* about SQL injection vulnerabilities.
|
|
249
|
-
*
|
|
250
|
-
* If you need your substitutions to be interpreted as identifiers, value literals or
|
|
251
|
-
* lists of things, see the {@link Sql.ref}, {@link Sql.table}, {@link Sql.id},
|
|
252
|
-
* {@link Sql.literal}, {@link Sql.raw} and {@link Sql.join} functions.
|
|
253
|
-
*
|
|
254
|
-
* You can pass sql snippets returned by the `sql` tag pretty much anywhere. Whenever
|
|
255
|
-
* something can't be done using the Kysely API, you should be able to drop down to
|
|
256
|
-
* raw SQL using the `sql` tag. Here's an example query that uses raw sql in a bunch
|
|
257
|
-
* of methods:
|
|
258
|
-
*
|
|
259
|
-
* ```ts
|
|
260
|
-
* const persons = await db
|
|
261
|
-
* .selectFrom('person')
|
|
262
|
-
* .select(
|
|
263
|
-
* // If you use `sql` in a select statement, remember to call the `as`
|
|
264
|
-
* // method to give it an alias. Otherwise Kysely is not able to add
|
|
265
|
-
* // the column to the result type.
|
|
266
|
-
* sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
|
|
267
|
-
* )
|
|
268
|
-
* .where(sql`birthdate between ${date1} and ${date2}`)
|
|
269
|
-
* // Here we assume we have list of nicknames for the person
|
|
270
|
-
* // (a list of strings) and we use the PostgreSQL `@>` operator
|
|
271
|
-
* // to test if all of them are valid nicknames for the user.
|
|
272
|
-
* .where('nicknames', '@>', sql`ARRAY[${sql.join(nicknames)}]`)
|
|
273
|
-
* .orderBy(sql`concat(first_name, ' ', last_name)`)
|
|
274
|
-
* .execute()
|
|
275
|
-
* ```
|
|
276
|
-
*
|
|
277
|
-
* The generated SQL (PostgreSQL):
|
|
278
|
-
*
|
|
279
|
-
* ```sql
|
|
280
|
-
* select concat(first_name, ' ', last_name) as "full_name"
|
|
281
|
-
* from "person"
|
|
282
|
-
* where birthdate between $1 and $2
|
|
283
|
-
* and "nicknames" @> ARRAY[$3, $4, $5, $6, $7, $8, $9, $10]
|
|
284
|
-
* order by concat(first_name, ' ', last_name)
|
|
285
|
-
* ```
|
|
286
|
-
*
|
|
287
|
-
* SQL snippets can be executed by calling the `execute` method and passing a `Kysely`
|
|
288
|
-
* instance as the only argument:
|
|
289
|
-
*
|
|
290
|
-
* ```ts
|
|
291
|
-
* const result = await sql<Person[]>`select * from person`.execute(db)
|
|
292
|
-
* ```
|
|
293
|
-
*
|
|
294
|
-
* You can merge other `sql` expressions and queries using substitutions:
|
|
295
|
-
*
|
|
296
|
-
* ```ts
|
|
297
|
-
* const petName = db.selectFrom('pet').select('name').limit(1)
|
|
298
|
-
* const fullName = sql`concat(first_name, ' ', last_name)`
|
|
299
|
-
*
|
|
300
|
-
* sql`
|
|
301
|
-
* select ${fullName} as full_name, ${petName} as pet_name
|
|
302
|
-
* from person
|
|
303
|
-
* `
|
|
304
|
-
* ```
|
|
305
|
-
*
|
|
306
|
-
* Substitutions also handle {@link ExpressionBuilder.ref},
|
|
307
|
-
* {@link DynamicModule.ref} and pretty much anything else you
|
|
308
|
-
* throw at it. Here's an example of calling a function in a
|
|
309
|
-
* type-safe way:
|
|
310
|
-
*
|
|
311
|
-
* ```ts
|
|
312
|
-
* db.selectFrom('person')
|
|
313
|
-
* .select([
|
|
314
|
-
* 'first_name',
|
|
315
|
-
* 'last_name',
|
|
316
|
-
* (eb) => {
|
|
317
|
-
* // The `eb.ref` method is type-safe and only accepts
|
|
318
|
-
* // column references that are possible.
|
|
319
|
-
* const firstName = eb.ref('first_name')
|
|
320
|
-
* const lastName = eb.ref('last_name')
|
|
321
|
-
*
|
|
322
|
-
* const fullName = sql<string>`concat(${firstName}, ' ', ${lastName})`
|
|
323
|
-
* return fullName.as('full_name')
|
|
324
|
-
* }
|
|
325
|
-
* ])
|
|
326
|
-
* ```
|
|
327
|
-
*
|
|
328
|
-
* don't know if that amount of ceremony is worth the small increase in
|
|
329
|
-
* type-safety though... But it's possible.
|
|
330
|
-
*/
|
|
331
331
|
export declare const sql: Sql;
|
|
@@ -7,102 +7,6 @@ import { parseTable } from '../parser/table-parser.js';
|
|
|
7
7
|
import { parseValueExpression } from '../parser/value-parser.js';
|
|
8
8
|
import { createQueryId } from '../util/query-id.js';
|
|
9
9
|
import { RawBuilder } from './raw-builder.js';
|
|
10
|
-
/**
|
|
11
|
-
* Template tag for creating raw SQL snippets and queries.
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { sql } from 'kysely'
|
|
15
|
-
*
|
|
16
|
-
* const id = 123
|
|
17
|
-
*
|
|
18
|
-
* const snippet = sql<Person[]>`select * from person where id = ${id}`
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* Substitutions (the things inside `${}`) are automatically passed to the database
|
|
22
|
-
* as parameters and are NOT interpolated to the SQL string. There's no need to worry
|
|
23
|
-
* about SQL injection vulnerabilities.
|
|
24
|
-
*
|
|
25
|
-
* If you need your substitutions to be interpreted as identifiers, value literals or
|
|
26
|
-
* lists of things, see the {@link Sql.ref}, {@link Sql.table}, {@link Sql.id},
|
|
27
|
-
* {@link Sql.literal}, {@link Sql.raw} and {@link Sql.join} functions.
|
|
28
|
-
*
|
|
29
|
-
* You can pass sql snippets returned by the `sql` tag pretty much anywhere. Whenever
|
|
30
|
-
* something can't be done using the Kysely API, you should be able to drop down to
|
|
31
|
-
* raw SQL using the `sql` tag. Here's an example query that uses raw sql in a bunch
|
|
32
|
-
* of methods:
|
|
33
|
-
*
|
|
34
|
-
* ```ts
|
|
35
|
-
* const persons = await db
|
|
36
|
-
* .selectFrom('person')
|
|
37
|
-
* .select(
|
|
38
|
-
* // If you use `sql` in a select statement, remember to call the `as`
|
|
39
|
-
* // method to give it an alias. Otherwise Kysely is not able to add
|
|
40
|
-
* // the column to the result type.
|
|
41
|
-
* sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
|
|
42
|
-
* )
|
|
43
|
-
* .where(sql`birthdate between ${date1} and ${date2}`)
|
|
44
|
-
* // Here we assume we have list of nicknames for the person
|
|
45
|
-
* // (a list of strings) and we use the PostgreSQL `@>` operator
|
|
46
|
-
* // to test if all of them are valid nicknames for the user.
|
|
47
|
-
* .where('nicknames', '@>', sql`ARRAY[${sql.join(nicknames)}]`)
|
|
48
|
-
* .orderBy(sql`concat(first_name, ' ', last_name)`)
|
|
49
|
-
* .execute()
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* The generated SQL (PostgreSQL):
|
|
53
|
-
*
|
|
54
|
-
* ```sql
|
|
55
|
-
* select concat(first_name, ' ', last_name) as "full_name"
|
|
56
|
-
* from "person"
|
|
57
|
-
* where birthdate between $1 and $2
|
|
58
|
-
* and "nicknames" @> ARRAY[$3, $4, $5, $6, $7, $8, $9, $10]
|
|
59
|
-
* order by concat(first_name, ' ', last_name)
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* SQL snippets can be executed by calling the `execute` method and passing a `Kysely`
|
|
63
|
-
* instance as the only argument:
|
|
64
|
-
*
|
|
65
|
-
* ```ts
|
|
66
|
-
* const result = await sql<Person[]>`select * from person`.execute(db)
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* You can merge other `sql` expressions and queries using substitutions:
|
|
70
|
-
*
|
|
71
|
-
* ```ts
|
|
72
|
-
* const petName = db.selectFrom('pet').select('name').limit(1)
|
|
73
|
-
* const fullName = sql`concat(first_name, ' ', last_name)`
|
|
74
|
-
*
|
|
75
|
-
* sql`
|
|
76
|
-
* select ${fullName} as full_name, ${petName} as pet_name
|
|
77
|
-
* from person
|
|
78
|
-
* `
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* Substitutions also handle {@link ExpressionBuilder.ref},
|
|
82
|
-
* {@link DynamicModule.ref} and pretty much anything else you
|
|
83
|
-
* throw at it. Here's an example of calling a function in a
|
|
84
|
-
* type-safe way:
|
|
85
|
-
*
|
|
86
|
-
* ```ts
|
|
87
|
-
* db.selectFrom('person')
|
|
88
|
-
* .select([
|
|
89
|
-
* 'first_name',
|
|
90
|
-
* 'last_name',
|
|
91
|
-
* (eb) => {
|
|
92
|
-
* // The `eb.ref` method is type-safe and only accepts
|
|
93
|
-
* // column references that are possible.
|
|
94
|
-
* const firstName = eb.ref('first_name')
|
|
95
|
-
* const lastName = eb.ref('last_name')
|
|
96
|
-
*
|
|
97
|
-
* const fullName = sql<string>`concat(${firstName}, ' ', ${lastName})`
|
|
98
|
-
* return fullName.as('full_name')
|
|
99
|
-
* }
|
|
100
|
-
* ])
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* don't know if that amount of ceremony is worth the small increase in
|
|
104
|
-
* type-safety though... But it's possible.
|
|
105
|
-
*/
|
|
106
10
|
export const sql = Object.assign((sqlFragments, ...parameters) => {
|
|
107
11
|
return new RawBuilder({
|
|
108
12
|
queryId: createQueryId(),
|
|
@@ -149,6 +149,60 @@ export declare class CreateTableBuilder<TB extends string, C extends string = ne
|
|
|
149
149
|
* ```
|
|
150
150
|
*/
|
|
151
151
|
addForeignKeyConstraint(constraintName: string, columns: C[], targetTable: string, targetColumns: string[], build?: ForeignKeyConstraintBuilderCallback): CreateTableBuilder<TB, C>;
|
|
152
|
+
/**
|
|
153
|
+
* This can be used to add any additional SQL to the front of the query __after__ the `create` keyword.
|
|
154
|
+
*
|
|
155
|
+
* Also see {@link temporary}.
|
|
156
|
+
*
|
|
157
|
+
* ### Examples
|
|
158
|
+
*
|
|
159
|
+
* ```ts
|
|
160
|
+
* db.schema.createTable('person')
|
|
161
|
+
* .modifyFront(sql`global temporary`)
|
|
162
|
+
* .addColumn('id', 'integer', col => col => primaryKey())
|
|
163
|
+
* .addColumn('first_name', 'varchar(64)', col => col.notNull())
|
|
164
|
+
* .addColumn('last_name', 'varchar(64), col => col.notNull())
|
|
165
|
+
* .execute()
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* The generated SQL (Postgres):
|
|
169
|
+
*
|
|
170
|
+
* ```sql
|
|
171
|
+
* create global temporary table "person" (
|
|
172
|
+
* "id" integer primary key,
|
|
173
|
+
* "first_name" varchar(64) not null,
|
|
174
|
+
* "last_name" varchar(64) not null
|
|
175
|
+
* )
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
modifyFront(modifier: AnyRawBuilder): CreateTableBuilder<TB, C>;
|
|
179
|
+
/**
|
|
180
|
+
* This can be used to add any additional SQL to the end of the query.
|
|
181
|
+
*
|
|
182
|
+
* Also see {@link onCommit}.
|
|
183
|
+
*
|
|
184
|
+
* ### Examples
|
|
185
|
+
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* db.schema.createTable('person')
|
|
188
|
+
* .addColumn('id', 'integer', col => col => primaryKey())
|
|
189
|
+
* .addColumn('first_name', 'varchar(64)', col => col.notNull())
|
|
190
|
+
* .addColumn('last_name', 'varchar(64), col => col.notNull())
|
|
191
|
+
* .modifyEnd(sql`collate utf8_unicode_ci`)
|
|
192
|
+
* .execute()
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* The generated SQL (MySQL):
|
|
196
|
+
*
|
|
197
|
+
* ```sql
|
|
198
|
+
* create table `person` (
|
|
199
|
+
* `id` integer primary key,
|
|
200
|
+
* `first_name` varchar(64) not null,
|
|
201
|
+
* `last_name` varchar(64) not null
|
|
202
|
+
* ) collate utf8_unicode_ci
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
modifyEnd(modifier: AnyRawBuilder): CreateTableBuilder<TB, C>;
|
|
152
206
|
toOperationNode(): CreateTableNode;
|
|
153
207
|
compile(): CompiledQuery;
|
|
154
208
|
execute(): Promise<void>;
|
|
@@ -204,6 +204,70 @@ export class CreateTableBuilder {
|
|
|
204
204
|
createTableNode: CreateTableNode.cloneWithConstraint(this.#props.createTableNode, builder.toOperationNode()),
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* This can be used to add any additional SQL to the front of the query __after__ the `create` keyword.
|
|
209
|
+
*
|
|
210
|
+
* Also see {@link temporary}.
|
|
211
|
+
*
|
|
212
|
+
* ### Examples
|
|
213
|
+
*
|
|
214
|
+
* ```ts
|
|
215
|
+
* db.schema.createTable('person')
|
|
216
|
+
* .modifyFront(sql`global temporary`)
|
|
217
|
+
* .addColumn('id', 'integer', col => col => primaryKey())
|
|
218
|
+
* .addColumn('first_name', 'varchar(64)', col => col.notNull())
|
|
219
|
+
* .addColumn('last_name', 'varchar(64), col => col.notNull())
|
|
220
|
+
* .execute()
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* The generated SQL (Postgres):
|
|
224
|
+
*
|
|
225
|
+
* ```sql
|
|
226
|
+
* create global temporary table "person" (
|
|
227
|
+
* "id" integer primary key,
|
|
228
|
+
* "first_name" varchar(64) not null,
|
|
229
|
+
* "last_name" varchar(64) not null
|
|
230
|
+
* )
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
modifyFront(modifier) {
|
|
234
|
+
return new CreateTableBuilder({
|
|
235
|
+
...this.#props,
|
|
236
|
+
createTableNode: CreateTableNode.cloneWithFrontModifier(this.#props.createTableNode, modifier.toOperationNode()),
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* This can be used to add any additional SQL to the end of the query.
|
|
241
|
+
*
|
|
242
|
+
* Also see {@link onCommit}.
|
|
243
|
+
*
|
|
244
|
+
* ### Examples
|
|
245
|
+
*
|
|
246
|
+
* ```ts
|
|
247
|
+
* db.schema.createTable('person')
|
|
248
|
+
* .addColumn('id', 'integer', col => col => primaryKey())
|
|
249
|
+
* .addColumn('first_name', 'varchar(64)', col => col.notNull())
|
|
250
|
+
* .addColumn('last_name', 'varchar(64), col => col.notNull())
|
|
251
|
+
* .modifyEnd(sql`collate utf8_unicode_ci`)
|
|
252
|
+
* .execute()
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* The generated SQL (MySQL):
|
|
256
|
+
*
|
|
257
|
+
* ```sql
|
|
258
|
+
* create table `person` (
|
|
259
|
+
* `id` integer primary key,
|
|
260
|
+
* `first_name` varchar(64) not null,
|
|
261
|
+
* `last_name` varchar(64) not null
|
|
262
|
+
* ) collate utf8_unicode_ci
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
modifyEnd(modifier) {
|
|
266
|
+
return new CreateTableBuilder({
|
|
267
|
+
...this.#props,
|
|
268
|
+
createTableNode: CreateTableNode.cloneWithEndModifier(this.#props.createTableNode, modifier.toOperationNode()),
|
|
269
|
+
});
|
|
270
|
+
}
|
|
207
271
|
toOperationNode() {
|
|
208
272
|
return this.#props.executor.transformQuery(this.#props.createTableNode, this.#props.queryId);
|
|
209
273
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AnyRawBuilder } from './type-utils.js';
|
|
2
|
+
export declare type ExplainFormat = 'text' | 'xml' | 'json' | 'yaml' | 'traditional' | 'tree';
|
|
3
|
+
export interface Explainable {
|
|
4
|
+
explain<O extends Record<string, any> = Record<string, any>>(format?: ExplainFormat, options?: AnyRawBuilder): Promise<O[]>;
|
|
5
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kysely",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Type safe SQL query builder",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"@types/chai-subset": "^1.3.3",
|
|
49
49
|
"@types/mocha": "^9.1.1",
|
|
50
50
|
"@types/pg": "^8.6.5",
|
|
51
|
+
"@types/sinon": "^10.0.13",
|
|
51
52
|
"better-sqlite3": "^7.5.3",
|
|
52
53
|
"chai": "^4.3.6",
|
|
53
54
|
"chai-as-promised": "^7.1.1",
|
|
@@ -59,6 +60,7 @@
|
|
|
59
60
|
"pg-cursor": "^2.7.3",
|
|
60
61
|
"playwright": "^1.22.2",
|
|
61
62
|
"prettier": "^2.7.1",
|
|
63
|
+
"sinon": "^14.0.0",
|
|
62
64
|
"tsd": "^0.21.0",
|
|
63
65
|
"typedoc": "^0.23.6",
|
|
64
66
|
"typescript": "4.7.4"
|