kysely 0.16.11 → 0.17.2
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 +2 -2
- package/dist/cjs/dialect/mysql/mysql-adapter.js +3 -4
- package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +19 -0
- package/dist/cjs/dialect/mysql/mysql-introspector.js +2 -1
- package/dist/cjs/dialect/postgres/postgres-adapter.js +3 -2
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +2 -1
- package/dist/cjs/driver/connection-provider.d.ts +1 -1
- package/dist/cjs/driver/default-connection-provider.d.ts +1 -1
- package/dist/cjs/driver/default-connection-provider.js +2 -2
- package/dist/cjs/driver/dummy-driver.d.ts +8 -0
- package/dist/cjs/driver/dummy-driver.js +8 -0
- package/dist/cjs/driver/single-connection-provider.d.ts +1 -1
- package/dist/cjs/driver/single-connection-provider.js +2 -2
- package/dist/cjs/index-nodeless.d.ts +2 -0
- package/dist/cjs/index-nodeless.js +2 -0
- package/dist/cjs/kysely.d.ts +3 -6
- package/dist/cjs/kysely.js +30 -41
- package/dist/cjs/migration/migrator.js +4 -4
- package/dist/cjs/operation-node/operation-node-transformer.js +1 -1
- package/dist/cjs/operation-node/raw-node.d.ts +4 -2
- package/dist/cjs/operation-node/raw-node.js +8 -2
- package/dist/cjs/parser/complex-expression-parser.d.ts +5 -5
- package/dist/cjs/parser/complex-expression-parser.js +5 -4
- package/dist/cjs/parser/filter-parser.d.ts +9 -9
- package/dist/cjs/parser/filter-parser.js +31 -30
- package/dist/cjs/parser/group-by-parser.d.ts +1 -2
- package/dist/cjs/parser/group-by-parser.js +2 -2
- package/dist/cjs/parser/insert-values-parser.d.ts +1 -2
- package/dist/cjs/parser/insert-values-parser.js +6 -6
- package/dist/cjs/parser/join-parser.d.ts +1 -2
- package/dist/cjs/parser/join-parser.js +8 -7
- package/dist/cjs/parser/order-by-parser.d.ts +1 -2
- package/dist/cjs/parser/order-by-parser.js +4 -4
- package/dist/cjs/parser/parse-utils.d.ts +10 -0
- package/dist/cjs/parser/parse-utils.js +38 -0
- package/dist/cjs/parser/reference-parser.d.ts +2 -3
- package/dist/cjs/parser/reference-parser.js +5 -5
- package/dist/cjs/parser/select-parser.d.ts +1 -2
- package/dist/cjs/parser/select-parser.js +5 -5
- package/dist/cjs/parser/table-parser.d.ts +2 -3
- package/dist/cjs/parser/table-parser.js +5 -5
- package/dist/cjs/parser/update-set-parser.d.ts +1 -2
- package/dist/cjs/parser/update-set-parser.js +2 -2
- package/dist/cjs/parser/value-parser.d.ts +3 -4
- package/dist/cjs/parser/value-parser.js +7 -7
- package/dist/cjs/parser/with-parser.d.ts +1 -2
- package/dist/cjs/parser/with-parser.js +3 -2
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
- package/dist/cjs/query-builder/delete-query-builder.d.ts +34 -23
- package/dist/cjs/query-builder/delete-query-builder.js +15 -15
- package/dist/cjs/query-builder/expression-builder.d.ts +4 -13
- package/dist/cjs/query-builder/expression-builder.js +12 -21
- package/dist/cjs/query-builder/function-builder.d.ts +2 -6
- package/dist/cjs/query-builder/function-builder.js +5 -8
- package/dist/cjs/query-builder/insert-query-builder.d.ts +12 -8
- package/dist/cjs/query-builder/insert-query-builder.js +8 -7
- package/dist/cjs/query-builder/join-builder.d.ts +0 -2
- package/dist/cjs/query-builder/join-builder.js +8 -8
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +46 -28
- package/dist/cjs/query-builder/on-conflict-builder.js +17 -17
- package/dist/cjs/query-builder/returning-interface.d.ts +3 -1
- package/dist/cjs/query-builder/select-query-builder.d.ts +52 -33
- package/dist/cjs/query-builder/select-query-builder.js +28 -26
- package/dist/cjs/query-builder/update-query-builder.d.ts +41 -28
- package/dist/cjs/query-builder/update-query-builder.js +22 -20
- package/dist/cjs/query-builder/where-interface.d.ts +31 -20
- package/dist/cjs/query-compiler/default-query-compiler.js +1 -1
- package/dist/cjs/query-creator.d.ts +10 -129
- package/dist/cjs/query-creator.js +5 -136
- package/dist/cjs/query-executor/default-query-executor.d.ts +21 -7
- package/dist/cjs/query-executor/default-query-executor.js +17 -19
- package/dist/cjs/query-executor/noop-query-executor.d.ts +20 -6
- package/dist/cjs/query-executor/noop-query-executor.js +11 -4
- package/dist/cjs/query-executor/query-executor-base.d.ts +62 -0
- package/dist/cjs/query-executor/query-executor-base.js +46 -0
- package/dist/cjs/query-executor/query-executor-provider.d.ts +8 -0
- package/dist/cjs/query-executor/query-executor-provider.js +2 -0
- package/dist/cjs/query-executor/query-executor.d.ts +20 -13
- package/dist/cjs/query-executor/query-executor.js +0 -57
- package/dist/cjs/raw-builder/raw-builder.d.ts +42 -11
- package/dist/cjs/raw-builder/raw-builder.js +55 -56
- package/dist/cjs/raw-builder/sql.d.ts +331 -0
- package/dist/cjs/raw-builder/sql.js +161 -0
- package/dist/cjs/schema/alter-table-builder.d.ts +42 -8
- package/dist/cjs/schema/alter-table-builder.js +20 -0
- package/dist/cjs/schema/column-definition-builder.d.ts +22 -8
- package/dist/cjs/schema/create-index-builder.d.ts +3 -1
- package/dist/cjs/schema/create-index-builder.js +3 -1
- package/dist/cjs/schema/create-table-builder.d.ts +7 -3
- package/dist/cjs/schema/create-table-builder.js +7 -3
- package/dist/cjs/schema/create-view-builder.d.ts +3 -3
- package/dist/cjs/schema/create-view-builder.js +3 -3
- package/dist/cjs/util/query-id.js +10 -4
- package/dist/cjs/util/random-string.js +65 -2
- package/dist/cjs/util/type-utils.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-adapter.js +3 -4
- package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +19 -0
- package/dist/esm/dialect/mysql/mysql-introspector.js +2 -1
- package/dist/esm/dialect/postgres/postgres-adapter.js +3 -2
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +2 -1
- package/dist/esm/driver/connection-provider.d.ts +1 -1
- package/dist/esm/driver/default-connection-provider.d.ts +1 -1
- package/dist/esm/driver/default-connection-provider.js +2 -2
- package/dist/esm/driver/dummy-driver.d.ts +8 -0
- package/dist/esm/driver/dummy-driver.js +8 -0
- package/dist/esm/driver/single-connection-provider.d.ts +1 -1
- package/dist/esm/driver/single-connection-provider.js +2 -2
- package/dist/esm/index-nodeless.d.ts +2 -0
- package/dist/esm/index-nodeless.js +2 -0
- package/dist/esm/kysely.d.ts +3 -6
- package/dist/esm/kysely.js +30 -41
- package/dist/esm/migration/migrator.js +4 -4
- package/dist/esm/operation-node/operation-node-transformer.js +1 -1
- package/dist/esm/operation-node/raw-node.d.ts +4 -2
- package/dist/esm/operation-node/raw-node.js +8 -2
- package/dist/esm/parser/complex-expression-parser.d.ts +5 -5
- package/dist/esm/parser/complex-expression-parser.js +5 -4
- package/dist/esm/parser/filter-parser.d.ts +9 -9
- package/dist/esm/parser/filter-parser.js +31 -30
- package/dist/esm/parser/group-by-parser.d.ts +1 -2
- package/dist/esm/parser/group-by-parser.js +2 -2
- package/dist/esm/parser/insert-values-parser.d.ts +1 -2
- package/dist/esm/parser/insert-values-parser.js +6 -6
- package/dist/esm/parser/join-parser.d.ts +1 -2
- package/dist/esm/parser/join-parser.js +8 -7
- package/dist/esm/parser/order-by-parser.d.ts +1 -2
- package/dist/esm/parser/order-by-parser.js +4 -4
- package/dist/esm/parser/parse-utils.d.ts +10 -0
- package/dist/esm/parser/parse-utils.js +32 -0
- package/dist/esm/parser/reference-parser.d.ts +2 -3
- package/dist/esm/parser/reference-parser.js +5 -5
- package/dist/esm/parser/select-parser.d.ts +1 -2
- package/dist/esm/parser/select-parser.js +5 -5
- package/dist/esm/parser/table-parser.d.ts +2 -3
- package/dist/esm/parser/table-parser.js +5 -5
- package/dist/esm/parser/update-set-parser.d.ts +1 -2
- package/dist/esm/parser/update-set-parser.js +2 -2
- package/dist/esm/parser/value-parser.d.ts +3 -4
- package/dist/esm/parser/value-parser.js +7 -7
- package/dist/esm/parser/with-parser.d.ts +1 -2
- package/dist/esm/parser/with-parser.js +3 -2
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
- package/dist/esm/query-builder/delete-query-builder.d.ts +34 -23
- package/dist/esm/query-builder/delete-query-builder.js +15 -15
- package/dist/esm/query-builder/expression-builder.d.ts +4 -13
- package/dist/esm/query-builder/expression-builder.js +12 -21
- package/dist/esm/query-builder/function-builder.d.ts +2 -6
- package/dist/esm/query-builder/function-builder.js +5 -8
- package/dist/esm/query-builder/insert-query-builder.d.ts +12 -8
- package/dist/esm/query-builder/insert-query-builder.js +8 -7
- package/dist/esm/query-builder/join-builder.d.ts +0 -2
- package/dist/esm/query-builder/join-builder.js +8 -8
- package/dist/esm/query-builder/on-conflict-builder.d.ts +46 -28
- package/dist/esm/query-builder/on-conflict-builder.js +17 -17
- package/dist/esm/query-builder/returning-interface.d.ts +3 -1
- package/dist/esm/query-builder/select-query-builder.d.ts +52 -33
- package/dist/esm/query-builder/select-query-builder.js +28 -26
- package/dist/esm/query-builder/update-query-builder.d.ts +41 -28
- package/dist/esm/query-builder/update-query-builder.js +22 -20
- package/dist/esm/query-builder/where-interface.d.ts +31 -20
- package/dist/esm/query-compiler/default-query-compiler.js +1 -1
- package/dist/esm/query-creator.d.ts +10 -129
- package/dist/esm/query-creator.js +5 -136
- package/dist/esm/query-executor/default-query-executor.d.ts +21 -7
- package/dist/esm/query-executor/default-query-executor.js +17 -19
- package/dist/esm/query-executor/noop-query-executor.d.ts +20 -6
- package/dist/esm/query-executor/noop-query-executor.js +10 -3
- package/dist/esm/query-executor/query-executor-base.d.ts +62 -0
- package/dist/esm/query-executor/query-executor-base.js +43 -0
- package/dist/esm/query-executor/query-executor-provider.d.ts +8 -0
- package/dist/esm/query-executor/query-executor-provider.js +2 -0
- package/dist/esm/query-executor/query-executor.d.ts +20 -13
- package/dist/esm/query-executor/query-executor.js +1 -55
- package/dist/esm/raw-builder/raw-builder.d.ts +42 -11
- package/dist/esm/raw-builder/raw-builder.js +56 -57
- package/dist/esm/raw-builder/sql.d.ts +331 -0
- package/dist/esm/raw-builder/sql.js +159 -0
- package/dist/esm/schema/alter-table-builder.d.ts +42 -8
- package/dist/esm/schema/alter-table-builder.js +20 -0
- package/dist/esm/schema/column-definition-builder.d.ts +22 -8
- package/dist/esm/schema/create-index-builder.d.ts +3 -1
- package/dist/esm/schema/create-index-builder.js +3 -1
- package/dist/esm/schema/create-table-builder.d.ts +7 -3
- package/dist/esm/schema/create-table-builder.js +7 -3
- package/dist/esm/schema/create-view-builder.d.ts +3 -3
- package/dist/esm/schema/create-view-builder.js +3 -3
- package/dist/esm/util/query-id.js +10 -4
- package/dist/esm/util/random-string.js +65 -2
- package/dist/esm/util/type-utils.d.ts +1 -1
- package/package.json +14 -14
- package/dist/cjs/parser/parse-context.d.ts +0 -55
- package/dist/cjs/parser/parse-context.js +0 -50
- package/dist/cjs/util/private-symbols.d.ts +0 -5
- package/dist/cjs/util/private-symbols.js +0 -8
- package/dist/esm/parser/parse-context.d.ts +0 -55
- package/dist/esm/parser/parse-context.js +0 -47
- package/dist/esm/util/private-symbols.d.ts +0 -5
- package/dist/esm/util/private-symbols.js +0 -6
|
@@ -4,10 +4,8 @@ import { DeleteQueryBuilder } from './query-builder/delete-query-builder.js';
|
|
|
4
4
|
import { UpdateQueryBuilder } from './query-builder/update-query-builder.js';
|
|
5
5
|
import { TableExpression, TableExpressionDatabase, TableExpressionTables, TableReference } from './parser/table-parser.js';
|
|
6
6
|
import { QueryExecutor } from './query-executor/query-executor.js';
|
|
7
|
-
import { RawBuilder } from './raw-builder/raw-builder.js';
|
|
8
7
|
import { CommonTableExpression, QueryCreatorWithCommonTableExpression, RecursiveCommonTableExpression } from './parser/with-parser.js';
|
|
9
8
|
import { WithNode } from './operation-node/with-node.js';
|
|
10
|
-
import { ParseContext } from './parser/parse-context.js';
|
|
11
9
|
import { InsertResult } from './query-builder/insert-result.js';
|
|
12
10
|
import { DeleteResult } from './query-builder/delete-result.js';
|
|
13
11
|
import { UpdateResult } from './query-builder/update-result.js';
|
|
@@ -73,9 +71,10 @@ export declare class QueryCreator<DB> {
|
|
|
73
71
|
* Create a select query from raw sql:
|
|
74
72
|
*
|
|
75
73
|
* ```ts
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
74
|
+
* import { sql } from 'kysely'
|
|
75
|
+
*
|
|
76
|
+
* const items = await db
|
|
77
|
+
* .selectFrom(sql<{ one: number }>`(select 1 as one)`.as('q'))
|
|
79
78
|
* .select('q.one')
|
|
80
79
|
* .execute()
|
|
81
80
|
*
|
|
@@ -91,18 +90,20 @@ export declare class QueryCreator<DB> {
|
|
|
91
90
|
* ) as q
|
|
92
91
|
* ```
|
|
93
92
|
*
|
|
94
|
-
* When you use `
|
|
95
|
-
* raw
|
|
96
|
-
* available for the query.
|
|
93
|
+
* When you use the `sql` tag you need to also provide the result type of the
|
|
94
|
+
* raw snippet / query so that Kysely can figure out what columns are
|
|
95
|
+
* available for the rest of the query.
|
|
97
96
|
*
|
|
98
97
|
* The `selectFrom` method also accepts an array for multiple tables. All
|
|
99
98
|
* the above examples can also be used in an array.
|
|
100
99
|
*
|
|
101
100
|
* ```ts
|
|
101
|
+
* import { sql } from 'kysely'
|
|
102
|
+
*
|
|
102
103
|
* const items = await db.selectFrom([
|
|
103
104
|
* 'person as p',
|
|
104
105
|
* db.selectFrom('pet').select('pet.species').as('a'),
|
|
105
|
-
*
|
|
106
|
+
* sql<{ one: number }>`(select 1 as one)`.as('q')
|
|
106
107
|
* ])
|
|
107
108
|
* .select(['p.id', 'a.species', 'q.one'])
|
|
108
109
|
* .execute()
|
|
@@ -299,128 +300,8 @@ export declare class QueryCreator<DB> {
|
|
|
299
300
|
* ```
|
|
300
301
|
*/
|
|
301
302
|
withSchema(schema: string): QueryCreator<DB>;
|
|
302
|
-
/**
|
|
303
|
-
* Provides a way to pass arbitrary SQL into your query and executing completely
|
|
304
|
-
* raw queries.
|
|
305
|
-
*
|
|
306
|
-
* You can use the strings `?` and `??` in the `sql` to bind parameters such as
|
|
307
|
-
* user input to the SQL. You should never EVER concatenate untrusted user
|
|
308
|
-
* input to the SQL string to avoid injection vulnerabilities. Instead use `?`
|
|
309
|
-
* in place of a value and pass the actual value in the `parameters` list. See
|
|
310
|
-
* the examples below.
|
|
311
|
-
*
|
|
312
|
-
* You should only use `raw` when there is no other way to get the job done. This is
|
|
313
|
-
* because Kysely is not able to use type inference when you use raw SQL. For example
|
|
314
|
-
* Kysely won't be able to automatically provide you with the correct query result
|
|
315
|
-
* type. However, there are ways to manually provide types when you use `raw` in most
|
|
316
|
-
* cases. See the examples below.
|
|
317
|
-
*
|
|
318
|
-
* Raw builder instances can be passed to pretty much anywhere: `select`, `where`,
|
|
319
|
-
* `*Join`, `groupBy`, `orderBy` etc. Just try it. If the method accepts it, it works.
|
|
320
|
-
*
|
|
321
|
-
* ### Examples
|
|
322
|
-
*
|
|
323
|
-
* Example of using `raw` in a select statement:
|
|
324
|
-
*
|
|
325
|
-
* ```ts
|
|
326
|
-
* const [person] = await db.selectFrom('person')
|
|
327
|
-
* .select(db.raw<string>('concat(first_name, ' ', last_name)').as('name'))
|
|
328
|
-
* .where('id', '=', 1)
|
|
329
|
-
* .execute()
|
|
330
|
-
*
|
|
331
|
-
* console.log(person.name)
|
|
332
|
-
* ```
|
|
333
|
-
*
|
|
334
|
-
* The generated SQL (PostgreSQL):
|
|
335
|
-
*
|
|
336
|
-
* ```sql
|
|
337
|
-
* select concat(first_name, ' ', last_name) as "name"
|
|
338
|
-
* from "person" where "id" = 1
|
|
339
|
-
* ```
|
|
340
|
-
*
|
|
341
|
-
* The above example selects computed column `name` by concatenating the first name
|
|
342
|
-
* and last name together.
|
|
343
|
-
*
|
|
344
|
-
* There are couple of things worth noticing:
|
|
345
|
-
*
|
|
346
|
-
* 1. You need to provide the output type of your SQL segment for the `raw` method
|
|
347
|
-
* so that Kysely knows what type to give for the `name` column. In this case it's
|
|
348
|
-
* a `string` since that's the output type of the `concat` function in SQL.
|
|
349
|
-
*
|
|
350
|
-
* 2. You need to give an alias for the selection using the `as` method so that
|
|
351
|
-
* Kysely is able to add a column to the output type. The alias needs to be
|
|
352
|
-
* known at compile time! If you pass a string variable whose value is not known
|
|
353
|
-
* at compile time, there is no way for Kysely or typescript to add a column to
|
|
354
|
-
* the output type. In this case you need to use the `castTo` method on the query
|
|
355
|
-
* to specify a return type for the query.
|
|
356
|
-
*
|
|
357
|
-
* We could've also used a `??` placeholder to provide `first_name` and `last_name` like
|
|
358
|
-
* this:
|
|
359
|
-
*
|
|
360
|
-
* ```ts
|
|
361
|
-
* db.raw<string>('concat(??, ' ', ??)', ['first_name', 'last_name'])
|
|
362
|
-
* ```
|
|
363
|
-
*
|
|
364
|
-
* or this:
|
|
365
|
-
*
|
|
366
|
-
* ```ts
|
|
367
|
-
* db.raw<string>('concat(??, ' ', ??)', ['person.first_name', 'person.last_name'])
|
|
368
|
-
* ```
|
|
369
|
-
*
|
|
370
|
-
* But it's often cleaner to just write the column names in the SQL. Again remember to
|
|
371
|
-
* never concatenate column names or any other untrusted user input to the SQL string or you
|
|
372
|
-
* are going to create an injection vulnerability. All user input should go to the parameters
|
|
373
|
-
* array, never to the SQL string directly. But if the column names or values are trusted
|
|
374
|
-
* and known at compile time, there is no reason to use parameters.
|
|
375
|
-
*
|
|
376
|
-
* Example of using `raw` in `where`:
|
|
377
|
-
*
|
|
378
|
-
* ```ts
|
|
379
|
-
* function getPersonsOlderThan(ageLimit: number) {
|
|
380
|
-
* return await db.selectFrom('person')
|
|
381
|
-
* .selectAll()
|
|
382
|
-
* .where(
|
|
383
|
-
* db.raw('now() - birth_date'),
|
|
384
|
-
* '>',
|
|
385
|
-
* db.raw('interval ? year', [ageLimit.toString()])
|
|
386
|
-
* )
|
|
387
|
-
* .execute()
|
|
388
|
-
* }
|
|
389
|
-
* ```
|
|
390
|
-
*
|
|
391
|
-
* The generated SQL (PostgreSQL):
|
|
392
|
-
*
|
|
393
|
-
* ```sql
|
|
394
|
-
* select * from "person" where now() - birth_date > interval $1 year
|
|
395
|
-
* ```
|
|
396
|
-
*
|
|
397
|
-
* The function in the above example returns people that are older than the given number of
|
|
398
|
-
* years. The number of years in this example is an untrusted user input, and therefore we use
|
|
399
|
-
* a `?` placeholder for it.
|
|
400
|
-
*
|
|
401
|
-
* Example of creating a completely raw query from scratch:
|
|
402
|
-
*
|
|
403
|
-
* ```ts
|
|
404
|
-
* const result = await db.raw<Person>('select p.* from person p').execute()
|
|
405
|
-
* const persons = result.rows
|
|
406
|
-
* ```
|
|
407
|
-
*
|
|
408
|
-
* For a raw query, you need to specify the type of the returned __row__. In
|
|
409
|
-
* this case we know the resulting items will be of type `Person` se specify that.
|
|
410
|
-
* The result of `execute()` method is always an array. In this case the type of
|
|
411
|
-
* the `persons` variable is `Person[]`.
|
|
412
|
-
*
|
|
413
|
-
* @param sql - The raw SQL. Special strings `?` and `??` can be used as parameter
|
|
414
|
-
* placeholders. `?` for values and `??` for identifiers such as column names
|
|
415
|
-
* or `column.table` references.
|
|
416
|
-
*
|
|
417
|
-
* @param params - The parameters that will be bound to the `?` and `??` placeholders in
|
|
418
|
-
* the sql string.
|
|
419
|
-
*/
|
|
420
|
-
raw<T = unknown>(sql: string, parameters?: unknown[]): RawBuilder<T>;
|
|
421
303
|
}
|
|
422
304
|
export interface QueryCreatorProps {
|
|
423
305
|
readonly executor: QueryExecutor;
|
|
424
|
-
readonly parseContext: ParseContext;
|
|
425
306
|
readonly withNode?: WithNode;
|
|
426
307
|
}
|
|
@@ -10,7 +10,6 @@ const insert_query_node_js_1 = require("./operation-node/insert-query-node.js");
|
|
|
10
10
|
const select_query_node_js_1 = require("./operation-node/select-query-node.js");
|
|
11
11
|
const update_query_node_js_1 = require("./operation-node/update-query-node.js");
|
|
12
12
|
const table_parser_js_1 = require("./parser/table-parser.js");
|
|
13
|
-
const raw_builder_js_1 = require("./raw-builder/raw-builder.js");
|
|
14
13
|
const with_parser_js_1 = require("./parser/with-parser.js");
|
|
15
14
|
const with_node_js_1 = require("./operation-node/with-node.js");
|
|
16
15
|
const query_id_js_1 = require("./util/query-id.js");
|
|
@@ -25,8 +24,7 @@ class QueryCreator {
|
|
|
25
24
|
return new select_query_builder_js_1.SelectQueryBuilder({
|
|
26
25
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
27
26
|
executor: this.#props.executor,
|
|
28
|
-
|
|
29
|
-
queryNode: select_query_node_js_1.SelectQueryNode.create((0, table_parser_js_1.parseTableExpressionOrList)(this.#props.parseContext, from), this.#props.withNode),
|
|
27
|
+
queryNode: select_query_node_js_1.SelectQueryNode.create((0, table_parser_js_1.parseTableExpressionOrList)(from), this.#props.withNode),
|
|
30
28
|
});
|
|
31
29
|
}
|
|
32
30
|
/**
|
|
@@ -71,7 +69,6 @@ class QueryCreator {
|
|
|
71
69
|
return new insert_query_builder_js_1.InsertQueryBuilder({
|
|
72
70
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
73
71
|
executor: this.#props.executor,
|
|
74
|
-
parseContext: this.#props.parseContext,
|
|
75
72
|
queryNode: insert_query_node_js_1.InsertQueryNode.create((0, table_parser_js_1.parseTable)(table), this.#props.withNode),
|
|
76
73
|
});
|
|
77
74
|
}
|
|
@@ -98,8 +95,7 @@ class QueryCreator {
|
|
|
98
95
|
return new delete_query_builder_js_1.DeleteQueryBuilder({
|
|
99
96
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
100
97
|
executor: this.#props.executor,
|
|
101
|
-
|
|
102
|
-
queryNode: delete_query_node_js_1.DeleteQueryNode.create((0, table_parser_js_1.parseTableExpression)(this.#props.parseContext, table), this.#props.withNode),
|
|
98
|
+
queryNode: delete_query_node_js_1.DeleteQueryNode.create((0, table_parser_js_1.parseTableExpression)(table), this.#props.withNode),
|
|
103
99
|
});
|
|
104
100
|
}
|
|
105
101
|
/**
|
|
@@ -129,8 +125,7 @@ class QueryCreator {
|
|
|
129
125
|
return new update_query_builder_js_1.UpdateQueryBuilder({
|
|
130
126
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
131
127
|
executor: this.#props.executor,
|
|
132
|
-
|
|
133
|
-
queryNode: update_query_node_js_1.UpdateQueryNode.create((0, table_parser_js_1.parseTableExpression)(this.#props.parseContext, table), this.#props.withNode),
|
|
128
|
+
queryNode: update_query_node_js_1.UpdateQueryNode.create((0, table_parser_js_1.parseTableExpression)(table), this.#props.withNode),
|
|
134
129
|
});
|
|
135
130
|
}
|
|
136
131
|
/**
|
|
@@ -175,7 +170,7 @@ class QueryCreator {
|
|
|
175
170
|
* ```
|
|
176
171
|
*/
|
|
177
172
|
with(name, expression) {
|
|
178
|
-
const cte = (0, with_parser_js_1.parseCommonTableExpression)(
|
|
173
|
+
const cte = (0, with_parser_js_1.parseCommonTableExpression)(name, expression);
|
|
179
174
|
return new QueryCreator({
|
|
180
175
|
...this.#props,
|
|
181
176
|
withNode: this.#props.withNode
|
|
@@ -189,7 +184,7 @@ class QueryCreator {
|
|
|
189
184
|
* See the {@link with} method for examples and more documentation.
|
|
190
185
|
*/
|
|
191
186
|
withRecursive(name, expression) {
|
|
192
|
-
const cte = (0, with_parser_js_1.parseCommonTableExpression)(
|
|
187
|
+
const cte = (0, with_parser_js_1.parseCommonTableExpression)(name, expression);
|
|
193
188
|
return new QueryCreator({
|
|
194
189
|
...this.#props,
|
|
195
190
|
withNode: this.#props.withNode
|
|
@@ -250,131 +245,5 @@ class QueryCreator {
|
|
|
250
245
|
executor: this.#props.executor.withPluginAtFront(new with_schema_plugin_js_1.WithSchemaPlugin(schema)),
|
|
251
246
|
});
|
|
252
247
|
}
|
|
253
|
-
/**
|
|
254
|
-
* Provides a way to pass arbitrary SQL into your query and executing completely
|
|
255
|
-
* raw queries.
|
|
256
|
-
*
|
|
257
|
-
* You can use the strings `?` and `??` in the `sql` to bind parameters such as
|
|
258
|
-
* user input to the SQL. You should never EVER concatenate untrusted user
|
|
259
|
-
* input to the SQL string to avoid injection vulnerabilities. Instead use `?`
|
|
260
|
-
* in place of a value and pass the actual value in the `parameters` list. See
|
|
261
|
-
* the examples below.
|
|
262
|
-
*
|
|
263
|
-
* You should only use `raw` when there is no other way to get the job done. This is
|
|
264
|
-
* because Kysely is not able to use type inference when you use raw SQL. For example
|
|
265
|
-
* Kysely won't be able to automatically provide you with the correct query result
|
|
266
|
-
* type. However, there are ways to manually provide types when you use `raw` in most
|
|
267
|
-
* cases. See the examples below.
|
|
268
|
-
*
|
|
269
|
-
* Raw builder instances can be passed to pretty much anywhere: `select`, `where`,
|
|
270
|
-
* `*Join`, `groupBy`, `orderBy` etc. Just try it. If the method accepts it, it works.
|
|
271
|
-
*
|
|
272
|
-
* ### Examples
|
|
273
|
-
*
|
|
274
|
-
* Example of using `raw` in a select statement:
|
|
275
|
-
*
|
|
276
|
-
* ```ts
|
|
277
|
-
* const [person] = await db.selectFrom('person')
|
|
278
|
-
* .select(db.raw<string>('concat(first_name, ' ', last_name)').as('name'))
|
|
279
|
-
* .where('id', '=', 1)
|
|
280
|
-
* .execute()
|
|
281
|
-
*
|
|
282
|
-
* console.log(person.name)
|
|
283
|
-
* ```
|
|
284
|
-
*
|
|
285
|
-
* The generated SQL (PostgreSQL):
|
|
286
|
-
*
|
|
287
|
-
* ```sql
|
|
288
|
-
* select concat(first_name, ' ', last_name) as "name"
|
|
289
|
-
* from "person" where "id" = 1
|
|
290
|
-
* ```
|
|
291
|
-
*
|
|
292
|
-
* The above example selects computed column `name` by concatenating the first name
|
|
293
|
-
* and last name together.
|
|
294
|
-
*
|
|
295
|
-
* There are couple of things worth noticing:
|
|
296
|
-
*
|
|
297
|
-
* 1. You need to provide the output type of your SQL segment for the `raw` method
|
|
298
|
-
* so that Kysely knows what type to give for the `name` column. In this case it's
|
|
299
|
-
* a `string` since that's the output type of the `concat` function in SQL.
|
|
300
|
-
*
|
|
301
|
-
* 2. You need to give an alias for the selection using the `as` method so that
|
|
302
|
-
* Kysely is able to add a column to the output type. The alias needs to be
|
|
303
|
-
* known at compile time! If you pass a string variable whose value is not known
|
|
304
|
-
* at compile time, there is no way for Kysely or typescript to add a column to
|
|
305
|
-
* the output type. In this case you need to use the `castTo` method on the query
|
|
306
|
-
* to specify a return type for the query.
|
|
307
|
-
*
|
|
308
|
-
* We could've also used a `??` placeholder to provide `first_name` and `last_name` like
|
|
309
|
-
* this:
|
|
310
|
-
*
|
|
311
|
-
* ```ts
|
|
312
|
-
* db.raw<string>('concat(??, ' ', ??)', ['first_name', 'last_name'])
|
|
313
|
-
* ```
|
|
314
|
-
*
|
|
315
|
-
* or this:
|
|
316
|
-
*
|
|
317
|
-
* ```ts
|
|
318
|
-
* db.raw<string>('concat(??, ' ', ??)', ['person.first_name', 'person.last_name'])
|
|
319
|
-
* ```
|
|
320
|
-
*
|
|
321
|
-
* But it's often cleaner to just write the column names in the SQL. Again remember to
|
|
322
|
-
* never concatenate column names or any other untrusted user input to the SQL string or you
|
|
323
|
-
* are going to create an injection vulnerability. All user input should go to the parameters
|
|
324
|
-
* array, never to the SQL string directly. But if the column names or values are trusted
|
|
325
|
-
* and known at compile time, there is no reason to use parameters.
|
|
326
|
-
*
|
|
327
|
-
* Example of using `raw` in `where`:
|
|
328
|
-
*
|
|
329
|
-
* ```ts
|
|
330
|
-
* function getPersonsOlderThan(ageLimit: number) {
|
|
331
|
-
* return await db.selectFrom('person')
|
|
332
|
-
* .selectAll()
|
|
333
|
-
* .where(
|
|
334
|
-
* db.raw('now() - birth_date'),
|
|
335
|
-
* '>',
|
|
336
|
-
* db.raw('interval ? year', [ageLimit.toString()])
|
|
337
|
-
* )
|
|
338
|
-
* .execute()
|
|
339
|
-
* }
|
|
340
|
-
* ```
|
|
341
|
-
*
|
|
342
|
-
* The generated SQL (PostgreSQL):
|
|
343
|
-
*
|
|
344
|
-
* ```sql
|
|
345
|
-
* select * from "person" where now() - birth_date > interval $1 year
|
|
346
|
-
* ```
|
|
347
|
-
*
|
|
348
|
-
* The function in the above example returns people that are older than the given number of
|
|
349
|
-
* years. The number of years in this example is an untrusted user input, and therefore we use
|
|
350
|
-
* a `?` placeholder for it.
|
|
351
|
-
*
|
|
352
|
-
* Example of creating a completely raw query from scratch:
|
|
353
|
-
*
|
|
354
|
-
* ```ts
|
|
355
|
-
* const result = await db.raw<Person>('select p.* from person p').execute()
|
|
356
|
-
* const persons = result.rows
|
|
357
|
-
* ```
|
|
358
|
-
*
|
|
359
|
-
* For a raw query, you need to specify the type of the returned __row__. In
|
|
360
|
-
* this case we know the resulting items will be of type `Person` se specify that.
|
|
361
|
-
* The result of `execute()` method is always an array. In this case the type of
|
|
362
|
-
* the `persons` variable is `Person[]`.
|
|
363
|
-
*
|
|
364
|
-
* @param sql - The raw SQL. Special strings `?` and `??` can be used as parameter
|
|
365
|
-
* placeholders. `?` for values and `??` for identifiers such as column names
|
|
366
|
-
* or `column.table` references.
|
|
367
|
-
*
|
|
368
|
-
* @param params - The parameters that will be bound to the `?` and `??` placeholders in
|
|
369
|
-
* the sql string.
|
|
370
|
-
*/
|
|
371
|
-
raw(sql, parameters) {
|
|
372
|
-
return new raw_builder_js_1.RawBuilder({
|
|
373
|
-
queryId: (0, query_id_js_1.createQueryId)(),
|
|
374
|
-
executor: this.#props.executor,
|
|
375
|
-
sql,
|
|
376
|
-
parameters,
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
248
|
}
|
|
380
249
|
exports.QueryCreator = QueryCreator;
|
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
import { ConnectionProvider } from '../driver/connection-provider.js';
|
|
2
|
-
import {
|
|
2
|
+
import { DatabaseConnection } from '../driver/database-connection.js';
|
|
3
3
|
import { CompiledQuery } from '../query-compiler/compiled-query.js';
|
|
4
4
|
import { RootOperationNode, QueryCompiler } from '../query-compiler/query-compiler.js';
|
|
5
5
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { QueryExecutorBase } from './query-executor-base.js';
|
|
7
|
+
import { DialectAdapter } from '../dialect/dialect-adapter.js';
|
|
8
|
+
export declare class DefaultQueryExecutor extends QueryExecutorBase {
|
|
8
9
|
#private;
|
|
9
|
-
constructor(compiler: QueryCompiler, connectionProvider: ConnectionProvider, plugins?: KyselyPlugin[]);
|
|
10
|
+
constructor(compiler: QueryCompiler, adapter: DialectAdapter, connectionProvider: ConnectionProvider, plugins?: KyselyPlugin[]);
|
|
11
|
+
/**
|
|
12
|
+
* Returns the adapter for the current dialect.
|
|
13
|
+
*/
|
|
14
|
+
get adapter(): DialectAdapter;
|
|
10
15
|
/**
|
|
11
16
|
* Compiles the transformed query into SQL. You usually want to pass
|
|
12
17
|
* the output of {@link transformQuery} into this method but you can
|
|
13
18
|
* compile any query using this method.
|
|
14
19
|
*/
|
|
15
20
|
compileQuery(node: RootOperationNode): CompiledQuery;
|
|
16
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Provides a connection for the callback and takes care of disposing
|
|
23
|
+
* the connection after the callback has been run.
|
|
24
|
+
*/
|
|
25
|
+
provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns a copy of this executor with a list of plugins added
|
|
28
|
+
* as the last plugins.
|
|
29
|
+
*/
|
|
30
|
+
withPlugins(plugins: ReadonlyArray<KyselyPlugin>): DefaultQueryExecutor;
|
|
17
31
|
/**
|
|
18
32
|
* Returns a copy of this executor with a plugin added as the
|
|
19
33
|
* last plugin.
|
|
@@ -27,9 +41,9 @@ export declare class DefaultQueryExecutor extends QueryExecutor {
|
|
|
27
41
|
/**
|
|
28
42
|
* Returns a copy of this executor with a new connection provider.
|
|
29
43
|
*/
|
|
30
|
-
withConnectionProvider(connectionProvider: ConnectionProvider):
|
|
44
|
+
withConnectionProvider(connectionProvider: ConnectionProvider): DefaultQueryExecutor;
|
|
31
45
|
/**
|
|
32
46
|
* Returns a copy of this executor without any plugins.
|
|
33
47
|
*/
|
|
34
|
-
withoutPlugins():
|
|
48
|
+
withoutPlugins(): DefaultQueryExecutor;
|
|
35
49
|
}
|
|
@@ -1,42 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultQueryExecutor = void 0;
|
|
4
|
-
const
|
|
5
|
-
class DefaultQueryExecutor extends
|
|
4
|
+
const query_executor_base_js_1 = require("./query-executor-base.js");
|
|
5
|
+
class DefaultQueryExecutor extends query_executor_base_js_1.QueryExecutorBase {
|
|
6
6
|
#compiler;
|
|
7
|
+
#adapter;
|
|
7
8
|
#connectionProvider;
|
|
8
|
-
constructor(compiler, connectionProvider, plugins = []) {
|
|
9
|
+
constructor(compiler, adapter, connectionProvider, plugins = []) {
|
|
9
10
|
super(plugins);
|
|
10
11
|
this.#compiler = compiler;
|
|
12
|
+
this.#adapter = adapter;
|
|
11
13
|
this.#connectionProvider = connectionProvider;
|
|
12
14
|
}
|
|
15
|
+
get adapter() {
|
|
16
|
+
return this.#adapter;
|
|
17
|
+
}
|
|
13
18
|
compileQuery(node) {
|
|
14
19
|
return this.#compiler.compileQuery(node);
|
|
15
20
|
}
|
|
16
|
-
|
|
17
|
-
return this.#connectionProvider.
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
provideConnection(consumer) {
|
|
22
|
+
return this.#connectionProvider.provideConnection(consumer);
|
|
23
|
+
}
|
|
24
|
+
withPlugins(plugins) {
|
|
25
|
+
return new DefaultQueryExecutor(this.#compiler, this.#adapter, this.#connectionProvider, [...this.plugins, ...plugins]);
|
|
20
26
|
}
|
|
21
27
|
withPlugin(plugin) {
|
|
22
|
-
return new DefaultQueryExecutor(this.#compiler, this.#connectionProvider, [
|
|
23
|
-
...this.plugins,
|
|
24
|
-
plugin,
|
|
25
|
-
]);
|
|
28
|
+
return new DefaultQueryExecutor(this.#compiler, this.#adapter, this.#connectionProvider, [...this.plugins, plugin]);
|
|
26
29
|
}
|
|
27
30
|
withPluginAtFront(plugin) {
|
|
28
|
-
return new DefaultQueryExecutor(this.#compiler, this.#connectionProvider, [
|
|
29
|
-
plugin,
|
|
30
|
-
...this.plugins,
|
|
31
|
-
]);
|
|
31
|
+
return new DefaultQueryExecutor(this.#compiler, this.#adapter, this.#connectionProvider, [plugin, ...this.plugins]);
|
|
32
32
|
}
|
|
33
33
|
withConnectionProvider(connectionProvider) {
|
|
34
|
-
return new DefaultQueryExecutor(this.#compiler, connectionProvider, [
|
|
35
|
-
...this.plugins,
|
|
36
|
-
]);
|
|
34
|
+
return new DefaultQueryExecutor(this.#compiler, this.#adapter, connectionProvider, [...this.plugins]);
|
|
37
35
|
}
|
|
38
36
|
withoutPlugins() {
|
|
39
|
-
return new DefaultQueryExecutor(this.#compiler, this.#connectionProvider, []);
|
|
37
|
+
return new DefaultQueryExecutor(this.#compiler, this.#adapter, this.#connectionProvider, []);
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
exports.DefaultQueryExecutor = DefaultQueryExecutor;
|
|
@@ -1,29 +1,42 @@
|
|
|
1
|
-
import { QueryResult } from '../driver/database-connection.js';
|
|
2
1
|
import { CompiledQuery } from '../query-compiler/compiled-query.js';
|
|
3
|
-
import { QueryExecutor } from './query-executor.js';
|
|
4
2
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
3
|
+
import { DialectAdapter } from '../dialect/dialect-adapter.js';
|
|
4
|
+
import { QueryExecutorBase } from './query-executor-base.js';
|
|
5
5
|
/**
|
|
6
6
|
* A {@link QueryExecutor} subclass that can be used when you don't
|
|
7
7
|
* have a {@link QueryCompiler}, {@link ConnectionProvider} or any
|
|
8
8
|
* other needed things to actually execute queries.
|
|
9
9
|
*/
|
|
10
|
-
export declare class NoopQueryExecutor extends
|
|
10
|
+
export declare class NoopQueryExecutor extends QueryExecutorBase {
|
|
11
|
+
/**
|
|
12
|
+
* Returns the adapter for the current dialect.
|
|
13
|
+
*/
|
|
14
|
+
get adapter(): DialectAdapter;
|
|
11
15
|
/**
|
|
12
16
|
* Compiles the transformed query into SQL. You usually want to pass
|
|
13
17
|
* the output of {@link transformQuery} into this method but you can
|
|
14
18
|
* compile any query using this method.
|
|
15
19
|
*/
|
|
16
20
|
compileQuery(): CompiledQuery;
|
|
17
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Provides a connection for the callback and takes care of disposing
|
|
23
|
+
* the connection after the callback has been run.
|
|
24
|
+
*/
|
|
25
|
+
provideConnection<T>(): Promise<T>;
|
|
18
26
|
/**
|
|
19
27
|
* Returns a copy of this executor with a new connection provider.
|
|
20
28
|
*/
|
|
21
|
-
withConnectionProvider():
|
|
29
|
+
withConnectionProvider(): NoopQueryExecutor;
|
|
22
30
|
/**
|
|
23
31
|
* Returns a copy of this executor with a plugin added as the
|
|
24
32
|
* last plugin.
|
|
25
33
|
*/
|
|
26
34
|
withPlugin(plugin: KyselyPlugin): NoopQueryExecutor;
|
|
35
|
+
/**
|
|
36
|
+
* Returns a copy of this executor with a list of plugins added
|
|
37
|
+
* as the last plugins.
|
|
38
|
+
*/
|
|
39
|
+
withPlugins(plugins: ReadonlyArray<KyselyPlugin>): NoopQueryExecutor;
|
|
27
40
|
/**
|
|
28
41
|
* Returns a copy of this executor with a plugin added as the
|
|
29
42
|
* first plugin.
|
|
@@ -32,5 +45,6 @@ export declare class NoopQueryExecutor extends QueryExecutor {
|
|
|
32
45
|
/**
|
|
33
46
|
* Returns a copy of this executor without any plugins.
|
|
34
47
|
*/
|
|
35
|
-
withoutPlugins():
|
|
48
|
+
withoutPlugins(): NoopQueryExecutor;
|
|
36
49
|
}
|
|
50
|
+
export declare const NOOP_QUERY_EXECUTOR: NoopQueryExecutor;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NoopQueryExecutor = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.NOOP_QUERY_EXECUTOR = exports.NoopQueryExecutor = void 0;
|
|
4
|
+
const query_executor_base_js_1 = require("./query-executor-base.js");
|
|
5
5
|
/**
|
|
6
6
|
* A {@link QueryExecutor} subclass that can be used when you don't
|
|
7
7
|
* have a {@link QueryCompiler}, {@link ConnectionProvider} or any
|
|
8
8
|
* other needed things to actually execute queries.
|
|
9
9
|
*/
|
|
10
|
-
class NoopQueryExecutor extends
|
|
10
|
+
class NoopQueryExecutor extends query_executor_base_js_1.QueryExecutorBase {
|
|
11
|
+
get adapter() {
|
|
12
|
+
throw new Error('this query cannot be compiled to SQL');
|
|
13
|
+
}
|
|
11
14
|
compileQuery() {
|
|
12
15
|
throw new Error('this query cannot be compiled to SQL');
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
provideConnection() {
|
|
15
18
|
throw new Error('this query cannot be executed');
|
|
16
19
|
}
|
|
17
20
|
withConnectionProvider() {
|
|
@@ -20,6 +23,9 @@ class NoopQueryExecutor extends query_executor_js_1.QueryExecutor {
|
|
|
20
23
|
withPlugin(plugin) {
|
|
21
24
|
return new NoopQueryExecutor([...this.plugins, plugin]);
|
|
22
25
|
}
|
|
26
|
+
withPlugins(plugins) {
|
|
27
|
+
return new NoopQueryExecutor([...this.plugins, ...plugins]);
|
|
28
|
+
}
|
|
23
29
|
withPluginAtFront(plugin) {
|
|
24
30
|
return new NoopQueryExecutor([plugin, ...this.plugins]);
|
|
25
31
|
}
|
|
@@ -28,3 +34,4 @@ class NoopQueryExecutor extends query_executor_js_1.QueryExecutor {
|
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
exports.NoopQueryExecutor = NoopQueryExecutor;
|
|
37
|
+
exports.NOOP_QUERY_EXECUTOR = new NoopQueryExecutor();
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ConnectionProvider } from '../driver/connection-provider.js';
|
|
2
|
+
import { DatabaseConnection, QueryResult } from '../driver/database-connection.js';
|
|
3
|
+
import { CompiledQuery } from '../query-compiler/compiled-query.js';
|
|
4
|
+
import { RootOperationNode } from '../query-compiler/query-compiler.js';
|
|
5
|
+
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
6
|
+
import { QueryId } from '../util/query-id.js';
|
|
7
|
+
import { DialectAdapter } from '../dialect/dialect-adapter.js';
|
|
8
|
+
import { QueryExecutor } from './query-executor.js';
|
|
9
|
+
export declare abstract class QueryExecutorBase implements QueryExecutor {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(plugins?: ReadonlyArray<KyselyPlugin>);
|
|
12
|
+
abstract get adapter(): DialectAdapter;
|
|
13
|
+
/**
|
|
14
|
+
* Returns all installed plugins.
|
|
15
|
+
*/
|
|
16
|
+
get plugins(): ReadonlyArray<KyselyPlugin>;
|
|
17
|
+
/**
|
|
18
|
+
* Given the query the user has built (expressed as an operation node tree)
|
|
19
|
+
* this method runs it through all plugins' `transformQuery` methods and
|
|
20
|
+
* returns the result.
|
|
21
|
+
*/
|
|
22
|
+
transformQuery<T extends RootOperationNode>(node: T, queryId: QueryId): T;
|
|
23
|
+
/**
|
|
24
|
+
* Compiles the transformed query into SQL. You usually want to pass
|
|
25
|
+
* the output of {@link transformQuery} into this method but you can
|
|
26
|
+
* compile any query using this method.
|
|
27
|
+
*/
|
|
28
|
+
abstract compileQuery(node: RootOperationNode, queryId: QueryId): CompiledQuery;
|
|
29
|
+
/**
|
|
30
|
+
* Provides a connection for the callback and takes care of disposing
|
|
31
|
+
* the connection after the callback has been run.
|
|
32
|
+
*/
|
|
33
|
+
abstract provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Executes a compiled query and runs the result through all plugins'
|
|
36
|
+
* `transformResult` method.
|
|
37
|
+
*/
|
|
38
|
+
executeQuery<R>(compiledQuery: CompiledQuery, queryId: QueryId): Promise<QueryResult<R>>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a copy of this executor with a new connection provider.
|
|
41
|
+
*/
|
|
42
|
+
abstract withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutorBase;
|
|
43
|
+
/**
|
|
44
|
+
* Returns a copy of this executor with a plugin added as the
|
|
45
|
+
* last plugin.
|
|
46
|
+
*/
|
|
47
|
+
abstract withPlugin(plugin: KyselyPlugin): QueryExecutorBase;
|
|
48
|
+
/**
|
|
49
|
+
* Returns a copy of this executor with a list of plugins added
|
|
50
|
+
* as the last plugins.
|
|
51
|
+
*/
|
|
52
|
+
abstract withPlugins(plugin: ReadonlyArray<KyselyPlugin>): QueryExecutorBase;
|
|
53
|
+
/**
|
|
54
|
+
* Returns a copy of this executor with a plugin added as the
|
|
55
|
+
* first plugin.
|
|
56
|
+
*/
|
|
57
|
+
abstract withPluginAtFront(plugin: KyselyPlugin): QueryExecutorBase;
|
|
58
|
+
/**
|
|
59
|
+
* Returns a copy of this executor without any plugins.
|
|
60
|
+
*/
|
|
61
|
+
abstract withoutPlugins(): QueryExecutorBase;
|
|
62
|
+
}
|