kysely 0.16.3 → 0.16.7
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 +122 -9
- package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +205 -0
- package/dist/cjs/dialect/mysql/mysql-dialect-config.js +2 -0
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -205
- package/dist/cjs/dialect/mysql/mysql-dialect.js +2 -1
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-driver.js +11 -3
- package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +103 -0
- package/dist/cjs/dialect/postgres/postgres-dialect-config.js +2 -0
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -103
- package/dist/cjs/dialect/postgres/postgres-dialect.js +2 -1
- package/dist/cjs/dialect/postgres/postgres-driver.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-driver.js +12 -3
- package/dist/cjs/dialect/sqlite/sqlite-dialect-config.d.ts +43 -0
- package/dist/cjs/dialect/sqlite/sqlite-dialect-config.js +2 -0
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -43
- package/dist/cjs/dialect/sqlite/sqlite-dialect.js +2 -1
- package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +11 -3
- package/dist/cjs/driver/dummy-driver.d.ts +68 -0
- package/dist/cjs/driver/dummy-driver.js +62 -0
- package/dist/cjs/driver/runtime-driver.d.ts +1 -1
- package/dist/cjs/driver/runtime-driver.js +30 -33
- package/dist/cjs/index-nodeless.d.ts +2 -0
- package/dist/cjs/index-nodeless.js +2 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/kysely.d.ts +8 -6
- package/dist/cjs/kysely.js +8 -6
- package/dist/cjs/migration/migrator.d.ts +2 -2
- package/dist/cjs/operation-node/primitive-value-list-node.d.ts +2 -3
- package/dist/cjs/operation-node/value-node.d.ts +3 -4
- package/dist/cjs/parser/complex-expression-parser.d.ts +1 -0
- package/dist/cjs/parser/complex-expression-parser.js +5 -1
- package/dist/cjs/parser/default-value-parser.d.ts +2 -3
- package/dist/cjs/parser/default-value-parser.js +2 -2
- package/dist/cjs/parser/insert-values-parser.js +4 -3
- package/dist/cjs/parser/reference-parser.d.ts +2 -3
- package/dist/cjs/parser/value-parser.d.ts +2 -3
- package/dist/cjs/parser/value-parser.js +6 -7
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.js +19 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.js +42 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +51 -9
- package/dist/cjs/query-builder/delete-query-builder.js +56 -8
- package/dist/cjs/query-builder/expression-builder.d.ts +1 -1
- package/dist/cjs/query-builder/expression-builder.js +2 -2
- package/dist/cjs/query-builder/function-builder.d.ts +29 -5
- package/dist/cjs/query-builder/function-builder.js +31 -7
- package/dist/cjs/query-builder/insert-query-builder.d.ts +53 -11
- package/dist/cjs/query-builder/insert-query-builder.js +58 -10
- package/dist/cjs/query-builder/select-query-builder.d.ts +58 -16
- package/dist/cjs/query-builder/select-query-builder.js +64 -15
- package/dist/cjs/query-builder/update-query-builder.d.ts +52 -9
- package/dist/cjs/query-builder/update-query-builder.js +57 -8
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +1 -2
- package/dist/cjs/query-creator.d.ts +2 -2
- package/dist/cjs/query-creator.js +2 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +30 -4
- package/dist/cjs/schema/alter-table-builder.js +2 -5
- package/dist/cjs/schema/column-definition-builder.d.ts +27 -2
- package/dist/cjs/schema/create-view-builder.js +1 -1
- package/dist/cjs/util/log.d.ts +1 -0
- package/dist/cjs/util/log.js +3 -0
- package/dist/cjs/util/object-utils.d.ts +5 -5
- package/dist/cjs/util/object-utils.js +52 -11
- package/dist/cjs/util/type-utils.d.ts +21 -0
- package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +205 -0
- package/dist/esm/dialect/mysql/mysql-dialect-config.js +2 -0
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -205
- package/dist/esm/dialect/mysql/mysql-dialect.js +2 -1
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-driver.js +12 -4
- package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +103 -0
- package/dist/esm/dialect/postgres/postgres-dialect-config.js +2 -0
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -103
- package/dist/esm/dialect/postgres/postgres-dialect.js +2 -1
- package/dist/esm/dialect/postgres/postgres-driver.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-driver.js +12 -3
- package/dist/esm/dialect/sqlite/sqlite-dialect-config.d.ts +43 -0
- package/dist/esm/dialect/sqlite/sqlite-dialect-config.js +2 -0
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -43
- package/dist/esm/dialect/sqlite/sqlite-dialect.js +2 -1
- package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-driver.js +12 -4
- package/dist/esm/driver/dummy-driver.d.ts +68 -0
- package/dist/esm/driver/dummy-driver.js +59 -0
- package/dist/esm/driver/runtime-driver.d.ts +1 -1
- package/dist/esm/driver/runtime-driver.js +29 -32
- package/dist/esm/index-nodeless.d.ts +2 -0
- package/dist/esm/index-nodeless.js +2 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/kysely.d.ts +8 -6
- package/dist/esm/kysely.js +8 -6
- package/dist/esm/migration/migrator.d.ts +2 -2
- package/dist/esm/operation-node/primitive-value-list-node.d.ts +2 -3
- package/dist/esm/operation-node/value-node.d.ts +3 -4
- package/dist/esm/parser/complex-expression-parser.d.ts +1 -0
- package/dist/esm/parser/complex-expression-parser.js +3 -0
- package/dist/esm/parser/default-value-parser.d.ts +2 -3
- package/dist/esm/parser/default-value-parser.js +2 -2
- package/dist/esm/parser/insert-values-parser.js +5 -4
- package/dist/esm/parser/reference-parser.d.ts +2 -3
- package/dist/esm/parser/reference-parser.js +1 -1
- package/dist/esm/parser/value-parser.d.ts +2 -3
- package/dist/esm/parser/value-parser.js +8 -9
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.js +16 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.js +39 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +51 -9
- package/dist/esm/query-builder/delete-query-builder.js +56 -8
- package/dist/esm/query-builder/expression-builder.d.ts +1 -1
- package/dist/esm/query-builder/expression-builder.js +1 -1
- package/dist/esm/query-builder/function-builder.d.ts +29 -5
- package/dist/esm/query-builder/function-builder.js +31 -7
- package/dist/esm/query-builder/insert-query-builder.d.ts +53 -11
- package/dist/esm/query-builder/insert-query-builder.js +58 -10
- package/dist/esm/query-builder/select-query-builder.d.ts +58 -16
- package/dist/esm/query-builder/select-query-builder.js +64 -15
- package/dist/esm/query-builder/update-query-builder.d.ts +52 -9
- package/dist/esm/query-builder/update-query-builder.js +57 -8
- package/dist/esm/query-compiler/default-query-compiler.d.ts +1 -2
- package/dist/esm/query-creator.d.ts +2 -2
- package/dist/esm/query-creator.js +2 -2
- package/dist/esm/schema/alter-table-builder.d.ts +30 -4
- package/dist/esm/schema/alter-table-builder.js +2 -5
- package/dist/esm/schema/column-definition-builder.d.ts +27 -2
- package/dist/esm/schema/create-view-builder.js +1 -1
- package/dist/esm/util/log.d.ts +1 -0
- package/dist/esm/util/log.js +3 -0
- package/dist/esm/util/object-utils.d.ts +5 -5
- package/dist/esm/util/object-utils.js +50 -9
- package/dist/esm/util/type-utils.d.ts +21 -0
- package/package.json +11 -5
- package/.prettierignore +0 -1
- package/dist/cjs/util/dynamic-import.d.ts +0 -2
- package/dist/cjs/util/dynamic-import.js +0 -32
- package/dist/esm/util/dynamic-import.d.ts +0 -2
- package/dist/esm/util/dynamic-import.js +0 -28
|
@@ -6,13 +6,14 @@ import { SelectExpression } from '../parser/select-parser.js';
|
|
|
6
6
|
import { ExistsExpression, FilterOperator, FilterValueExpressionOrList, WhereGrouper } from '../parser/filter-parser.js';
|
|
7
7
|
import { ReturningRow } from '../parser/returning-parser.js';
|
|
8
8
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
9
|
-
import { AnyRawBuilder, SingleResultType } from '../util/type-utils.js';
|
|
9
|
+
import { AnyRawBuilder, MergePartial, SingleResultType } from '../util/type-utils.js';
|
|
10
10
|
import { UpdateQueryNode } from '../operation-node/update-query-node.js';
|
|
11
11
|
import { MutationObject } from '../parser/update-set-parser.js';
|
|
12
12
|
import { Compilable } from '../util/compilable.js';
|
|
13
13
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
14
14
|
import { QueryId } from '../util/query-id.js';
|
|
15
15
|
import { ParseContext } from '../parser/parse-context.js';
|
|
16
|
+
import { UpdateResult } from './update-result.js';
|
|
16
17
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
17
18
|
import { WhereInterface } from './where-interface.js';
|
|
18
19
|
import { JoinInterface } from './join-interface.js';
|
|
@@ -676,24 +677,63 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
676
677
|
/**
|
|
677
678
|
* Simply calls the given function passing `this` as the only argument.
|
|
678
679
|
*
|
|
679
|
-
*
|
|
680
|
+
* If you want to conditionally call a method on `this`, see
|
|
681
|
+
* the {@link if} method.
|
|
680
682
|
*
|
|
681
683
|
* ### Examples
|
|
682
684
|
*
|
|
685
|
+
* The next example uses a helper funtion `log` to log a query:
|
|
686
|
+
*
|
|
683
687
|
* ```ts
|
|
688
|
+
* function log<T extends Compilable>(qb: T): T {
|
|
689
|
+
* console.log(qb.compile())
|
|
690
|
+
* return qb
|
|
691
|
+
* }
|
|
692
|
+
*
|
|
684
693
|
* db.updateTable('person')
|
|
685
694
|
* .set(values)
|
|
686
|
-
* .call(
|
|
687
|
-
* if (something) {
|
|
688
|
-
* return qb.where('something', '=', something)
|
|
689
|
-
* } else {
|
|
690
|
-
* return qb.where('somethingElse', '=', somethingElse)
|
|
691
|
-
* }
|
|
692
|
-
* })
|
|
695
|
+
* .call(log)
|
|
693
696
|
* .execute()
|
|
694
697
|
* ```
|
|
695
698
|
*/
|
|
696
699
|
call<T>(func: (qb: this) => T): T;
|
|
700
|
+
/**
|
|
701
|
+
* Call `func(this)` if `condition` is true.
|
|
702
|
+
*
|
|
703
|
+
* This method is especially handy with optional selects. Any `returning` or `returningAll`
|
|
704
|
+
* method calls add columns as optional fields to the output type when called inside
|
|
705
|
+
* the `func` callback. This is because we can't know if those selections were actually
|
|
706
|
+
* made before running the code.
|
|
707
|
+
*
|
|
708
|
+
* You can also call any other methods inside the callback.
|
|
709
|
+
*
|
|
710
|
+
* ### Examples
|
|
711
|
+
*
|
|
712
|
+
* ```ts
|
|
713
|
+
* async function updatePerson(id: number, updates: UpdateablePerson, returnLastName: boolean) {
|
|
714
|
+
* return await db
|
|
715
|
+
* .updateTable('person')
|
|
716
|
+
* .set(updates)
|
|
717
|
+
* .where('id', '=', id)
|
|
718
|
+
* .returning(['id', 'first_name'])
|
|
719
|
+
* .if(returnLastName, (qb) => qb.returning('last_name'))
|
|
720
|
+
* .executeTakeFirstOrThrow()
|
|
721
|
+
* }
|
|
722
|
+
* ```
|
|
723
|
+
*
|
|
724
|
+
* Any selections added inside the `if` callback will be added as optional fields to the
|
|
725
|
+
* output type since we can't know if the selections were actually made before running
|
|
726
|
+
* the code. In the example above the return type of the `updatePerson` function is:
|
|
727
|
+
*
|
|
728
|
+
* ```ts
|
|
729
|
+
* {
|
|
730
|
+
* id: number
|
|
731
|
+
* first_name: string
|
|
732
|
+
* last_name?: string
|
|
733
|
+
* }
|
|
734
|
+
* ```
|
|
735
|
+
*/
|
|
736
|
+
if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, TB, O2>): UpdateQueryBuilder<DB, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
|
|
697
737
|
/**
|
|
698
738
|
* Change the output type of the query.
|
|
699
739
|
*
|
|
@@ -701,6 +741,9 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
701
741
|
* don't support your use case.
|
|
702
742
|
*/
|
|
703
743
|
castTo<T>(): UpdateQueryBuilder<DB, TB, T>;
|
|
744
|
+
/**
|
|
745
|
+
* Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
|
|
746
|
+
*/
|
|
704
747
|
withPlugin(plugin: KyselyPlugin): UpdateQueryBuilder<DB, TB, O>;
|
|
705
748
|
toOperationNode(): UpdateQueryNode;
|
|
706
749
|
compile(): CompiledQuery;
|
|
@@ -194,26 +194,72 @@ class UpdateQueryBuilder {
|
|
|
194
194
|
/**
|
|
195
195
|
* Simply calls the given function passing `this` as the only argument.
|
|
196
196
|
*
|
|
197
|
-
*
|
|
197
|
+
* If you want to conditionally call a method on `this`, see
|
|
198
|
+
* the {@link if} method.
|
|
198
199
|
*
|
|
199
200
|
* ### Examples
|
|
200
201
|
*
|
|
202
|
+
* The next example uses a helper funtion `log` to log a query:
|
|
203
|
+
*
|
|
201
204
|
* ```ts
|
|
205
|
+
* function log<T extends Compilable>(qb: T): T {
|
|
206
|
+
* console.log(qb.compile())
|
|
207
|
+
* return qb
|
|
208
|
+
* }
|
|
209
|
+
*
|
|
202
210
|
* db.updateTable('person')
|
|
203
211
|
* .set(values)
|
|
204
|
-
* .call(
|
|
205
|
-
* if (something) {
|
|
206
|
-
* return qb.where('something', '=', something)
|
|
207
|
-
* } else {
|
|
208
|
-
* return qb.where('somethingElse', '=', somethingElse)
|
|
209
|
-
* }
|
|
210
|
-
* })
|
|
212
|
+
* .call(log)
|
|
211
213
|
* .execute()
|
|
212
214
|
* ```
|
|
213
215
|
*/
|
|
214
216
|
call(func) {
|
|
215
217
|
return func(this);
|
|
216
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Call `func(this)` if `condition` is true.
|
|
221
|
+
*
|
|
222
|
+
* This method is especially handy with optional selects. Any `returning` or `returningAll`
|
|
223
|
+
* method calls add columns as optional fields to the output type when called inside
|
|
224
|
+
* the `func` callback. This is because we can't know if those selections were actually
|
|
225
|
+
* made before running the code.
|
|
226
|
+
*
|
|
227
|
+
* You can also call any other methods inside the callback.
|
|
228
|
+
*
|
|
229
|
+
* ### Examples
|
|
230
|
+
*
|
|
231
|
+
* ```ts
|
|
232
|
+
* async function updatePerson(id: number, updates: UpdateablePerson, returnLastName: boolean) {
|
|
233
|
+
* return await db
|
|
234
|
+
* .updateTable('person')
|
|
235
|
+
* .set(updates)
|
|
236
|
+
* .where('id', '=', id)
|
|
237
|
+
* .returning(['id', 'first_name'])
|
|
238
|
+
* .if(returnLastName, (qb) => qb.returning('last_name'))
|
|
239
|
+
* .executeTakeFirstOrThrow()
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* Any selections added inside the `if` callback will be added as optional fields to the
|
|
244
|
+
* output type since we can't know if the selections were actually made before running
|
|
245
|
+
* the code. In the example above the return type of the `updatePerson` function is:
|
|
246
|
+
*
|
|
247
|
+
* ```ts
|
|
248
|
+
* {
|
|
249
|
+
* id: number
|
|
250
|
+
* first_name: string
|
|
251
|
+
* last_name?: string
|
|
252
|
+
* }
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
if(condition, func) {
|
|
256
|
+
if (condition) {
|
|
257
|
+
return func(this);
|
|
258
|
+
}
|
|
259
|
+
return new UpdateQueryBuilder({
|
|
260
|
+
...this.#props,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
217
263
|
/**
|
|
218
264
|
* Change the output type of the query.
|
|
219
265
|
*
|
|
@@ -223,6 +269,9 @@ class UpdateQueryBuilder {
|
|
|
223
269
|
castTo() {
|
|
224
270
|
return new UpdateQueryBuilder(this.#props);
|
|
225
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
|
|
274
|
+
*/
|
|
226
275
|
withPlugin(plugin) {
|
|
227
276
|
return new UpdateQueryBuilder({
|
|
228
277
|
...this.#props,
|
|
@@ -44,7 +44,6 @@ import { ValueNode } from '../operation-node/value-node.js';
|
|
|
44
44
|
import { WhereNode } from '../operation-node/where-node.js';
|
|
45
45
|
import { CommonTableExpressionNode } from '../operation-node/common-table-expression-node.js';
|
|
46
46
|
import { WithNode } from '../operation-node/with-node.js';
|
|
47
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
48
47
|
import { CompiledQuery } from './compiled-query.js';
|
|
49
48
|
import { RootOperationNode, QueryCompiler } from './query-compiler.js';
|
|
50
49
|
import { HavingNode } from '../operation-node/having-node.js';
|
|
@@ -150,5 +149,5 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
150
149
|
protected getRightIdentifierWrapper(): string;
|
|
151
150
|
protected getCurrentParameterPlaceholder(): string;
|
|
152
151
|
protected addParameter(parameter: unknown): void;
|
|
153
|
-
protected appendImmediateValue(value:
|
|
152
|
+
protected appendImmediateValue(value: unknown): void;
|
|
154
153
|
}
|
|
@@ -162,7 +162,7 @@ export declare class QueryCreator<DB> {
|
|
|
162
162
|
/**
|
|
163
163
|
* Creates a delete query.
|
|
164
164
|
*
|
|
165
|
-
* See the {@link
|
|
165
|
+
* See the {@link DeleteQueryBuilder.where} method for examples on how to specify
|
|
166
166
|
* a where clause for the delete operation.
|
|
167
167
|
*
|
|
168
168
|
* The return value of the query is an instance of {@link DeleteResult}.
|
|
@@ -182,7 +182,7 @@ export declare class QueryCreator<DB> {
|
|
|
182
182
|
/**
|
|
183
183
|
* Creates an update query.
|
|
184
184
|
*
|
|
185
|
-
* See the {@link
|
|
185
|
+
* See the {@link UpdateQueryBuilder.where} method for examples on how to specify
|
|
186
186
|
* a where clause for the update operation.
|
|
187
187
|
*
|
|
188
188
|
* See the {@link UpdateQueryBuilder.set} method for examples on how to
|
|
@@ -78,7 +78,7 @@ class QueryCreator {
|
|
|
78
78
|
/**
|
|
79
79
|
* Creates a delete query.
|
|
80
80
|
*
|
|
81
|
-
* See the {@link
|
|
81
|
+
* See the {@link DeleteQueryBuilder.where} method for examples on how to specify
|
|
82
82
|
* a where clause for the delete operation.
|
|
83
83
|
*
|
|
84
84
|
* The return value of the query is an instance of {@link DeleteResult}.
|
|
@@ -105,7 +105,7 @@ class QueryCreator {
|
|
|
105
105
|
/**
|
|
106
106
|
* Creates an update query.
|
|
107
107
|
*
|
|
108
|
-
* See the {@link
|
|
108
|
+
* See the {@link UpdateQueryBuilder.where} method for examples on how to specify
|
|
109
109
|
* a where clause for the update operation.
|
|
110
110
|
*
|
|
111
111
|
* See the {@link UpdateQueryBuilder.set} method for examples on how to
|
|
@@ -5,13 +5,13 @@ import { OperationNodeSource } from '../operation-node/operation-node-source.js'
|
|
|
5
5
|
import { OnModifyForeignAction } from '../operation-node/references-node.js';
|
|
6
6
|
import { CompiledQuery } from '../query-compiler/compiled-query.js';
|
|
7
7
|
import { Compilable } from '../util/compilable.js';
|
|
8
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
9
8
|
import { ColumnDefinitionBuilder, ColumnDefinitionBuilderInterface } from './column-definition-builder.js';
|
|
10
9
|
import { AnyRawBuilder } from '../util/type-utils.js';
|
|
11
10
|
import { QueryId } from '../util/query-id.js';
|
|
12
11
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
13
12
|
import { DataTypeExpression } from '../parser/data-type-parser.js';
|
|
14
13
|
import { ForeignKeyConstraintBuilder, ForeignKeyConstraintBuilderInterface } from './foreign-key-constraint-builder.js';
|
|
14
|
+
import { DefaultValueExpression } from '../parser/default-value-parser.js';
|
|
15
15
|
/**
|
|
16
16
|
* This builder can be used to create a `alter table` query.
|
|
17
17
|
*/
|
|
@@ -43,7 +43,7 @@ export declare class AlterColumnBuilder {
|
|
|
43
43
|
#private;
|
|
44
44
|
constructor(props: AlterColumnBuilderProps);
|
|
45
45
|
setDataType(dataType: ColumnDataType): AlterTableExecutor;
|
|
46
|
-
setDefault(value:
|
|
46
|
+
setDefault(value: DefaultValueExpression): AlterTableExecutor;
|
|
47
47
|
dropDefault(): AlterTableExecutor;
|
|
48
48
|
setNotNull(): AlterTableExecutor;
|
|
49
49
|
dropNotNull(): AlterTableExecutor;
|
|
@@ -141,8 +141,21 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
141
141
|
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
|
142
142
|
* .execute()
|
|
143
143
|
* ```
|
|
144
|
+
*
|
|
145
|
+
* Raw expressions are also supported:
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* db.schema
|
|
149
|
+
* .createTable('pet')
|
|
150
|
+
* .addColumn(
|
|
151
|
+
* 'number_of_legs',
|
|
152
|
+
* 'integer',
|
|
153
|
+
* (col) => col.defaultTo(db.raw('any SQL here'))
|
|
154
|
+
* )
|
|
155
|
+
* .execute()
|
|
156
|
+
* ```
|
|
144
157
|
*/
|
|
145
|
-
defaultTo(value:
|
|
158
|
+
defaultTo(value: DefaultValueExpression): AlterTableAddColumnBuilder;
|
|
146
159
|
/**
|
|
147
160
|
* Adds a check constraint for the column.
|
|
148
161
|
*
|
|
@@ -286,8 +299,21 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
|
|
|
286
299
|
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
|
287
300
|
* .execute()
|
|
288
301
|
* ```
|
|
302
|
+
*
|
|
303
|
+
* Raw expressions are also supported:
|
|
304
|
+
*
|
|
305
|
+
* ```ts
|
|
306
|
+
* db.schema
|
|
307
|
+
* .createTable('pet')
|
|
308
|
+
* .addColumn(
|
|
309
|
+
* 'number_of_legs',
|
|
310
|
+
* 'integer',
|
|
311
|
+
* (col) => col.defaultTo(db.raw('any SQL here'))
|
|
312
|
+
* )
|
|
313
|
+
* .execute()
|
|
314
|
+
* ```
|
|
289
315
|
*/
|
|
290
|
-
defaultTo(value:
|
|
316
|
+
defaultTo(value: DefaultValueExpression): AlterTableModifyColumnBuilder;
|
|
291
317
|
/**
|
|
292
318
|
* Adds a check constraint for the column.
|
|
293
319
|
*
|
|
@@ -8,10 +8,8 @@ const column_definition_node_js_1 = require("../operation-node/column-definition
|
|
|
8
8
|
const data_type_node_js_1 = require("../operation-node/data-type-node.js");
|
|
9
9
|
const drop_column_node_js_1 = require("../operation-node/drop-column-node.js");
|
|
10
10
|
const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
|
11
|
-
const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
|
|
12
11
|
const rename_column_node_js_1 = require("../operation-node/rename-column-node.js");
|
|
13
12
|
const table_node_js_1 = require("../operation-node/table-node.js");
|
|
14
|
-
const value_node_js_1 = require("../operation-node/value-node.js");
|
|
15
13
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
16
14
|
const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
17
15
|
const column_definition_builder_js_1 = require("./column-definition-builder.js");
|
|
@@ -23,6 +21,7 @@ const unique_constraint_node_js_1 = require("../operation-node/unique-constraint
|
|
|
23
21
|
const check_constraint_node_js_1 = require("../operation-node/check-constraint-node.js");
|
|
24
22
|
const foreign_key_constraint_node_js_1 = require("../operation-node/foreign-key-constraint-node.js");
|
|
25
23
|
const column_node_js_1 = require("../operation-node/column-node.js");
|
|
24
|
+
const default_value_parser_js_1 = require("../parser/default-value-parser.js");
|
|
26
25
|
/**
|
|
27
26
|
* This builder can be used to create a `alter table` query.
|
|
28
27
|
*/
|
|
@@ -130,9 +129,7 @@ class AlterColumnBuilder {
|
|
|
130
129
|
...this.#props,
|
|
131
130
|
alterTableNode: alter_table_node_js_1.AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
132
131
|
alterColumn: alter_column_node_js_1.AlterColumnNode.cloneWith(this.#props.alterColumnNode, {
|
|
133
|
-
setDefault: (0,
|
|
134
|
-
? value.toOperationNode()
|
|
135
|
-
: value_node_js_1.ValueNode.createImmediate(value),
|
|
132
|
+
setDefault: (0, default_value_parser_js_1.parseDefaultValueExpression)(value),
|
|
136
133
|
}),
|
|
137
134
|
}),
|
|
138
135
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
|
2
2
|
import { OnModifyForeignAction } from '../operation-node/references-node.js';
|
|
3
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
4
3
|
import { ColumnDefinitionNode } from '../operation-node/column-definition-node.js';
|
|
5
4
|
import { AnyRawBuilder } from '../util/type-utils.js';
|
|
6
5
|
import { DefaultValueExpression } from '../parser/default-value-parser.js';
|
|
@@ -83,8 +82,21 @@ export interface ColumnDefinitionBuilderInterface {
|
|
|
83
82
|
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
|
84
83
|
* .execute()
|
|
85
84
|
* ```
|
|
85
|
+
*
|
|
86
|
+
* Raw expressions are also supported:
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* db.schema
|
|
90
|
+
* .createTable('pet')
|
|
91
|
+
* .addColumn(
|
|
92
|
+
* 'number_of_legs',
|
|
93
|
+
* 'integer',
|
|
94
|
+
* (col) => col.defaultTo(db.raw('any SQL here'))
|
|
95
|
+
* )
|
|
96
|
+
* .execute()
|
|
97
|
+
* ```
|
|
86
98
|
*/
|
|
87
|
-
defaultTo(value:
|
|
99
|
+
defaultTo(value: DefaultValueExpression): ColumnDefinitionBuilderInterface;
|
|
88
100
|
/**
|
|
89
101
|
* Adds a check constraint for the column.
|
|
90
102
|
*
|
|
@@ -222,6 +234,19 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
|
|
|
222
234
|
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
|
223
235
|
* .execute()
|
|
224
236
|
* ```
|
|
237
|
+
*
|
|
238
|
+
* Raw expressions are also supported:
|
|
239
|
+
*
|
|
240
|
+
* ```ts
|
|
241
|
+
* db.schema
|
|
242
|
+
* .createTable('pet')
|
|
243
|
+
* .addColumn(
|
|
244
|
+
* 'number_of_legs',
|
|
245
|
+
* 'integer',
|
|
246
|
+
* (col) => col.defaultTo(db.raw('any SQL here'))
|
|
247
|
+
* )
|
|
248
|
+
* .execute()
|
|
249
|
+
* ```
|
|
225
250
|
*/
|
|
226
251
|
defaultTo(value: DefaultValueExpression): ColumnDefinitionBuilder;
|
|
227
252
|
/**
|
|
@@ -5,7 +5,7 @@ const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
|
5
5
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
6
6
|
const create_view_node_js_1 = require("../operation-node/create-view-node.js");
|
|
7
7
|
const reference_parser_js_1 = require("../parser/reference-parser.js");
|
|
8
|
-
const immediate_value_plugin_js_1 = require("../plugin/immediate-value
|
|
8
|
+
const immediate_value_plugin_js_1 = require("../plugin/immediate-value/immediate-value-plugin.js");
|
|
9
9
|
class CreateViewBuilder {
|
|
10
10
|
#props;
|
|
11
11
|
constructor(props) {
|
package/dist/cjs/util/log.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare type LogConfig = ReadonlyArray<LogLevel> | Logger;
|
|
|
17
17
|
export declare class Log {
|
|
18
18
|
#private;
|
|
19
19
|
constructor(config: LogConfig);
|
|
20
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
20
21
|
query(getEvent: () => QueryLogEvent): void;
|
|
21
22
|
error(getEvent: () => ErrorLogEvent): void;
|
|
22
23
|
}
|
package/dist/cjs/util/log.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
export declare type PrimitiveValue = string | number | boolean | null | Date | Buffer | BigInt;
|
|
3
|
-
export declare function isEmpty(obj: ArrayLike<unknown> | string | object | Buffer): boolean;
|
|
1
|
+
export declare function isEmpty(obj: ArrayLike<unknown> | string | object): boolean;
|
|
4
2
|
export declare function isString(obj: unknown): obj is string;
|
|
5
3
|
export declare function isNumber(obj: unknown): obj is number;
|
|
6
4
|
export declare function isBoolean(obj: unknown): obj is boolean;
|
|
7
5
|
export declare function isNull(obj: unknown): obj is null;
|
|
8
6
|
export declare function isDate(obj: unknown): obj is Date;
|
|
9
7
|
export declare function isBigInt(obj: unknown): obj is BigInt;
|
|
10
|
-
export declare function isBuffer(obj: unknown): obj is
|
|
11
|
-
|
|
8
|
+
export declare function isBuffer(obj: unknown): obj is {
|
|
9
|
+
length: number;
|
|
10
|
+
};
|
|
12
11
|
export declare function isFunction(obj: unknown): obj is Function;
|
|
13
12
|
export declare function isObject(obj: unknown): obj is Record<string, unknown>;
|
|
14
13
|
export declare function getLast<T>(arr: ArrayLike<T>): T | undefined;
|
|
@@ -17,3 +16,4 @@ export declare function asArray<T>(arg: T | T[]): T[];
|
|
|
17
16
|
export declare function asReadonlyArray<T>(arg: T | ReadonlyArray<T>): ReadonlyArray<T>;
|
|
18
17
|
export declare function isReadonlyArray(arg: unknown): arg is ReadonlyArray<unknown>;
|
|
19
18
|
export declare function noop<T>(obj: T): T;
|
|
19
|
+
export declare function compare(obj1: unknown, obj2: unknown): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noop = exports.isReadonlyArray = exports.asReadonlyArray = exports.asArray = exports.freeze = exports.getLast = exports.isObject = exports.isFunction = exports.
|
|
3
|
+
exports.compare = exports.noop = exports.isReadonlyArray = exports.asReadonlyArray = exports.asArray = exports.freeze = exports.getLast = exports.isObject = exports.isFunction = exports.isBuffer = exports.isBigInt = exports.isDate = exports.isNull = exports.isBoolean = exports.isNumber = exports.isString = exports.isEmpty = void 0;
|
|
4
4
|
function isEmpty(obj) {
|
|
5
5
|
if (Array.isArray(obj) || isString(obj) || isBuffer(obj)) {
|
|
6
6
|
return obj.length === 0;
|
|
@@ -35,20 +35,12 @@ function isBigInt(obj) {
|
|
|
35
35
|
return typeof obj === 'bigint';
|
|
36
36
|
}
|
|
37
37
|
exports.isBigInt = isBigInt;
|
|
38
|
+
// Don't change the returnd type to `obj is Buffer` to not create a
|
|
39
|
+
// hard dependency to node.
|
|
38
40
|
function isBuffer(obj) {
|
|
39
41
|
return typeof Buffer !== 'undefined' && Buffer.isBuffer(obj);
|
|
40
42
|
}
|
|
41
43
|
exports.isBuffer = isBuffer;
|
|
42
|
-
function isPrimitive(obj) {
|
|
43
|
-
return (isString(obj) ||
|
|
44
|
-
isNumber(obj) ||
|
|
45
|
-
isBoolean(obj) ||
|
|
46
|
-
isNull(obj) ||
|
|
47
|
-
isDate(obj) ||
|
|
48
|
-
isBigInt(obj) ||
|
|
49
|
-
isBuffer(obj));
|
|
50
|
-
}
|
|
51
|
-
exports.isPrimitive = isPrimitive;
|
|
52
44
|
function isFunction(obj) {
|
|
53
45
|
return typeof obj === 'function';
|
|
54
46
|
}
|
|
@@ -91,3 +83,52 @@ function noop(obj) {
|
|
|
91
83
|
return obj;
|
|
92
84
|
}
|
|
93
85
|
exports.noop = noop;
|
|
86
|
+
function compare(obj1, obj2) {
|
|
87
|
+
if (isReadonlyArray(obj1) && isReadonlyArray(obj2)) {
|
|
88
|
+
return compareArrays(obj1, obj2);
|
|
89
|
+
}
|
|
90
|
+
else if (isObject(obj1) && isObject(obj2)) {
|
|
91
|
+
return compareObjects(obj1, obj2);
|
|
92
|
+
}
|
|
93
|
+
return obj1 === obj2;
|
|
94
|
+
}
|
|
95
|
+
exports.compare = compare;
|
|
96
|
+
function compareArrays(arr1, arr2) {
|
|
97
|
+
if (arr1.length !== arr2.length) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
for (let i = 0; i < arr1.length; ++i) {
|
|
101
|
+
if (!compare(arr1[i], arr2[i])) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
function compareObjects(obj1, obj2) {
|
|
108
|
+
if (isBuffer(obj1) && isBuffer(obj2)) {
|
|
109
|
+
return compareBuffers(obj1, obj2);
|
|
110
|
+
}
|
|
111
|
+
else if (isDate(obj1) && isDate(obj2)) {
|
|
112
|
+
return compareDates(obj1, obj2);
|
|
113
|
+
}
|
|
114
|
+
return compareGenericObjects(obj1, obj2);
|
|
115
|
+
}
|
|
116
|
+
function compareBuffers(buf1, buf2) {
|
|
117
|
+
return Buffer.compare(buf1, buf2) === 0;
|
|
118
|
+
}
|
|
119
|
+
function compareDates(date1, date2) {
|
|
120
|
+
return date1.getTime() === date2.getTime();
|
|
121
|
+
}
|
|
122
|
+
function compareGenericObjects(obj1, obj2) {
|
|
123
|
+
const keys1 = Object.keys(obj1);
|
|
124
|
+
const keys2 = Object.keys(obj2);
|
|
125
|
+
if (keys1.length !== keys2.length) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
for (const key of keys1) {
|
|
129
|
+
if (!compare(obj1[key], obj2[key])) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
@@ -111,3 +111,24 @@ export declare type UnknownRow = Record<string, unknown>;
|
|
|
111
111
|
export declare type Nullable<T> = {
|
|
112
112
|
[P in keyof T]: T[P] | null;
|
|
113
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Takes all properties from T1 and merges all properties from T2
|
|
116
|
+
* that don't exist in T1 as optional properties.
|
|
117
|
+
*
|
|
118
|
+
* Example:
|
|
119
|
+
*
|
|
120
|
+
* interface Person {
|
|
121
|
+
* name: string
|
|
122
|
+
* age: number
|
|
123
|
+
* }
|
|
124
|
+
*
|
|
125
|
+
* interface Pet {
|
|
126
|
+
* name: string
|
|
127
|
+
* species: 'cat' | 'dog'
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
130
|
+
* type Merged = MergePartial<Person, Pet>
|
|
131
|
+
*
|
|
132
|
+
* // { name: string, age: number, species?: 'cat' | 'dog' }
|
|
133
|
+
*/
|
|
134
|
+
export declare type MergePartial<T1, T2> = T1 & Partial<Omit<T2, keyof T1>>;
|