kysely 0.16.4 → 0.16.5
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/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/query-builder/expression-builder.d.ts +1 -1
- package/dist/cjs/query-builder/expression-builder.js +2 -2
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +1 -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/util/object-utils.d.ts +4 -5
- package/dist/cjs/util/object-utils.js +3 -11
- 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/query-builder/expression-builder.d.ts +1 -1
- package/dist/esm/query-builder/expression-builder.js +1 -1
- package/dist/esm/query-compiler/default-query-compiler.d.ts +1 -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/util/object-utils.d.ts +4 -5
- package/dist/esm/util/object-utils.js +2 -9
- package/package.json +1 -1
|
@@ -144,8 +144,8 @@ export interface MigratorProps {
|
|
|
144
144
|
readonly provider: MigrationProvider;
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
-
* All migration methods ({@link
|
|
148
|
-
* {@link
|
|
147
|
+
* All migration methods ({@link Migrator.migrateTo | migrateTo},
|
|
148
|
+
* {@link Migrator.migrateToLatest | migrateToLatest} etc.) never
|
|
149
149
|
* throw but return this object instead.
|
|
150
150
|
*/
|
|
151
151
|
export interface MigrationResultSet {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
3
2
|
/**
|
|
4
3
|
* This node is basically just a performance optimization over the normal ValueListNode.
|
|
@@ -7,12 +6,12 @@ import { OperationNode } from './operation-node.js';
|
|
|
7
6
|
*/
|
|
8
7
|
export interface PrimitiveValueListNode extends OperationNode {
|
|
9
8
|
readonly kind: 'PrimitiveValueListNode';
|
|
10
|
-
readonly values: ReadonlyArray<
|
|
9
|
+
readonly values: ReadonlyArray<unknown>;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* @internal
|
|
14
13
|
*/
|
|
15
14
|
export declare const PrimitiveValueListNode: Readonly<{
|
|
16
15
|
is(node: OperationNode): node is PrimitiveValueListNode;
|
|
17
|
-
create(values: ReadonlyArray<
|
|
16
|
+
create(values: ReadonlyArray<unknown>): PrimitiveValueListNode;
|
|
18
17
|
}>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
3
2
|
export interface ValueNode extends OperationNode {
|
|
4
3
|
readonly kind: 'ValueNode';
|
|
5
|
-
readonly value:
|
|
4
|
+
readonly value: unknown;
|
|
6
5
|
readonly immediate?: boolean;
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
@@ -10,6 +9,6 @@ export interface ValueNode extends OperationNode {
|
|
|
10
9
|
*/
|
|
11
10
|
export declare const ValueNode: Readonly<{
|
|
12
11
|
is(node: OperationNode): node is ValueNode;
|
|
13
|
-
create(value:
|
|
14
|
-
createImmediate(value:
|
|
12
|
+
create(value: unknown): ValueNode;
|
|
13
|
+
createImmediate(value: unknown): ValueNode;
|
|
15
14
|
}>;
|
|
@@ -7,3 +7,4 @@ export declare type ComplexExpression<DB, TB extends keyof DB> = AnySelectQueryB
|
|
|
7
7
|
export declare type AliasedComplexExpression<DB, TB extends keyof DB> = AnyAliasedQueryBuilder | AliasedQueryBuilderFactory<DB, TB> | AnyAliasedRawBuilder | AliasedRawBuilderFactory<DB, TB>;
|
|
8
8
|
export declare function parseComplexExpression(ctx: ParseContext, exp: ComplexExpression<any, any>): SelectQueryNode | RawNode;
|
|
9
9
|
export declare function parseAliasedComplexExpression(ctx: ParseContext, exp: AliasedComplexExpression<any, any>): AliasNode;
|
|
10
|
+
export declare function isComplexExpression(obj: unknown): obj is ComplexExpression<any, any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseAliasedComplexExpression = exports.parseComplexExpression = void 0;
|
|
3
|
+
exports.isComplexExpression = exports.parseAliasedComplexExpression = exports.parseComplexExpression = void 0;
|
|
4
4
|
const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
|
|
5
5
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
6
6
|
function parseComplexExpression(ctx, exp) {
|
|
@@ -23,3 +23,7 @@ function parseAliasedComplexExpression(ctx, exp) {
|
|
|
23
23
|
throw new Error(`invalid aliased expression: ${JSON.stringify(exp)}`);
|
|
24
24
|
}
|
|
25
25
|
exports.parseAliasedComplexExpression = parseAliasedComplexExpression;
|
|
26
|
+
function isComplexExpression(obj) {
|
|
27
|
+
return (0, operation_node_source_js_1.isOperationNodeSource)(obj) || (0, object_utils_js_1.isFunction)(obj);
|
|
28
|
+
}
|
|
29
|
+
exports.isComplexExpression = isComplexExpression;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RawNode } from '../operation-node/raw-node.js';
|
|
2
2
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare type DefaultValueExpression = PrimitiveValue | AnyRawBuilder;
|
|
3
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
4
|
+
export declare type DefaultValueExpression = unknown | RawBuilder;
|
|
6
5
|
export declare function parseDefaultValueExpression(value: DefaultValueExpression): ValueNode | RawNode;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseDefaultValueExpression = void 0;
|
|
4
|
-
const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
|
|
5
4
|
const value_node_js_1 = require("../operation-node/value-node.js");
|
|
5
|
+
const raw_builder_js_1 = require("../raw-builder/raw-builder.js");
|
|
6
6
|
function parseDefaultValueExpression(value) {
|
|
7
|
-
return
|
|
7
|
+
return value instanceof raw_builder_js_1.RawBuilder
|
|
8
8
|
? value.toOperationNode()
|
|
9
9
|
: value_node_js_1.ValueNode.createImmediate(value);
|
|
10
10
|
}
|
|
@@ -7,6 +7,7 @@ const value_list_node_js_1 = require("../operation-node/value-list-node.js");
|
|
|
7
7
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
8
8
|
const value_parser_js_1 = require("./value-parser.js");
|
|
9
9
|
const values_node_js_1 = require("../operation-node/values-node.js");
|
|
10
|
+
const complex_expression_parser_js_1 = require("./complex-expression-parser.js");
|
|
10
11
|
function parseInsertObjectOrList(ctx, args) {
|
|
11
12
|
return parseInsertColumnsAndValues(ctx, Array.isArray(args) ? args : [args]);
|
|
12
13
|
}
|
|
@@ -40,8 +41,8 @@ function parseRowValues(ctx, row, columns) {
|
|
|
40
41
|
rowValues[columnIdx] = value;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
if (rowValues.
|
|
44
|
-
return
|
|
44
|
+
if (rowValues.some(complex_expression_parser_js_1.isComplexExpression)) {
|
|
45
|
+
return value_list_node_js_1.ValueListNode.create(rowValues.map((it) => (0, value_parser_js_1.parseValueExpression)(ctx, it)));
|
|
45
46
|
}
|
|
46
|
-
return
|
|
47
|
+
return primitive_value_list_node_js_1.PrimitiveValueListNode.create(rowValues);
|
|
47
48
|
}
|
|
@@ -2,7 +2,6 @@ import { AliasNode } from '../operation-node/alias-node.js';
|
|
|
2
2
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
3
3
|
import { ReferenceExpressionNode } from '../operation-node/operation-node-utils.js';
|
|
4
4
|
import { ReferenceNode } from '../operation-node/reference-node.js';
|
|
5
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
6
5
|
import { AnyColumn, AnyColumnWithTable, ExtractColumnType, ValueType } from '../util/type-utils.js';
|
|
7
6
|
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
8
7
|
import { SelectQueryBuilder } from '../query-builder/select-query-builder.js';
|
|
@@ -13,8 +12,8 @@ import { SelectType } from '../util/column-type.js';
|
|
|
13
12
|
export declare type ReferenceExpression<DB, TB extends keyof DB> = StringReference<DB, TB> | DynamicReferenceBuilder<any> | ComplexExpression<DB, TB>;
|
|
14
13
|
export declare type ReferenceExpressionOrList<DB, TB extends keyof DB> = ReferenceExpression<DB, TB> | ReadonlyArray<ReferenceExpression<DB, TB>>;
|
|
15
14
|
export declare type StringReference<DB, TB extends keyof DB> = AnyColumn<DB, TB> | AnyColumnWithTable<DB, TB>;
|
|
16
|
-
export declare type ExtractTypeFromReferenceExpression<DB, TB extends keyof DB, RE> = RE extends string ? SelectType<ExtractTypeFromStringReference<DB, TB, RE>> : RE extends RawBuilder<infer O> ? O : RE extends (qb: any) => RawBuilder<infer O> ? O : RE extends SelectQueryBuilder<any, any, infer O> ? ValueType<O> : RE extends (qb: any) => SelectQueryBuilder<any, any, infer O> ? ValueType<O> :
|
|
17
|
-
declare type ExtractTypeFromStringReference<DB, TB extends keyof DB, RE extends string> = RE extends `${infer SC}.${infer T}.${infer C}` ? `${SC}.${T}` extends TB ? C extends keyof DB[`${SC}.${T}`] ? DB[`${SC}.${T}`][C] : never : never : RE extends `${infer T}.${infer C}` ? T extends TB ? C extends keyof DB[T] ? DB[T][C] : never : never : RE extends AnyColumn<DB, TB> ? ExtractColumnType<DB, TB, RE> :
|
|
15
|
+
export declare type ExtractTypeFromReferenceExpression<DB, TB extends keyof DB, RE> = RE extends string ? SelectType<ExtractTypeFromStringReference<DB, TB, RE>> : RE extends RawBuilder<infer O> ? O : RE extends (qb: any) => RawBuilder<infer O> ? O : RE extends SelectQueryBuilder<any, any, infer O> ? ValueType<O> : RE extends (qb: any) => SelectQueryBuilder<any, any, infer O> ? ValueType<O> : unknown;
|
|
16
|
+
declare type ExtractTypeFromStringReference<DB, TB extends keyof DB, RE extends string> = RE extends `${infer SC}.${infer T}.${infer C}` ? `${SC}.${T}` extends TB ? C extends keyof DB[`${SC}.${T}`] ? DB[`${SC}.${T}`][C] : never : never : RE extends `${infer T}.${infer C}` ? T extends TB ? C extends keyof DB[T] ? DB[T][C] : never : never : RE extends AnyColumn<DB, TB> ? ExtractColumnType<DB, TB, RE> : unknown;
|
|
18
17
|
export declare function parseReferenceExpressionOrList(ctx: ParseContext, arg: ReferenceExpressionOrList<any, any>): ReferenceExpressionNode[];
|
|
19
18
|
export declare function parseReferenceExpression(ctx: ParseContext, exp: ReferenceExpression<any, any>): ReferenceExpressionNode;
|
|
20
19
|
export declare function parseStringReference(ref: string): ColumnNode | ReferenceNode;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ValueExpressionNode } from '../operation-node/operation-node-utils.js';
|
|
2
2
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
3
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
4
3
|
import { ParseContext } from './parse-context.js';
|
|
5
4
|
import { SelectQueryNode } from '../operation-node/select-query-node.js';
|
|
6
5
|
import { RawNode } from '../operation-node/raw-node.js';
|
|
7
6
|
import { ComplexExpression } from './complex-expression-parser.js';
|
|
8
7
|
export declare type ValueExpression<DB, TB extends keyof DB, V> = V | ComplexExpression<DB, TB>;
|
|
9
8
|
export declare type ValueExpressionOrList<DB, TB extends keyof DB, V> = ValueExpression<DB, TB, V> | ReadonlyArray<ValueExpression<DB, TB, V>>;
|
|
10
|
-
export declare function parseValueExpressionOrList(ctx: ParseContext, arg: ValueExpressionOrList<any, any,
|
|
11
|
-
export declare function parseValueExpression(ctx: ParseContext, exp: ValueExpression<any, any,
|
|
9
|
+
export declare function parseValueExpressionOrList(ctx: ParseContext, arg: ValueExpressionOrList<any, any, unknown>): ValueExpressionNode;
|
|
10
|
+
export declare function parseValueExpression(ctx: ParseContext, exp: ValueExpression<any, any, unknown>): ValueNode | SelectQueryNode | RawNode;
|
|
@@ -16,16 +16,15 @@ function parseValueExpressionOrList(ctx, arg) {
|
|
|
16
16
|
}
|
|
17
17
|
exports.parseValueExpressionOrList = parseValueExpressionOrList;
|
|
18
18
|
function parseValueExpression(ctx, exp) {
|
|
19
|
-
if ((0,
|
|
20
|
-
return
|
|
19
|
+
if ((0, complex_expression_parser_js_1.isComplexExpression)(exp)) {
|
|
20
|
+
return (0, complex_expression_parser_js_1.parseComplexExpression)(ctx, exp);
|
|
21
21
|
}
|
|
22
|
-
return
|
|
22
|
+
return value_node_js_1.ValueNode.create(exp);
|
|
23
23
|
}
|
|
24
24
|
exports.parseValueExpression = parseValueExpression;
|
|
25
25
|
function parseValueExpressionList(ctx, arg) {
|
|
26
|
-
if (arg.
|
|
27
|
-
|
|
28
|
-
return primitive_value_list_node_js_1.PrimitiveValueListNode.create(arg);
|
|
26
|
+
if (arg.some(complex_expression_parser_js_1.isComplexExpression)) {
|
|
27
|
+
return value_list_node_js_1.ValueListNode.create(arg.map((it) => parseValueExpression(ctx, it)));
|
|
29
28
|
}
|
|
30
|
-
return
|
|
29
|
+
return primitive_value_list_node_js_1.PrimitiveValueListNode.create(arg);
|
|
31
30
|
}
|
|
@@ -3,8 +3,8 @@ import { TableExpression, TableExpressionDatabase, TableExpressionTables } from
|
|
|
3
3
|
import { NoopQueryExecutor } from '../query-executor/noop-query-executor.js';
|
|
4
4
|
import { ParseContext } from '../parser/parse-context.js';
|
|
5
5
|
import { FunctionBuilder } from './function-builder.js';
|
|
6
|
-
import { RawBuilder } from '../index-nodeless.js';
|
|
7
6
|
import { ExtractTypeFromReferenceExpression, StringReference } from '../parser/reference-parser.js';
|
|
7
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
8
8
|
export declare class ExpressionBuilder<DB, TB extends keyof DB> {
|
|
9
9
|
#private;
|
|
10
10
|
constructor(props: ExpressionBuilderProps);
|
|
@@ -8,7 +8,7 @@ const with_schema_plugin_js_1 = require("../plugin/with-schema/with-schema-plugi
|
|
|
8
8
|
const query_id_js_1 = require("../util/query-id.js");
|
|
9
9
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
10
10
|
const function_builder_js_1 = require("./function-builder.js");
|
|
11
|
-
const
|
|
11
|
+
const raw_builder_js_1 = require("../raw-builder/raw-builder.js");
|
|
12
12
|
class ExpressionBuilder {
|
|
13
13
|
#props;
|
|
14
14
|
constructor(props) {
|
|
@@ -69,7 +69,7 @@ class ExpressionBuilder {
|
|
|
69
69
|
* See {@link QueryCreator.raw}.
|
|
70
70
|
*/
|
|
71
71
|
raw(sql, parameters) {
|
|
72
|
-
return new
|
|
72
|
+
return new raw_builder_js_1.RawBuilder({
|
|
73
73
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
74
74
|
executor: this.#props.executor,
|
|
75
75
|
sql,
|
|
@@ -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
|
}
|
|
@@ -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
|
/**
|
|
@@ -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;
|
|
@@ -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.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
|
}
|
|
@@ -144,8 +144,8 @@ export interface MigratorProps {
|
|
|
144
144
|
readonly provider: MigrationProvider;
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
-
* All migration methods ({@link
|
|
148
|
-
* {@link
|
|
147
|
+
* All migration methods ({@link Migrator.migrateTo | migrateTo},
|
|
148
|
+
* {@link Migrator.migrateToLatest | migrateToLatest} etc.) never
|
|
149
149
|
* throw but return this object instead.
|
|
150
150
|
*/
|
|
151
151
|
export interface MigrationResultSet {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
3
2
|
/**
|
|
4
3
|
* This node is basically just a performance optimization over the normal ValueListNode.
|
|
@@ -7,12 +6,12 @@ import { OperationNode } from './operation-node.js';
|
|
|
7
6
|
*/
|
|
8
7
|
export interface PrimitiveValueListNode extends OperationNode {
|
|
9
8
|
readonly kind: 'PrimitiveValueListNode';
|
|
10
|
-
readonly values: ReadonlyArray<
|
|
9
|
+
readonly values: ReadonlyArray<unknown>;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* @internal
|
|
14
13
|
*/
|
|
15
14
|
export declare const PrimitiveValueListNode: Readonly<{
|
|
16
15
|
is(node: OperationNode): node is PrimitiveValueListNode;
|
|
17
|
-
create(values: ReadonlyArray<
|
|
16
|
+
create(values: ReadonlyArray<unknown>): PrimitiveValueListNode;
|
|
18
17
|
}>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
3
2
|
export interface ValueNode extends OperationNode {
|
|
4
3
|
readonly kind: 'ValueNode';
|
|
5
|
-
readonly value:
|
|
4
|
+
readonly value: unknown;
|
|
6
5
|
readonly immediate?: boolean;
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
@@ -10,6 +9,6 @@ export interface ValueNode extends OperationNode {
|
|
|
10
9
|
*/
|
|
11
10
|
export declare const ValueNode: Readonly<{
|
|
12
11
|
is(node: OperationNode): node is ValueNode;
|
|
13
|
-
create(value:
|
|
14
|
-
createImmediate(value:
|
|
12
|
+
create(value: unknown): ValueNode;
|
|
13
|
+
createImmediate(value: unknown): ValueNode;
|
|
15
14
|
}>;
|
|
@@ -7,3 +7,4 @@ export declare type ComplexExpression<DB, TB extends keyof DB> = AnySelectQueryB
|
|
|
7
7
|
export declare type AliasedComplexExpression<DB, TB extends keyof DB> = AnyAliasedQueryBuilder | AliasedQueryBuilderFactory<DB, TB> | AnyAliasedRawBuilder | AliasedRawBuilderFactory<DB, TB>;
|
|
8
8
|
export declare function parseComplexExpression(ctx: ParseContext, exp: ComplexExpression<any, any>): SelectQueryNode | RawNode;
|
|
9
9
|
export declare function parseAliasedComplexExpression(ctx: ParseContext, exp: AliasedComplexExpression<any, any>): AliasNode;
|
|
10
|
+
export declare function isComplexExpression(obj: unknown): obj is ComplexExpression<any, any>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RawNode } from '../operation-node/raw-node.js';
|
|
2
2
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare type DefaultValueExpression = PrimitiveValue | AnyRawBuilder;
|
|
3
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
4
|
+
export declare type DefaultValueExpression = unknown | RawBuilder;
|
|
6
5
|
export declare function parseDefaultValueExpression(value: DefaultValueExpression): ValueNode | RawNode;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="./default-value-parser.d.ts" />
|
|
2
|
-
import { isOperationNodeSource } from '../operation-node/operation-node-source.js';
|
|
3
2
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
3
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
4
4
|
export function parseDefaultValueExpression(value) {
|
|
5
|
-
return
|
|
5
|
+
return value instanceof RawBuilder
|
|
6
6
|
? value.toOperationNode()
|
|
7
7
|
: ValueNode.createImmediate(value);
|
|
8
8
|
}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
3
3
|
import { PrimitiveValueListNode } from '../operation-node/primitive-value-list-node.js';
|
|
4
4
|
import { ValueListNode } from '../operation-node/value-list-node.js';
|
|
5
|
-
import { freeze
|
|
5
|
+
import { freeze } from '../util/object-utils.js';
|
|
6
6
|
import { parseValueExpression } from './value-parser.js';
|
|
7
7
|
import { ValuesNode } from '../operation-node/values-node.js';
|
|
8
|
+
import { isComplexExpression } from './complex-expression-parser.js';
|
|
8
9
|
export function parseInsertObjectOrList(ctx, args) {
|
|
9
10
|
return parseInsertColumnsAndValues(ctx, Array.isArray(args) ? args : [args]);
|
|
10
11
|
}
|
|
@@ -37,8 +38,8 @@ function parseRowValues(ctx, row, columns) {
|
|
|
37
38
|
rowValues[columnIdx] = value;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
if (rowValues.
|
|
41
|
-
return
|
|
41
|
+
if (rowValues.some(isComplexExpression)) {
|
|
42
|
+
return ValueListNode.create(rowValues.map((it) => parseValueExpression(ctx, it)));
|
|
42
43
|
}
|
|
43
|
-
return
|
|
44
|
+
return PrimitiveValueListNode.create(rowValues);
|
|
44
45
|
}
|
|
@@ -2,7 +2,6 @@ import { AliasNode } from '../operation-node/alias-node.js';
|
|
|
2
2
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
3
3
|
import { ReferenceExpressionNode } from '../operation-node/operation-node-utils.js';
|
|
4
4
|
import { ReferenceNode } from '../operation-node/reference-node.js';
|
|
5
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
6
5
|
import { AnyColumn, AnyColumnWithTable, ExtractColumnType, ValueType } from '../util/type-utils.js';
|
|
7
6
|
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
8
7
|
import { SelectQueryBuilder } from '../query-builder/select-query-builder.js';
|
|
@@ -13,8 +12,8 @@ import { SelectType } from '../util/column-type.js';
|
|
|
13
12
|
export declare type ReferenceExpression<DB, TB extends keyof DB> = StringReference<DB, TB> | DynamicReferenceBuilder<any> | ComplexExpression<DB, TB>;
|
|
14
13
|
export declare type ReferenceExpressionOrList<DB, TB extends keyof DB> = ReferenceExpression<DB, TB> | ReadonlyArray<ReferenceExpression<DB, TB>>;
|
|
15
14
|
export declare type StringReference<DB, TB extends keyof DB> = AnyColumn<DB, TB> | AnyColumnWithTable<DB, TB>;
|
|
16
|
-
export declare type ExtractTypeFromReferenceExpression<DB, TB extends keyof DB, RE> = RE extends string ? SelectType<ExtractTypeFromStringReference<DB, TB, RE>> : RE extends RawBuilder<infer O> ? O : RE extends (qb: any) => RawBuilder<infer O> ? O : RE extends SelectQueryBuilder<any, any, infer O> ? ValueType<O> : RE extends (qb: any) => SelectQueryBuilder<any, any, infer O> ? ValueType<O> :
|
|
17
|
-
declare type ExtractTypeFromStringReference<DB, TB extends keyof DB, RE extends string> = RE extends `${infer SC}.${infer T}.${infer C}` ? `${SC}.${T}` extends TB ? C extends keyof DB[`${SC}.${T}`] ? DB[`${SC}.${T}`][C] : never : never : RE extends `${infer T}.${infer C}` ? T extends TB ? C extends keyof DB[T] ? DB[T][C] : never : never : RE extends AnyColumn<DB, TB> ? ExtractColumnType<DB, TB, RE> :
|
|
15
|
+
export declare type ExtractTypeFromReferenceExpression<DB, TB extends keyof DB, RE> = RE extends string ? SelectType<ExtractTypeFromStringReference<DB, TB, RE>> : RE extends RawBuilder<infer O> ? O : RE extends (qb: any) => RawBuilder<infer O> ? O : RE extends SelectQueryBuilder<any, any, infer O> ? ValueType<O> : RE extends (qb: any) => SelectQueryBuilder<any, any, infer O> ? ValueType<O> : unknown;
|
|
16
|
+
declare type ExtractTypeFromStringReference<DB, TB extends keyof DB, RE extends string> = RE extends `${infer SC}.${infer T}.${infer C}` ? `${SC}.${T}` extends TB ? C extends keyof DB[`${SC}.${T}`] ? DB[`${SC}.${T}`][C] : never : never : RE extends `${infer T}.${infer C}` ? T extends TB ? C extends keyof DB[T] ? DB[T][C] : never : never : RE extends AnyColumn<DB, TB> ? ExtractColumnType<DB, TB, RE> : unknown;
|
|
18
17
|
export declare function parseReferenceExpressionOrList(ctx: ParseContext, arg: ReferenceExpressionOrList<any, any>): ReferenceExpressionNode[];
|
|
19
18
|
export declare function parseReferenceExpression(ctx: ParseContext, exp: ReferenceExpression<any, any>): ReferenceExpressionNode;
|
|
20
19
|
export declare function parseStringReference(ref: string): ColumnNode | ReferenceNode;
|
|
@@ -3,7 +3,7 @@ import { AliasNode } from '../operation-node/alias-node.js';
|
|
|
3
3
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
4
4
|
import { ReferenceNode } from '../operation-node/reference-node.js';
|
|
5
5
|
import { TableNode } from '../operation-node/table-node.js';
|
|
6
|
-
import { isReadonlyArray, isString
|
|
6
|
+
import { isReadonlyArray, isString } from '../util/object-utils.js';
|
|
7
7
|
import { parseComplexExpression, } from './complex-expression-parser.js';
|
|
8
8
|
import { isDynamicReferenceBuilder, } from '../dynamic/dynamic-reference-builder.js';
|
|
9
9
|
export function parseReferenceExpressionOrList(ctx, arg) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ValueExpressionNode } from '../operation-node/operation-node-utils.js';
|
|
2
2
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
3
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
4
3
|
import { ParseContext } from './parse-context.js';
|
|
5
4
|
import { SelectQueryNode } from '../operation-node/select-query-node.js';
|
|
6
5
|
import { RawNode } from '../operation-node/raw-node.js';
|
|
7
6
|
import { ComplexExpression } from './complex-expression-parser.js';
|
|
8
7
|
export declare type ValueExpression<DB, TB extends keyof DB, V> = V | ComplexExpression<DB, TB>;
|
|
9
8
|
export declare type ValueExpressionOrList<DB, TB extends keyof DB, V> = ValueExpression<DB, TB, V> | ReadonlyArray<ValueExpression<DB, TB, V>>;
|
|
10
|
-
export declare function parseValueExpressionOrList(ctx: ParseContext, arg: ValueExpressionOrList<any, any,
|
|
11
|
-
export declare function parseValueExpression(ctx: ParseContext, exp: ValueExpression<any, any,
|
|
9
|
+
export declare function parseValueExpressionOrList(ctx: ParseContext, arg: ValueExpressionOrList<any, any, unknown>): ValueExpressionNode;
|
|
10
|
+
export declare function parseValueExpression(ctx: ParseContext, exp: ValueExpression<any, any, unknown>): ValueNode | SelectQueryNode | RawNode;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { PrimitiveValueListNode } from '../operation-node/primitive-value-list-node.js';
|
|
3
3
|
import { ValueListNode } from '../operation-node/value-list-node.js';
|
|
4
4
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
5
|
-
import {
|
|
6
|
-
import { parseComplexExpression, } from './complex-expression-parser.js';
|
|
5
|
+
import { isReadonlyArray } from '../util/object-utils.js';
|
|
6
|
+
import { parseComplexExpression, isComplexExpression, } from './complex-expression-parser.js';
|
|
7
7
|
export function parseValueExpressionOrList(ctx, arg) {
|
|
8
8
|
if (isReadonlyArray(arg)) {
|
|
9
9
|
return parseValueExpressionList(ctx, arg);
|
|
@@ -13,15 +13,14 @@ export function parseValueExpressionOrList(ctx, arg) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export function parseValueExpression(ctx, exp) {
|
|
16
|
-
if (
|
|
17
|
-
return
|
|
16
|
+
if (isComplexExpression(exp)) {
|
|
17
|
+
return parseComplexExpression(ctx, exp);
|
|
18
18
|
}
|
|
19
|
-
return
|
|
19
|
+
return ValueNode.create(exp);
|
|
20
20
|
}
|
|
21
21
|
function parseValueExpressionList(ctx, arg) {
|
|
22
|
-
if (arg.
|
|
23
|
-
|
|
24
|
-
return PrimitiveValueListNode.create(arg);
|
|
22
|
+
if (arg.some(isComplexExpression)) {
|
|
23
|
+
return ValueListNode.create(arg.map((it) => parseValueExpression(ctx, it)));
|
|
25
24
|
}
|
|
26
|
-
return
|
|
25
|
+
return PrimitiveValueListNode.create(arg);
|
|
27
26
|
}
|
|
@@ -3,8 +3,8 @@ import { TableExpression, TableExpressionDatabase, TableExpressionTables } from
|
|
|
3
3
|
import { NoopQueryExecutor } from '../query-executor/noop-query-executor.js';
|
|
4
4
|
import { ParseContext } from '../parser/parse-context.js';
|
|
5
5
|
import { FunctionBuilder } from './function-builder.js';
|
|
6
|
-
import { RawBuilder } from '../index-nodeless.js';
|
|
7
6
|
import { ExtractTypeFromReferenceExpression, StringReference } from '../parser/reference-parser.js';
|
|
7
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
8
8
|
export declare class ExpressionBuilder<DB, TB extends keyof DB> {
|
|
9
9
|
#private;
|
|
10
10
|
constructor(props: ExpressionBuilderProps);
|
|
@@ -6,7 +6,7 @@ import { WithSchemaPlugin } from '../plugin/with-schema/with-schema-plugin.js';
|
|
|
6
6
|
import { createQueryId } from '../util/query-id.js';
|
|
7
7
|
import { freeze } from '../util/object-utils.js';
|
|
8
8
|
import { FunctionBuilder } from './function-builder.js';
|
|
9
|
-
import { RawBuilder } from '../
|
|
9
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
10
10
|
export class ExpressionBuilder {
|
|
11
11
|
#props;
|
|
12
12
|
constructor(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
|
}
|
|
@@ -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
|
*
|
|
@@ -6,10 +6,8 @@ import { ColumnDefinitionNode } from '../operation-node/column-definition-node.j
|
|
|
6
6
|
import { DataTypeNode, } from '../operation-node/data-type-node.js';
|
|
7
7
|
import { DropColumnNode } from '../operation-node/drop-column-node.js';
|
|
8
8
|
import { IdentifierNode } from '../operation-node/identifier-node.js';
|
|
9
|
-
import { isOperationNodeSource, } from '../operation-node/operation-node-source.js';
|
|
10
9
|
import { RenameColumnNode } from '../operation-node/rename-column-node.js';
|
|
11
10
|
import { TableNode } from '../operation-node/table-node.js';
|
|
12
|
-
import { ValueNode } from '../operation-node/value-node.js';
|
|
13
11
|
import { freeze } from '../util/object-utils.js';
|
|
14
12
|
import { preventAwait } from '../util/prevent-await.js';
|
|
15
13
|
import { ColumnDefinitionBuilder, } from './column-definition-builder.js';
|
|
@@ -21,6 +19,7 @@ import { UniqueConstraintNode } from '../operation-node/unique-constraint-node.j
|
|
|
21
19
|
import { CheckConstraintNode } from '../operation-node/check-constraint-node.js';
|
|
22
20
|
import { ForeignKeyConstraintNode } from '../operation-node/foreign-key-constraint-node.js';
|
|
23
21
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
22
|
+
import { parseDefaultValueExpression, } from '../parser/default-value-parser.js';
|
|
24
23
|
/**
|
|
25
24
|
* This builder can be used to create a `alter table` query.
|
|
26
25
|
*/
|
|
@@ -127,9 +126,7 @@ export class AlterColumnBuilder {
|
|
|
127
126
|
...this.#props,
|
|
128
127
|
alterTableNode: AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
129
128
|
alterColumn: AlterColumnNode.cloneWith(this.#props.alterColumnNode, {
|
|
130
|
-
setDefault:
|
|
131
|
-
? value.toOperationNode()
|
|
132
|
-
: ValueNode.createImmediate(value),
|
|
129
|
+
setDefault: parseDefaultValueExpression(value),
|
|
133
130
|
}),
|
|
134
131
|
}),
|
|
135
132
|
});
|
|
@@ -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
|
/**
|
|
@@ -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;
|
|
@@ -26,18 +26,11 @@ export function isDate(obj) {
|
|
|
26
26
|
export function isBigInt(obj) {
|
|
27
27
|
return typeof obj === 'bigint';
|
|
28
28
|
}
|
|
29
|
+
// Don't change the returnd type to `obj is Buffer` to not create a
|
|
30
|
+
// hard dependency to node.
|
|
29
31
|
export function isBuffer(obj) {
|
|
30
32
|
return typeof Buffer !== 'undefined' && Buffer.isBuffer(obj);
|
|
31
33
|
}
|
|
32
|
-
export function isPrimitive(obj) {
|
|
33
|
-
return (isString(obj) ||
|
|
34
|
-
isNumber(obj) ||
|
|
35
|
-
isBoolean(obj) ||
|
|
36
|
-
isNull(obj) ||
|
|
37
|
-
isDate(obj) ||
|
|
38
|
-
isBigInt(obj) ||
|
|
39
|
-
isBuffer(obj));
|
|
40
|
-
}
|
|
41
34
|
export function isFunction(obj) {
|
|
42
35
|
return typeof obj === 'function';
|
|
43
36
|
}
|