kysely 0.12.1 → 0.12.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/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/kysely.d.ts +151 -0
- package/dist/cjs/kysely.js +37 -0
- package/dist/cjs/operation-node/common-table-expression-name-node.d.ts +15 -0
- package/dist/cjs/operation-node/common-table-expression-name-node.js +23 -0
- package/dist/cjs/operation-node/common-table-expression-node.d.ts +3 -3
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +9 -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/with-node.d.ts +3 -1
- package/dist/cjs/operation-node/with-node.js +2 -1
- package/dist/cjs/parser/with-parser.d.ts +32 -5
- package/dist/cjs/parser/with-parser.js +13 -2
- package/dist/cjs/plugin/with-schema/with-schema-transformer.js +8 -0
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +11 -0
- package/dist/cjs/query-creator.d.ts +27 -3
- package/dist/cjs/query-creator.js +33 -1
- package/dist/cjs/query-executor/default-query-executor.d.ts +19 -0
- package/dist/cjs/query-executor/noop-query-executor.d.ts +19 -0
- package/dist/cjs/raw-builder/raw-builder.js +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/kysely.d.ts +151 -0
- package/dist/esm/kysely.js +37 -0
- package/dist/esm/operation-node/common-table-expression-name-node.d.ts +15 -0
- package/dist/esm/operation-node/common-table-expression-name-node.js +20 -0
- package/dist/esm/operation-node/common-table-expression-node.d.ts +3 -3
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +9 -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/with-node.d.ts +3 -1
- package/dist/esm/operation-node/with-node.js +2 -1
- package/dist/esm/parser/with-parser.d.ts +32 -5
- package/dist/esm/parser/with-parser.js +13 -2
- package/dist/esm/plugin/with-schema/with-schema-transformer.js +8 -0
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/esm/query-compiler/default-query-compiler.js +11 -0
- package/dist/esm/query-creator.d.ts +27 -3
- package/dist/esm/query-creator.js +33 -1
- package/dist/esm/query-executor/default-query-executor.d.ts +19 -0
- package/dist/esm/query-executor/noop-query-executor.d.ts +19 -0
- package/dist/esm/raw-builder/raw-builder.js +1 -1
- package/package.json +2 -2
|
@@ -570,6 +570,9 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
570
570
|
}
|
|
571
571
|
visitWith(node) {
|
|
572
572
|
this.append('with ');
|
|
573
|
+
if (node.recursive) {
|
|
574
|
+
this.append('recursive ');
|
|
575
|
+
}
|
|
573
576
|
this.compileList(node.expressions);
|
|
574
577
|
}
|
|
575
578
|
visitCommonTableExpression(node) {
|
|
@@ -577,6 +580,14 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
577
580
|
this.append(' as ');
|
|
578
581
|
this.visitNode(node.expression);
|
|
579
582
|
}
|
|
583
|
+
visitCommonTableExpressionName(node) {
|
|
584
|
+
this.visitNode(node.table);
|
|
585
|
+
if (node.columns) {
|
|
586
|
+
this.append('(');
|
|
587
|
+
this.compileList(node.columns);
|
|
588
|
+
this.append(')');
|
|
589
|
+
}
|
|
590
|
+
}
|
|
580
591
|
visitAlterTable(node) {
|
|
581
592
|
this.append('alter table ');
|
|
582
593
|
this.visitNode(node.table);
|
|
@@ -5,7 +5,7 @@ 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
7
|
import { RawBuilder } from './raw-builder/raw-builder.js';
|
|
8
|
-
import { CommonTableExpression, QueryCreatorWithCommonTableExpression } from './parser/with-parser.js';
|
|
8
|
+
import { CommonTableExpression, QueryCreatorWithCommonTableExpression, RecursiveCommonTableExpression } from './parser/with-parser.js';
|
|
9
9
|
import { WithNode } from './operation-node/with-node.js';
|
|
10
10
|
import { ParseContext } from './parser/parse-context.js';
|
|
11
11
|
import { InsertResult } from './query-builder/insert-result.js';
|
|
@@ -206,7 +206,7 @@ export declare class QueryCreator<DB> {
|
|
|
206
206
|
*/
|
|
207
207
|
updateTable<TR extends TableReference<DB>>(table: TR): UpdateQueryBuilder<TableExpressionDatabase<DB, TR>, TableExpressionTables<DB, never, TR>, UpdateResult>;
|
|
208
208
|
/**
|
|
209
|
-
* Creates a `with` query (
|
|
209
|
+
* Creates a `with` query (Common Table Expression).
|
|
210
210
|
*
|
|
211
211
|
* ### Examples
|
|
212
212
|
*
|
|
@@ -227,8 +227,32 @@ export declare class QueryCreator<DB> {
|
|
|
227
227
|
* .selectAll()
|
|
228
228
|
* .execute()
|
|
229
229
|
* ```
|
|
230
|
+
*
|
|
231
|
+
* The CTE name can optionally specify column names in addition to
|
|
232
|
+
* a name. In that case Kysely requires the expression to retun
|
|
233
|
+
* rows with the same columns.
|
|
234
|
+
*
|
|
235
|
+
* ```ts
|
|
236
|
+
* await db
|
|
237
|
+
* .with('jennifers(id, age)', (db) => db
|
|
238
|
+
* .selectFrom('person')
|
|
239
|
+
* .where('first_name', '=', 'Jennifer')
|
|
240
|
+
* // This is ok since we return columns with the same
|
|
241
|
+
* // names as specified by `jennifers(id, age)`.
|
|
242
|
+
* .select(['id', 'age'])
|
|
243
|
+
* )
|
|
244
|
+
* .selectFrom('jennifers')
|
|
245
|
+
* .selectAll()
|
|
246
|
+
* .execute()
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
with<N extends string, E extends CommonTableExpression<DB, N>>(name: N, expression: E): QueryCreatorWithCommonTableExpression<DB, N, E>;
|
|
250
|
+
/**
|
|
251
|
+
* Creates a recursive `with` query (Common Table Expression).
|
|
252
|
+
*
|
|
253
|
+
* See the {@link with} method for examples and more documentation.
|
|
230
254
|
*/
|
|
231
|
-
|
|
255
|
+
withRecursive<N extends string, E extends RecursiveCommonTableExpression<DB, N>>(name: N, expression: E): QueryCreatorWithCommonTableExpression<DB, N, E>;
|
|
232
256
|
/**
|
|
233
257
|
* Sets the schema to be used for all table references that don't explicitly
|
|
234
258
|
* specify a schema.
|
|
@@ -133,7 +133,7 @@ export class QueryCreator {
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
|
-
* Creates a `with` query (
|
|
136
|
+
* Creates a `with` query (Common Table Expression).
|
|
137
137
|
*
|
|
138
138
|
* ### Examples
|
|
139
139
|
*
|
|
@@ -154,6 +154,24 @@ export class QueryCreator {
|
|
|
154
154
|
* .selectAll()
|
|
155
155
|
* .execute()
|
|
156
156
|
* ```
|
|
157
|
+
*
|
|
158
|
+
* The CTE name can optionally specify column names in addition to
|
|
159
|
+
* a name. In that case Kysely requires the expression to retun
|
|
160
|
+
* rows with the same columns.
|
|
161
|
+
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* await db
|
|
164
|
+
* .with('jennifers(id, age)', (db) => db
|
|
165
|
+
* .selectFrom('person')
|
|
166
|
+
* .where('first_name', '=', 'Jennifer')
|
|
167
|
+
* // This is ok since we return columns with the same
|
|
168
|
+
* // names as specified by `jennifers(id, age)`.
|
|
169
|
+
* .select(['id', 'age'])
|
|
170
|
+
* )
|
|
171
|
+
* .selectFrom('jennifers')
|
|
172
|
+
* .selectAll()
|
|
173
|
+
* .execute()
|
|
174
|
+
* ```
|
|
157
175
|
*/
|
|
158
176
|
with(name, expression) {
|
|
159
177
|
const cte = parseCommonTableExpression(this.#props.parseContext, name, expression);
|
|
@@ -164,6 +182,20 @@ export class QueryCreator {
|
|
|
164
182
|
: WithNode.create(cte),
|
|
165
183
|
});
|
|
166
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Creates a recursive `with` query (Common Table Expression).
|
|
187
|
+
*
|
|
188
|
+
* See the {@link with} method for examples and more documentation.
|
|
189
|
+
*/
|
|
190
|
+
withRecursive(name, expression) {
|
|
191
|
+
const cte = parseCommonTableExpression(this.#props.parseContext, name, expression);
|
|
192
|
+
return new QueryCreator({
|
|
193
|
+
...this.#props,
|
|
194
|
+
withNode: this.#props.withNode
|
|
195
|
+
? WithNode.cloneWithExpression(this.#props.withNode, cte)
|
|
196
|
+
: WithNode.create(cte, { recursive: true }),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
167
199
|
/**
|
|
168
200
|
* Sets the schema to be used for all table references that don't explicitly
|
|
169
201
|
* specify a schema.
|
|
@@ -7,10 +7,29 @@ import { QueryExecutor } from './query-executor.js';
|
|
|
7
7
|
export declare class DefaultQueryExecutor extends QueryExecutor {
|
|
8
8
|
#private;
|
|
9
9
|
constructor(compiler: QueryCompiler, connectionProvider: ConnectionProvider, plugins?: KyselyPlugin[]);
|
|
10
|
+
/**
|
|
11
|
+
* Compiles the transformed query into SQL. You usually want to pass
|
|
12
|
+
* the output of {@link transformQuery} into this method but you can
|
|
13
|
+
* compile any query using this method.
|
|
14
|
+
*/
|
|
10
15
|
compileQuery(node: RootOperationNode): CompiledQuery;
|
|
11
16
|
protected executeQueryImpl<R>(compiledQuery: CompiledQuery): Promise<QueryResult<R>>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns a copy of this executor with a plugin added as the
|
|
19
|
+
* last plugin.
|
|
20
|
+
*/
|
|
12
21
|
withPlugin(plugin: KyselyPlugin): DefaultQueryExecutor;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a copy of this executor with a plugin added as the
|
|
24
|
+
* first plugin.
|
|
25
|
+
*/
|
|
13
26
|
withPluginAtFront(plugin: KyselyPlugin): DefaultQueryExecutor;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a copy of this executor with a new connection provider.
|
|
29
|
+
*/
|
|
14
30
|
withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutor;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a copy of this executor without any plugins.
|
|
33
|
+
*/
|
|
15
34
|
withoutPlugins(): QueryExecutor;
|
|
16
35
|
}
|
|
@@ -8,10 +8,29 @@ import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
|
8
8
|
* other needed things to actually execute queries.
|
|
9
9
|
*/
|
|
10
10
|
export declare class NoopQueryExecutor extends QueryExecutor {
|
|
11
|
+
/**
|
|
12
|
+
* Compiles the transformed query into SQL. You usually want to pass
|
|
13
|
+
* the output of {@link transformQuery} into this method but you can
|
|
14
|
+
* compile any query using this method.
|
|
15
|
+
*/
|
|
11
16
|
compileQuery(): CompiledQuery;
|
|
12
17
|
protected executeQueryImpl<R>(): Promise<QueryResult<R>>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a copy of this executor with a new connection provider.
|
|
20
|
+
*/
|
|
13
21
|
withConnectionProvider(): QueryExecutor;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a copy of this executor with a plugin added as the
|
|
24
|
+
* last plugin.
|
|
25
|
+
*/
|
|
14
26
|
withPlugin(plugin: KyselyPlugin): NoopQueryExecutor;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a copy of this executor with a plugin added as the
|
|
29
|
+
* first plugin.
|
|
30
|
+
*/
|
|
15
31
|
withPluginAtFront(plugin: KyselyPlugin): NoopQueryExecutor;
|
|
32
|
+
/**
|
|
33
|
+
* Returns a copy of this executor without any plugins.
|
|
34
|
+
*/
|
|
16
35
|
withoutPlugins(): QueryExecutor;
|
|
17
36
|
}
|
|
@@ -47,7 +47,7 @@ export class RawBuilder {
|
|
|
47
47
|
if (match.index > 0 && sql[match.index - 1] === '\\') {
|
|
48
48
|
continue;
|
|
49
49
|
}
|
|
50
|
-
sqlFragments.push(sql.slice(sqlIdx, match.index).
|
|
50
|
+
sqlFragments.push(sql.slice(sqlIdx, match.index).replace(/\\\?/g, '?'));
|
|
51
51
|
argNodes.push(parseRawArg(str, parameters[paramIdx]));
|
|
52
52
|
sqlIdx = match.index + str.length;
|
|
53
53
|
++paramIdx;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kysely",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Type safe SQL query builder",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git://github.com/koskimas/kysely.git"
|
|
8
8
|
},
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
10
|
+
"node": ">=14.0.0"
|
|
11
11
|
},
|
|
12
12
|
"main": "dist/cjs/index.js",
|
|
13
13
|
"module": "dist/esm/index.js",
|