kysely 0.19.12 → 0.21.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.
Files changed (144) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/dialect/mysql/mysql-introspector.js +2 -0
  3. package/dist/cjs/dialect/mysql/mysql-query-compiler.d.ts +5 -0
  4. package/dist/cjs/dialect/mysql/mysql-query-compiler.js +16 -0
  5. package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +5 -12
  6. package/dist/cjs/dialect/postgres/postgres-driver.js +16 -11
  7. package/dist/cjs/dialect/postgres/postgres-introspector.js +17 -9
  8. package/dist/cjs/dialect/postgres/postgres-query-compiler.d.ts +1 -3
  9. package/dist/cjs/dialect/postgres/postgres-query-compiler.js +3 -8
  10. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +2 -0
  11. package/dist/cjs/dialect/sqlite/sqlite-query-compiler.d.ts +3 -0
  12. package/dist/cjs/dialect/sqlite/sqlite-query-compiler.js +10 -0
  13. package/dist/cjs/index.d.ts +3 -0
  14. package/dist/cjs/index.js +3 -0
  15. package/dist/cjs/operation-node/create-table-node.d.ts +6 -1
  16. package/dist/cjs/operation-node/create-table-node.js +16 -0
  17. package/dist/cjs/operation-node/create-type-node.d.ts +2 -2
  18. package/dist/cjs/operation-node/create-type-node.js +2 -2
  19. package/dist/cjs/operation-node/create-view-node.d.ts +2 -2
  20. package/dist/cjs/operation-node/create-view-node.js +2 -2
  21. package/dist/cjs/operation-node/delete-query-node.d.ts +3 -0
  22. package/dist/cjs/operation-node/delete-query-node.js +6 -0
  23. package/dist/cjs/operation-node/drop-index-node.d.ts +2 -2
  24. package/dist/cjs/operation-node/drop-index-node.js +2 -2
  25. package/dist/cjs/operation-node/drop-type-node.d.ts +2 -2
  26. package/dist/cjs/operation-node/drop-type-node.js +2 -2
  27. package/dist/cjs/operation-node/drop-view-node.d.ts +2 -2
  28. package/dist/cjs/operation-node/drop-view-node.js +2 -2
  29. package/dist/cjs/operation-node/explain-node.d.ts +16 -0
  30. package/dist/cjs/operation-node/explain-node.js +19 -0
  31. package/dist/cjs/operation-node/identifier-node.d.ts +2 -2
  32. package/dist/cjs/operation-node/identifier-node.js +2 -2
  33. package/dist/cjs/operation-node/insert-query-node.d.ts +2 -0
  34. package/dist/cjs/operation-node/operation-node-transformer.d.ts +7 -3
  35. package/dist/cjs/operation-node/operation-node-transformer.js +30 -6
  36. package/dist/cjs/operation-node/operation-node-visitor.d.ts +8 -4
  37. package/dist/cjs/operation-node/operation-node-visitor.js +2 -0
  38. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  39. package/dist/cjs/operation-node/reference-node.d.ts +1 -1
  40. package/dist/cjs/operation-node/reference-node.js +1 -2
  41. package/dist/cjs/operation-node/schemable-identifier-node.d.ts +15 -0
  42. package/dist/cjs/operation-node/schemable-identifier-node.js +26 -0
  43. package/dist/cjs/operation-node/select-query-node.d.ts +3 -0
  44. package/dist/cjs/operation-node/select-query-node.js +6 -0
  45. package/dist/cjs/operation-node/selection-node.d.ts +2 -1
  46. package/dist/cjs/operation-node/table-node.d.ts +2 -3
  47. package/dist/cjs/operation-node/table-node.js +3 -4
  48. package/dist/cjs/operation-node/update-query-node.d.ts +3 -0
  49. package/dist/cjs/operation-node/update-query-node.js +6 -0
  50. package/dist/cjs/parser/select-parser.js +2 -1
  51. package/dist/cjs/plugin/camel-case/camel-case-transformer.js +1 -1
  52. package/dist/cjs/plugin/with-schema/with-schema-transformer.d.ts +4 -28
  53. package/dist/cjs/plugin/with-schema/with-schema-transformer.js +72 -78
  54. package/dist/cjs/query-builder/delete-query-builder.d.ts +19 -1
  55. package/dist/cjs/query-builder/delete-query-builder.js +24 -0
  56. package/dist/cjs/query-builder/function-builder.d.ts +3 -3
  57. package/dist/cjs/query-builder/insert-query-builder.d.ts +20 -2
  58. package/dist/cjs/query-builder/insert-query-builder.js +26 -0
  59. package/dist/cjs/query-builder/select-query-builder.d.ts +38 -1
  60. package/dist/cjs/query-builder/select-query-builder.js +45 -2
  61. package/dist/cjs/query-builder/update-query-builder.d.ts +20 -1
  62. package/dist/cjs/query-builder/update-query-builder.js +25 -0
  63. package/dist/cjs/query-compiler/default-query-compiler.d.ts +8 -0
  64. package/dist/cjs/query-compiler/default-query-compiler.js +63 -5
  65. package/dist/cjs/raw-builder/sql.d.ts +96 -96
  66. package/dist/cjs/raw-builder/sql.js +0 -96
  67. package/dist/cjs/schema/alter-table-builder.d.ts +6 -6
  68. package/dist/cjs/schema/column-definition-builder.d.ts +6 -6
  69. package/dist/cjs/schema/create-table-builder.d.ts +54 -0
  70. package/dist/cjs/schema/create-table-builder.js +64 -0
  71. package/dist/cjs/util/explainable.d.ts +5 -0
  72. package/dist/cjs/util/explainable.js +2 -0
  73. package/dist/esm/dialect/mysql/mysql-introspector.js +2 -0
  74. package/dist/esm/dialect/mysql/mysql-query-compiler.d.ts +5 -0
  75. package/dist/esm/dialect/mysql/mysql-query-compiler.js +16 -0
  76. package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +5 -12
  77. package/dist/esm/dialect/postgres/postgres-driver.js +16 -11
  78. package/dist/esm/dialect/postgres/postgres-introspector.js +17 -9
  79. package/dist/esm/dialect/postgres/postgres-query-compiler.d.ts +1 -3
  80. package/dist/esm/dialect/postgres/postgres-query-compiler.js +3 -8
  81. package/dist/esm/dialect/sqlite/sqlite-introspector.js +2 -0
  82. package/dist/esm/dialect/sqlite/sqlite-query-compiler.d.ts +3 -0
  83. package/dist/esm/dialect/sqlite/sqlite-query-compiler.js +10 -0
  84. package/dist/esm/index.d.ts +3 -0
  85. package/dist/esm/index.js +3 -0
  86. package/dist/esm/operation-node/create-table-node.d.ts +6 -1
  87. package/dist/esm/operation-node/create-table-node.js +16 -0
  88. package/dist/esm/operation-node/create-type-node.d.ts +2 -2
  89. package/dist/esm/operation-node/create-type-node.js +2 -2
  90. package/dist/esm/operation-node/create-view-node.d.ts +2 -2
  91. package/dist/esm/operation-node/create-view-node.js +2 -2
  92. package/dist/esm/operation-node/delete-query-node.d.ts +3 -0
  93. package/dist/esm/operation-node/delete-query-node.js +6 -0
  94. package/dist/esm/operation-node/drop-index-node.d.ts +2 -2
  95. package/dist/esm/operation-node/drop-index-node.js +2 -2
  96. package/dist/esm/operation-node/drop-type-node.d.ts +2 -2
  97. package/dist/esm/operation-node/drop-type-node.js +2 -2
  98. package/dist/esm/operation-node/drop-view-node.d.ts +2 -2
  99. package/dist/esm/operation-node/drop-view-node.js +2 -2
  100. package/dist/esm/operation-node/explain-node.d.ts +16 -0
  101. package/dist/esm/operation-node/explain-node.js +17 -0
  102. package/dist/esm/operation-node/identifier-node.d.ts +2 -2
  103. package/dist/esm/operation-node/identifier-node.js +2 -2
  104. package/dist/esm/operation-node/insert-query-node.d.ts +2 -0
  105. package/dist/esm/operation-node/operation-node-transformer.d.ts +7 -3
  106. package/dist/esm/operation-node/operation-node-transformer.js +30 -6
  107. package/dist/esm/operation-node/operation-node-visitor.d.ts +8 -4
  108. package/dist/esm/operation-node/operation-node-visitor.js +2 -0
  109. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  110. package/dist/esm/operation-node/reference-node.d.ts +1 -1
  111. package/dist/esm/operation-node/reference-node.js +1 -2
  112. package/dist/esm/operation-node/schemable-identifier-node.d.ts +15 -0
  113. package/dist/esm/operation-node/schemable-identifier-node.js +24 -0
  114. package/dist/esm/operation-node/select-query-node.d.ts +3 -0
  115. package/dist/esm/operation-node/select-query-node.js +6 -0
  116. package/dist/esm/operation-node/selection-node.d.ts +2 -1
  117. package/dist/esm/operation-node/table-node.d.ts +2 -3
  118. package/dist/esm/operation-node/table-node.js +3 -4
  119. package/dist/esm/operation-node/update-query-node.d.ts +3 -0
  120. package/dist/esm/operation-node/update-query-node.js +6 -0
  121. package/dist/esm/parser/select-parser.js +2 -1
  122. package/dist/esm/plugin/camel-case/camel-case-transformer.js +1 -1
  123. package/dist/esm/plugin/with-schema/with-schema-transformer.d.ts +4 -28
  124. package/dist/esm/plugin/with-schema/with-schema-transformer.js +72 -78
  125. package/dist/esm/query-builder/delete-query-builder.d.ts +19 -1
  126. package/dist/esm/query-builder/delete-query-builder.js +24 -0
  127. package/dist/esm/query-builder/function-builder.d.ts +3 -3
  128. package/dist/esm/query-builder/insert-query-builder.d.ts +20 -2
  129. package/dist/esm/query-builder/insert-query-builder.js +26 -0
  130. package/dist/esm/query-builder/select-query-builder.d.ts +38 -1
  131. package/dist/esm/query-builder/select-query-builder.js +45 -2
  132. package/dist/esm/query-builder/update-query-builder.d.ts +20 -1
  133. package/dist/esm/query-builder/update-query-builder.js +25 -0
  134. package/dist/esm/query-compiler/default-query-compiler.d.ts +8 -0
  135. package/dist/esm/query-compiler/default-query-compiler.js +63 -5
  136. package/dist/esm/raw-builder/sql.d.ts +96 -96
  137. package/dist/esm/raw-builder/sql.js +0 -96
  138. package/dist/esm/schema/alter-table-builder.d.ts +6 -6
  139. package/dist/esm/schema/column-definition-builder.d.ts +6 -6
  140. package/dist/esm/schema/create-table-builder.d.ts +54 -0
  141. package/dist/esm/schema/create-table-builder.js +64 -0
  142. package/dist/esm/util/explainable.d.ts +5 -0
  143. package/dist/esm/util/explainable.js +2 -0
  144. package/package.json +4 -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(),
@@ -92,7 +92,7 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
92
92
  * Makes the column the primary key.
93
93
  *
94
94
  * If you want to specify a composite primary key use the
95
- * {@link TableBuilder.addPrimaryKeyConstraint} method.
95
+ * {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
96
96
  */
97
97
  primaryKey(): AlterTableAddColumnBuilder;
98
98
  /**
@@ -100,7 +100,7 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
100
100
  *
101
101
  * If your database engine doesn't support foreign key constraints in the
102
102
  * column definition (like MySQL 5) you need to call the table level
103
- * {@link TableBuilder.addForeignKeyConstraint} method instead.
103
+ * {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
104
104
  *
105
105
  * ### Examples
106
106
  *
@@ -114,7 +114,7 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
114
114
  *
115
115
  * If your database engine doesn't support foreign key constraints in the
116
116
  * column definition (like MySQL 5) you need to call the table level
117
- * {@link TableBuilder.addForeignKeyConstraint} method instead.
117
+ * {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
118
118
  *
119
119
  * ### Examples
120
120
  *
@@ -258,7 +258,7 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
258
258
  * Makes the column the primary key.
259
259
  *
260
260
  * If you want to specify a composite primary key use the
261
- * {@link TableBuilder.addPrimaryKeyConstraint} method.
261
+ * {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
262
262
  */
263
263
  primaryKey(): AlterTableModifyColumnBuilder;
264
264
  /**
@@ -266,7 +266,7 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
266
266
  *
267
267
  * If your database engine doesn't support foreign key constraints in the
268
268
  * column definition (like MySQL 5) you need to call the table level
269
- * {@link TableBuilder.addForeignKeyConstraint} method instead.
269
+ * {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
270
270
  *
271
271
  * ### Examples
272
272
  *
@@ -280,7 +280,7 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
280
280
  *
281
281
  * If your database engine doesn't support foreign key constraints in the
282
282
  * column definition (like MySQL 5) you need to call the table level
283
- * {@link TableBuilder.addForeignKeyConstraint} method instead.
283
+ * {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
284
284
  *
285
285
  * ### Examples
286
286
  *
@@ -16,7 +16,7 @@ export interface ColumnDefinitionBuilderInterface {
16
16
  * Makes the column the primary key.
17
17
  *
18
18
  * If you want to specify a composite primary key use the
19
- * {@link TableBuilder.addPrimaryKeyConstraint} method.
19
+ * {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
20
20
  */
21
21
  primaryKey(): ColumnDefinitionBuilderInterface;
22
22
  /**
@@ -24,7 +24,7 @@ export interface ColumnDefinitionBuilderInterface {
24
24
  *
25
25
  * If your database engine doesn't support foreign key constraints in the
26
26
  * column definition (like MySQL 5) you need to call the table level
27
- * {@link TableBuilder.addForeignKeyConstraint} method instead.
27
+ * {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
28
28
  *
29
29
  * ### Examples
30
30
  *
@@ -38,7 +38,7 @@ export interface ColumnDefinitionBuilderInterface {
38
38
  *
39
39
  * If your database engine doesn't support foreign key constraints in the
40
40
  * column definition (like MySQL 5) you need to call the table level
41
- * {@link TableBuilder.addForeignKeyConstraint} method instead.
41
+ * {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
42
42
  *
43
43
  * ### Examples
44
44
  *
@@ -175,7 +175,7 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
175
175
  * Makes the column the primary key.
176
176
  *
177
177
  * If you want to specify a composite primary key use the
178
- * {@link TableBuilder.addPrimaryKeyConstraint} method.
178
+ * {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
179
179
  */
180
180
  primaryKey(): ColumnDefinitionBuilder;
181
181
  /**
@@ -183,7 +183,7 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
183
183
  *
184
184
  * If your database engine doesn't support foreign key constraints in the
185
185
  * column definition (like MySQL 5) you need to call the table level
186
- * {@link TableBuilder.addForeignKeyConstraint} method instead.
186
+ * {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
187
187
  *
188
188
  * ### Examples
189
189
  *
@@ -197,7 +197,7 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
197
197
  *
198
198
  * If your database engine doesn't support foreign key constraints in the
199
199
  * column definition (like MySQL 5) you need to call the table level
200
- * {@link TableBuilder.addForeignKeyConstraint} method instead.
200
+ * {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
201
201
  *
202
202
  * ### Examples
203
203
  *
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="./explainable.d.ts" />
2
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely",
3
- "version": "0.19.12",
3
+ "version": "0.21.0",
4
4
  "description": "Type safe SQL query builder",
5
5
  "repository": {
6
6
  "type": "git",
@@ -48,6 +48,8 @@
48
48
  "@types/chai-subset": "^1.3.3",
49
49
  "@types/mocha": "^9.1.1",
50
50
  "@types/pg": "^8.6.5",
51
+ "@types/pg-cursor": "^2.7.0",
52
+ "@types/sinon": "^10.0.13",
51
53
  "better-sqlite3": "^7.5.3",
52
54
  "chai": "^4.3.6",
53
55
  "chai-as-promised": "^7.1.1",
@@ -59,6 +61,7 @@
59
61
  "pg-cursor": "^2.7.3",
60
62
  "playwright": "^1.22.2",
61
63
  "prettier": "^2.7.1",
64
+ "sinon": "^14.0.0",
62
65
  "tsd": "^0.21.0",
63
66
  "typedoc": "^0.23.6",
64
67
  "typescript": "4.7.4"