drizzle-orm 1.0.0-beta.1-bd417c1 → 1.0.0-beta.1-6b935a0
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/gel-core/columns/common.cjs +8 -0
- package/gel-core/columns/common.cjs.map +1 -1
- package/gel-core/columns/common.d.cts +2 -0
- package/gel-core/columns/common.d.ts +2 -0
- package/gel-core/columns/common.js +8 -0
- package/gel-core/columns/common.js.map +1 -1
- package/gel-core/columns/custom.cjs +12 -0
- package/gel-core/columns/custom.cjs.map +1 -1
- package/gel-core/columns/custom.d.cts +38 -1
- package/gel-core/columns/custom.d.ts +38 -1
- package/gel-core/columns/custom.js +12 -0
- package/gel-core/columns/custom.js.map +1 -1
- package/gel-core/dialect.cjs +21 -2
- package/gel-core/dialect.cjs.map +1 -1
- package/gel-core/dialect.js +22 -3
- package/gel-core/dialect.js.map +1 -1
- package/mysql-core/columns/custom.cjs +28 -0
- package/mysql-core/columns/custom.cjs.map +1 -1
- package/mysql-core/columns/custom.d.cts +38 -1
- package/mysql-core/columns/custom.d.ts +38 -1
- package/mysql-core/columns/custom.js +28 -0
- package/mysql-core/columns/custom.js.map +1 -1
- package/mysql-core/dialect.cjs +3 -0
- package/mysql-core/dialect.cjs.map +1 -1
- package/mysql-core/dialect.js +3 -0
- package/mysql-core/dialect.js.map +1 -1
- package/package.json +37 -37
- package/pg-core/columns/common.cjs +8 -0
- package/pg-core/columns/common.cjs.map +1 -1
- package/pg-core/columns/common.d.cts +1 -0
- package/pg-core/columns/common.d.ts +1 -0
- package/pg-core/columns/common.js +8 -0
- package/pg-core/columns/common.js.map +1 -1
- package/pg-core/columns/custom.cjs +27 -0
- package/pg-core/columns/custom.cjs.map +1 -1
- package/pg-core/columns/custom.d.cts +38 -1
- package/pg-core/columns/custom.d.ts +38 -1
- package/pg-core/columns/custom.js +27 -0
- package/pg-core/columns/custom.js.map +1 -1
- package/pg-core/dialect.cjs +7 -3
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.js +7 -3
- package/pg-core/dialect.js.map +1 -1
- package/relations.cjs +1 -1
- package/relations.cjs.map +1 -1
- package/relations.js +1 -1
- package/relations.js.map +1 -1
- package/singlestore-core/columns/custom.cjs +28 -0
- package/singlestore-core/columns/custom.cjs.map +1 -1
- package/singlestore-core/columns/custom.d.cts +38 -1
- package/singlestore-core/columns/custom.d.ts +38 -1
- package/singlestore-core/columns/custom.js +28 -0
- package/singlestore-core/columns/custom.js.map +1 -1
- package/sql/sql.cjs.map +1 -1
- package/sql/sql.d.cts +1 -0
- package/sql/sql.d.ts +1 -0
- package/sql/sql.js.map +1 -1
- package/sqlite-core/columns/custom.cjs +27 -0
- package/sqlite-core/columns/custom.cjs.map +1 -1
- package/sqlite-core/columns/custom.d.cts +38 -1
- package/sqlite-core/columns/custom.d.ts +38 -1
- package/sqlite-core/columns/custom.js +27 -0
- package/sqlite-core/columns/custom.js.map +1 -1
- package/sqlite-core/dialect.cjs +3 -0
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.js +3 -0
- package/sqlite-core/dialect.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ColumnBuilderBaseConfig } from "../../column-builder.js";
|
|
2
2
|
import type { ColumnBaseConfig } from "../../column.js";
|
|
3
3
|
import { entityKind } from "../../entity.js";
|
|
4
|
-
import type { SQL } from "../../sql/sql.js";
|
|
4
|
+
import type { SQL, SQLGenerator } from "../../sql/sql.js";
|
|
5
5
|
import type { AnySQLiteTable } from "../table.js";
|
|
6
6
|
import { type Equal } from "../../utils.js";
|
|
7
7
|
import { SQLiteColumn, SQLiteColumnBuilder } from "./common.js";
|
|
@@ -34,11 +34,15 @@ export declare class SQLiteCustomColumn<T extends ColumnBaseConfig<'custom', 'SQ
|
|
|
34
34
|
private sqlName;
|
|
35
35
|
private mapTo?;
|
|
36
36
|
private mapFrom?;
|
|
37
|
+
private mapJson?;
|
|
38
|
+
private wrapName?;
|
|
37
39
|
constructor(table: AnySQLiteTable<{
|
|
38
40
|
name: T['tableName'];
|
|
39
41
|
}>, config: SQLiteCustomColumnBuilder<T>['config']);
|
|
40
42
|
getSQLType(): string;
|
|
41
43
|
mapFromDriverValue(value: T['driverParam']): T['data'];
|
|
44
|
+
mapFromJsonValue(value: unknown): T['data'];
|
|
45
|
+
jsonWrapName(name: SQL, sql: SQLGenerator): SQL;
|
|
42
46
|
mapToDriverValue(value: T['data']): T['driverParam'];
|
|
43
47
|
}
|
|
44
48
|
export type CustomTypeValues = {
|
|
@@ -56,6 +60,10 @@ export type CustomTypeValues = {
|
|
|
56
60
|
* Type helper, that represents what type database driver is accepting for specific database data type
|
|
57
61
|
*/
|
|
58
62
|
driverData?: unknown;
|
|
63
|
+
/**
|
|
64
|
+
* Type helper, that represents what type field returns after being aggregated to JSON
|
|
65
|
+
*/
|
|
66
|
+
jsonData?: unknown;
|
|
59
67
|
/**
|
|
60
68
|
* What config type should be used for {@link CustomTypeParams} `dataType` generation
|
|
61
69
|
*/
|
|
@@ -141,6 +149,35 @@ export interface CustomTypeParams<T extends CustomTypeValues> {
|
|
|
141
149
|
* ```
|
|
142
150
|
*/
|
|
143
151
|
fromDriver?: (value: T['driverData']) => T['data'];
|
|
152
|
+
/**
|
|
153
|
+
* Optional mapping function, that is responsible for data mapping from database's JSON format to JS/TS code
|
|
154
|
+
*
|
|
155
|
+
* Used by Relational Queries V2
|
|
156
|
+
* @example
|
|
157
|
+
* For example, when using blob we need to map it's hex representation back to Buffer
|
|
158
|
+
* ```
|
|
159
|
+
* fromJson(value: string): Buffer {
|
|
160
|
+
* return Buffer.from(value, 'hex');
|
|
161
|
+
* },
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @default
|
|
165
|
+
* Defaults to `fromDriver` function
|
|
166
|
+
*/
|
|
167
|
+
fromJson?: (value: T['jsonData']) => T['data'];
|
|
168
|
+
/**
|
|
169
|
+
* Optional name wrapper function, that is responsible for modifying field in selection before it's casted to JSON
|
|
170
|
+
*
|
|
171
|
+
* Used by Relational Queries V2
|
|
172
|
+
* @example
|
|
173
|
+
* For example, when using blob we need to cast field to hex to be able to query it in JSON fields
|
|
174
|
+
* ```
|
|
175
|
+
* jsonWrap(name: SQL, sql: SQLGenerator): SQL {
|
|
176
|
+
* return sql`hex(${name})`
|
|
177
|
+
* },
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
jsonWrap?: (name: SQL, sql: SQLGenerator) => SQL;
|
|
144
181
|
}
|
|
145
182
|
/**
|
|
146
183
|
* Custom sqlite database data type generator
|
|
@@ -21,11 +21,15 @@ class SQLiteCustomColumn extends SQLiteColumn {
|
|
|
21
21
|
sqlName;
|
|
22
22
|
mapTo;
|
|
23
23
|
mapFrom;
|
|
24
|
+
mapJson;
|
|
25
|
+
wrapName;
|
|
24
26
|
constructor(table, config) {
|
|
25
27
|
super(table, config);
|
|
26
28
|
this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
|
|
27
29
|
this.mapTo = config.customTypeParams.toDriver;
|
|
28
30
|
this.mapFrom = config.customTypeParams.fromDriver;
|
|
31
|
+
this.mapJson = config.customTypeParams.fromJson;
|
|
32
|
+
this.wrapName = config.customTypeParams.jsonWrap;
|
|
29
33
|
}
|
|
30
34
|
getSQLType() {
|
|
31
35
|
return this.sqlName;
|
|
@@ -33,6 +37,29 @@ class SQLiteCustomColumn extends SQLiteColumn {
|
|
|
33
37
|
mapFromDriverValue(value) {
|
|
34
38
|
return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
|
|
35
39
|
}
|
|
40
|
+
mapFromJsonValue(value) {
|
|
41
|
+
return typeof this.mapJson === "function" ? this.mapJson(value) : this.mapFromDriverValue(value);
|
|
42
|
+
}
|
|
43
|
+
jsonWrapName(name, sql) {
|
|
44
|
+
if (typeof this.wrapName === "function")
|
|
45
|
+
return this.wrapName(name, sql);
|
|
46
|
+
const rawType = this.getSQLType().toLowerCase();
|
|
47
|
+
const parenPos = rawType.indexOf("(");
|
|
48
|
+
const type = parenPos + 1 ? rawType.slice(0, parenPos) : rawType;
|
|
49
|
+
switch (type) {
|
|
50
|
+
case "numeric":
|
|
51
|
+
case "decimal":
|
|
52
|
+
case "bigint": {
|
|
53
|
+
return sql`cast(${name} as text)`;
|
|
54
|
+
}
|
|
55
|
+
case "blob": {
|
|
56
|
+
return sql`hex(${name})`;
|
|
57
|
+
}
|
|
58
|
+
default: {
|
|
59
|
+
return name;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
36
63
|
mapToDriverValue(value) {
|
|
37
64
|
return typeof this.mapTo === "function" ? this.mapTo(value) : value;
|
|
38
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/sqlite-core/columns/custom.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { SQL } from '~/sql/sql.ts';\nimport type { AnySQLiteTable } from '~/sqlite-core/table.ts';\nimport { type Equal, getColumnNameAndConfig } from '~/utils.ts';\nimport { SQLiteColumn, SQLiteColumnBuilder } from './common.ts';\n\nexport type ConvertCustomConfig<TName extends string, T extends Partial<CustomTypeValues>> =\n\t& {\n\t\tname: TName;\n\t\tdataType: 'custom';\n\t\tcolumnType: 'SQLiteCustomColumn';\n\t\tdata: T['data'];\n\t\tdriverParam: T['driverData'];\n\t\tenumValues: undefined;\n\t}\n\t& (T['notNull'] extends true ? { notNull: true } : {})\n\t& (T['default'] extends true ? { hasDefault: true } : {});\n\nexport interface SQLiteCustomColumnInnerConfig {\n\tcustomTypeValues: CustomTypeValues;\n}\n\nexport class SQLiteCustomColumnBuilder<T extends ColumnBuilderBaseConfig<'custom', 'SQLiteCustomColumn'>>\n\textends SQLiteColumnBuilder<\n\t\tT,\n\t\t{\n\t\t\tfieldConfig: CustomTypeValues['config'];\n\t\t\tcustomTypeParams: CustomTypeParams<any>;\n\t\t},\n\t\t{\n\t\t\tsqliteColumnBuilderBrand: 'SQLiteCustomColumnBuilderBrand';\n\t\t}\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteCustomColumnBuilder';\n\n\tconstructor(\n\t\tname: T['name'],\n\t\tfieldConfig: CustomTypeValues['config'],\n\t\tcustomTypeParams: CustomTypeParams<any>,\n\t) {\n\t\tsuper(name, 'custom', 'SQLiteCustomColumn');\n\t\tthis.config.fieldConfig = fieldConfig;\n\t\tthis.config.customTypeParams = customTypeParams;\n\t}\n\n\t/** @internal */\n\tbuild<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteCustomColumn<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteCustomColumn<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SQLiteCustomColumn<T extends ColumnBaseConfig<'custom', 'SQLiteCustomColumn'>> extends SQLiteColumn<T> {\n\tstatic override readonly [entityKind]: string = 'SQLiteCustomColumn';\n\n\tprivate sqlName: string;\n\tprivate mapTo?: (value: T['data']) => T['driverParam'];\n\tprivate mapFrom?: (value: T['driverParam']) => T['data'];\n\n\tconstructor(\n\t\ttable: AnySQLiteTable<{ name: T['tableName'] }>,\n\t\tconfig: SQLiteCustomColumnBuilder<T>['config'],\n\t) {\n\t\tsuper(table, config);\n\t\tthis.sqlName = config.customTypeParams.dataType(config.fieldConfig);\n\t\tthis.mapTo = config.customTypeParams.toDriver;\n\t\tthis.mapFrom = config.customTypeParams.fromDriver;\n\t}\n\n\tgetSQLType(): string {\n\t\treturn this.sqlName;\n\t}\n\n\toverride mapFromDriverValue(value: T['driverParam']): T['data'] {\n\t\treturn typeof this.mapFrom === 'function' ? this.mapFrom(value) : value as T['data'];\n\t}\n\n\toverride mapToDriverValue(value: T['data']): T['driverParam'] {\n\t\treturn typeof this.mapTo === 'function' ? this.mapTo(value) : value as T['data'];\n\t}\n}\n\nexport type CustomTypeValues = {\n\t/**\n\t * Required type for custom column, that will infer proper type model\n\t *\n\t * Examples:\n\t *\n\t * If you want your column to be `string` type after selecting/or on inserting - use `data: string`. Like `text`, `varchar`\n\t *\n\t * If you want your column to be `number` type after selecting/or on inserting - use `data: number`. Like `integer`\n\t */\n\tdata: unknown;\n\n\t/**\n\t * Type helper, that represents what type database driver is accepting for specific database data type\n\t */\n\tdriverData?: unknown;\n\n\t/**\n\t * What config type should be used for {@link CustomTypeParams} `dataType` generation\n\t */\n\tconfig?: Record<string, any>;\n\n\t/**\n\t * Whether the config argument should be required or not\n\t * @default false\n\t */\n\tconfigRequired?: boolean;\n\n\t/**\n\t * If your custom data type should be notNull by default you can use `notNull: true`\n\t *\n\t * @example\n\t * const customSerial = customType<{ data: number, notNull: true, default: true }>({\n\t * \t dataType() {\n\t * \t return 'serial';\n\t * },\n\t * });\n\t */\n\tnotNull?: boolean;\n\n\t/**\n\t * If your custom data type has default you can use `default: true`\n\t *\n\t * @example\n\t * const customSerial = customType<{ data: number, notNull: true, default: true }>({\n\t * \t dataType() {\n\t * \t return 'serial';\n\t * },\n\t * });\n\t */\n\tdefault?: boolean;\n};\n\nexport interface CustomTypeParams<T extends CustomTypeValues> {\n\t/**\n\t * Database data type string representation, that is used for migrations\n\t * @example\n\t * ```\n\t * `jsonb`, `text`\n\t * ```\n\t *\n\t * If database data type needs additional params you can use them from `config` param\n\t * @example\n\t * ```\n\t * `varchar(256)`, `numeric(2,3)`\n\t * ```\n\t *\n\t * To make `config` be of specific type please use config generic in {@link CustomTypeValues}\n\t *\n\t * @example\n\t * Usage example\n\t * ```\n\t * dataType() {\n\t * return 'boolean';\n\t * },\n\t * ```\n\t * Or\n\t * ```\n\t * dataType(config) {\n\t * \t return typeof config.length !== 'undefined' ? `varchar(${config.length})` : `varchar`;\n\t * \t }\n\t * ```\n\t */\n\tdataType: (config: T['config'] | (Equal<T['configRequired'], true> extends true ? never : undefined)) => string;\n\n\t/**\n\t * Optional mapping function, between user input and driver\n\t * @example\n\t * For example, when using jsonb we need to map JS/TS object to string before writing to database\n\t * ```\n\t * toDriver(value: TData): string {\n\t * \t return JSON.stringify(value);\n\t * }\n\t * ```\n\t */\n\ttoDriver?: (value: T['data']) => T['driverData'] | SQL;\n\n\t/**\n\t * Optional mapping function, that is responsible for data mapping from database to JS/TS code\n\t * @example\n\t * For example, when using timestamp we need to map string Date representation to JS Date\n\t * ```\n\t * fromDriver(value: string): Date {\n\t * \treturn new Date(value);\n\t * },\n\t * ```\n\t */\n\tfromDriver?: (value: T['driverData']) => T['data'];\n}\n\n/**\n * Custom sqlite database data type generator\n */\nexport function customType<T extends CustomTypeValues = CustomTypeValues>(\n\tcustomTypeParams: CustomTypeParams<T>,\n): Equal<T['configRequired'], true> extends true ? {\n\t\t<TConfig extends Record<string, any> & T['config']>(\n\t\t\tfieldConfig: TConfig,\n\t\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<'', T>>;\n\t\t<TName extends string>(\n\t\t\tdbName: TName,\n\t\t\tfieldConfig: T['config'],\n\t\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<TName, T>>;\n\t}\n\t: {\n\t\t(): SQLiteCustomColumnBuilder<ConvertCustomConfig<'', T>>;\n\t\t<TConfig extends Record<string, any> & T['config']>(\n\t\t\tfieldConfig?: TConfig,\n\t\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<'', T>>;\n\t\t<TName extends string>(\n\t\t\tdbName: TName,\n\t\t\tfieldConfig?: T['config'],\n\t\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<TName, T>>;\n\t}\n{\n\treturn <TName extends string>(\n\t\ta?: TName | T['config'],\n\t\tb?: T['config'],\n\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<TName, T>> => {\n\t\tconst { name, config } = getColumnNameAndConfig<T['config']>(a, b);\n\t\treturn new SQLiteCustomColumnBuilder(\n\t\t\tname as ConvertCustomConfig<TName, T>['name'],\n\t\t\tconfig,\n\t\t\tcustomTypeParams,\n\t\t);\n\t};\n}\n"],"mappings":"AAEA,SAAS,kBAAkB;AAG3B,SAAqB,8BAA8B;AACnD,SAAS,cAAc,2BAA2B;AAkB3C,MAAM,kCACJ,oBAUT;AAAA,EACC,QAA0B,UAAU,IAAY;AAAA,EAEhD,YACC,MACA,aACA,kBACC;AACD,UAAM,MAAM,UAAU,oBAAoB;AAC1C,SAAK,OAAO,cAAc;AAC1B,SAAK,OAAO,mBAAmB;AAAA,EAChC;AAAA;AAAA,EAGA,MACC,OACsD;AACtD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,2BAAuF,aAAgB;AAAA,EACnH,QAA0B,UAAU,IAAY;AAAA,EAExC;AAAA,EACA;AAAA,EACA;AAAA,EAER,YACC,OACA,QACC;AACD,UAAM,OAAO,MAAM;AACnB,SAAK,UAAU,OAAO,iBAAiB,SAAS,OAAO,WAAW;AAClE,SAAK,QAAQ,OAAO,iBAAiB;AACrC,SAAK,UAAU,OAAO,iBAAiB;AAAA,EACxC;AAAA,EAEA,aAAqB;AACpB,WAAO,KAAK;AAAA,EACb;AAAA,EAES,mBAAmB,OAAoC;AAC/D,WAAO,OAAO,KAAK,YAAY,aAAa,KAAK,QAAQ,KAAK,IAAI;AAAA,EACnE;AAAA,EAES,iBAAiB,OAAoC;AAC7D,WAAO,OAAO,KAAK,UAAU,aAAa,KAAK,MAAM,KAAK,IAAI;AAAA,EAC/D;AACD;AAmHO,SAAS,WACf,kBAoBD;AACC,SAAO,CACN,GACA,MAC8D;AAC9D,UAAM,EAAE,MAAM,OAAO,IAAI,uBAAoC,GAAG,CAAC;AACjE,WAAO,IAAI;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/sqlite-core/columns/custom.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { SQL, SQLGenerator } from '~/sql/sql.ts';\nimport type { AnySQLiteTable } from '~/sqlite-core/table.ts';\nimport { type Equal, getColumnNameAndConfig } from '~/utils.ts';\nimport { SQLiteColumn, SQLiteColumnBuilder } from './common.ts';\n\nexport type ConvertCustomConfig<TName extends string, T extends Partial<CustomTypeValues>> =\n\t& {\n\t\tname: TName;\n\t\tdataType: 'custom';\n\t\tcolumnType: 'SQLiteCustomColumn';\n\t\tdata: T['data'];\n\t\tdriverParam: T['driverData'];\n\t\tenumValues: undefined;\n\t}\n\t& (T['notNull'] extends true ? { notNull: true } : {})\n\t& (T['default'] extends true ? { hasDefault: true } : {});\n\nexport interface SQLiteCustomColumnInnerConfig {\n\tcustomTypeValues: CustomTypeValues;\n}\n\nexport class SQLiteCustomColumnBuilder<T extends ColumnBuilderBaseConfig<'custom', 'SQLiteCustomColumn'>>\n\textends SQLiteColumnBuilder<\n\t\tT,\n\t\t{\n\t\t\tfieldConfig: CustomTypeValues['config'];\n\t\t\tcustomTypeParams: CustomTypeParams<any>;\n\t\t},\n\t\t{\n\t\t\tsqliteColumnBuilderBrand: 'SQLiteCustomColumnBuilderBrand';\n\t\t}\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteCustomColumnBuilder';\n\n\tconstructor(\n\t\tname: T['name'],\n\t\tfieldConfig: CustomTypeValues['config'],\n\t\tcustomTypeParams: CustomTypeParams<any>,\n\t) {\n\t\tsuper(name, 'custom', 'SQLiteCustomColumn');\n\t\tthis.config.fieldConfig = fieldConfig;\n\t\tthis.config.customTypeParams = customTypeParams;\n\t}\n\n\t/** @internal */\n\tbuild<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteCustomColumn<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteCustomColumn<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SQLiteCustomColumn<T extends ColumnBaseConfig<'custom', 'SQLiteCustomColumn'>> extends SQLiteColumn<T> {\n\tstatic override readonly [entityKind]: string = 'SQLiteCustomColumn';\n\n\tprivate sqlName: string;\n\tprivate mapTo?: (value: T['data']) => T['driverParam'];\n\tprivate mapFrom?: (value: T['driverParam']) => T['data'];\n\tprivate mapJson?: (value: unknown) => T['data'];\n\tprivate wrapName?: (name: SQL, sql: SQLGenerator) => SQL;\n\n\tconstructor(\n\t\ttable: AnySQLiteTable<{ name: T['tableName'] }>,\n\t\tconfig: SQLiteCustomColumnBuilder<T>['config'],\n\t) {\n\t\tsuper(table, config);\n\t\tthis.sqlName = config.customTypeParams.dataType(config.fieldConfig);\n\t\tthis.mapTo = config.customTypeParams.toDriver;\n\t\tthis.mapFrom = config.customTypeParams.fromDriver;\n\t\tthis.mapJson = config.customTypeParams.fromJson;\n\t\tthis.wrapName = config.customTypeParams.jsonWrap;\n\t}\n\n\tgetSQLType(): string {\n\t\treturn this.sqlName;\n\t}\n\n\toverride mapFromDriverValue(value: T['driverParam']): T['data'] {\n\t\treturn typeof this.mapFrom === 'function' ? this.mapFrom(value) : value as T['data'];\n\t}\n\n\tmapFromJsonValue(value: unknown): T['data'] {\n\t\treturn typeof this.mapJson === 'function' ? this.mapJson(value) : this.mapFromDriverValue(value) as T['data'];\n\t}\n\n\tjsonWrapName(name: SQL, sql: SQLGenerator): SQL {\n\t\tif (typeof this.wrapName === 'function') return this.wrapName(name, sql);\n\n\t\tconst rawType = this.getSQLType().toLowerCase();\n\t\tconst parenPos = rawType.indexOf('(');\n\t\tconst type = (parenPos + 1) ? rawType.slice(0, parenPos) : rawType;\n\n\t\tswitch (type) {\n\t\t\tcase 'numeric':\n\t\t\tcase 'decimal':\n\t\t\tcase 'bigint': {\n\t\t\t\treturn sql`cast(${name} as text)`;\n\t\t\t}\n\t\t\tcase 'blob': {\n\t\t\t\treturn sql`hex(${name})`;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn name;\n\t\t\t}\n\t\t}\n\t}\n\n\toverride mapToDriverValue(value: T['data']): T['driverParam'] {\n\t\treturn typeof this.mapTo === 'function' ? this.mapTo(value) : value as T['data'];\n\t}\n}\n\nexport type CustomTypeValues = {\n\t/**\n\t * Required type for custom column, that will infer proper type model\n\t *\n\t * Examples:\n\t *\n\t * If you want your column to be `string` type after selecting/or on inserting - use `data: string`. Like `text`, `varchar`\n\t *\n\t * If you want your column to be `number` type after selecting/or on inserting - use `data: number`. Like `integer`\n\t */\n\tdata: unknown;\n\n\t/**\n\t * Type helper, that represents what type database driver is accepting for specific database data type\n\t */\n\tdriverData?: unknown;\n\n\t/**\n\t * Type helper, that represents what type field returns after being aggregated to JSON\n\t */\n\tjsonData?: unknown;\n\n\t/**\n\t * What config type should be used for {@link CustomTypeParams} `dataType` generation\n\t */\n\tconfig?: Record<string, any>;\n\n\t/**\n\t * Whether the config argument should be required or not\n\t * @default false\n\t */\n\tconfigRequired?: boolean;\n\n\t/**\n\t * If your custom data type should be notNull by default you can use `notNull: true`\n\t *\n\t * @example\n\t * const customSerial = customType<{ data: number, notNull: true, default: true }>({\n\t * \t dataType() {\n\t * \t return 'serial';\n\t * },\n\t * });\n\t */\n\tnotNull?: boolean;\n\n\t/**\n\t * If your custom data type has default you can use `default: true`\n\t *\n\t * @example\n\t * const customSerial = customType<{ data: number, notNull: true, default: true }>({\n\t * \t dataType() {\n\t * \t return 'serial';\n\t * },\n\t * });\n\t */\n\tdefault?: boolean;\n};\n\nexport interface CustomTypeParams<T extends CustomTypeValues> {\n\t/**\n\t * Database data type string representation, that is used for migrations\n\t * @example\n\t * ```\n\t * `jsonb`, `text`\n\t * ```\n\t *\n\t * If database data type needs additional params you can use them from `config` param\n\t * @example\n\t * ```\n\t * `varchar(256)`, `numeric(2,3)`\n\t * ```\n\t *\n\t * To make `config` be of specific type please use config generic in {@link CustomTypeValues}\n\t *\n\t * @example\n\t * Usage example\n\t * ```\n\t * dataType() {\n\t * return 'boolean';\n\t * },\n\t * ```\n\t * Or\n\t * ```\n\t * dataType(config) {\n\t * \t return typeof config.length !== 'undefined' ? `varchar(${config.length})` : `varchar`;\n\t * \t }\n\t * ```\n\t */\n\tdataType: (config: T['config'] | (Equal<T['configRequired'], true> extends true ? never : undefined)) => string;\n\n\t/**\n\t * Optional mapping function, between user input and driver\n\t * @example\n\t * For example, when using jsonb we need to map JS/TS object to string before writing to database\n\t * ```\n\t * toDriver(value: TData): string {\n\t * \t return JSON.stringify(value);\n\t * }\n\t * ```\n\t */\n\ttoDriver?: (value: T['data']) => T['driverData'] | SQL;\n\n\t/**\n\t * Optional mapping function, that is responsible for data mapping from database to JS/TS code\n\t * @example\n\t * For example, when using timestamp we need to map string Date representation to JS Date\n\t * ```\n\t * fromDriver(value: string): Date {\n\t * \treturn new Date(value);\n\t * },\n\t * ```\n\t */\n\tfromDriver?: (value: T['driverData']) => T['data'];\n\n\t/**\n\t * Optional mapping function, that is responsible for data mapping from database's JSON format to JS/TS code\n\t *\n\t * Used by Relational Queries V2\n\t * @example\n\t * For example, when using blob we need to map it's hex representation back to Buffer\n\t * ```\n\t * fromJson(value: string): Buffer {\n\t * \treturn Buffer.from(value, 'hex');\n\t * },\n\t * ```\n\t *\n\t * @default\n\t * Defaults to `fromDriver` function\n\t */\n\tfromJson?: (value: T['jsonData']) => T['data'];\n\n\t/**\n\t * Optional name wrapper function, that is responsible for modifying field in selection before it's casted to JSON\n\t *\n\t * Used by Relational Queries V2\n\t * @example\n\t * For example, when using blob we need to cast field to hex to be able to query it in JSON fields\n\t * ```\n\t * jsonWrap(name: SQL, sql: SQLGenerator): SQL {\n\t * \treturn sql`hex(${name})`\n\t * },\n\t * ```\n\t */\n\tjsonWrap?: (name: SQL, sql: SQLGenerator) => SQL;\n}\n\n/**\n * Custom sqlite database data type generator\n */\nexport function customType<T extends CustomTypeValues = CustomTypeValues>(\n\tcustomTypeParams: CustomTypeParams<T>,\n): Equal<T['configRequired'], true> extends true ? {\n\t\t<TConfig extends Record<string, any> & T['config']>(\n\t\t\tfieldConfig: TConfig,\n\t\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<'', T>>;\n\t\t<TName extends string>(\n\t\t\tdbName: TName,\n\t\t\tfieldConfig: T['config'],\n\t\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<TName, T>>;\n\t}\n\t: {\n\t\t(): SQLiteCustomColumnBuilder<ConvertCustomConfig<'', T>>;\n\t\t<TConfig extends Record<string, any> & T['config']>(\n\t\t\tfieldConfig?: TConfig,\n\t\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<'', T>>;\n\t\t<TName extends string>(\n\t\t\tdbName: TName,\n\t\t\tfieldConfig?: T['config'],\n\t\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<TName, T>>;\n\t}\n{\n\treturn <TName extends string>(\n\t\ta?: TName | T['config'],\n\t\tb?: T['config'],\n\t): SQLiteCustomColumnBuilder<ConvertCustomConfig<TName, T>> => {\n\t\tconst { name, config } = getColumnNameAndConfig<T['config']>(a, b);\n\t\treturn new SQLiteCustomColumnBuilder(\n\t\t\tname as ConvertCustomConfig<TName, T>['name'],\n\t\t\tconfig,\n\t\t\tcustomTypeParams,\n\t\t);\n\t};\n}\n"],"mappings":"AAEA,SAAS,kBAAkB;AAG3B,SAAqB,8BAA8B;AACnD,SAAS,cAAc,2BAA2B;AAkB3C,MAAM,kCACJ,oBAUT;AAAA,EACC,QAA0B,UAAU,IAAY;AAAA,EAEhD,YACC,MACA,aACA,kBACC;AACD,UAAM,MAAM,UAAU,oBAAoB;AAC1C,SAAK,OAAO,cAAc;AAC1B,SAAK,OAAO,mBAAmB;AAAA,EAChC;AAAA;AAAA,EAGA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AO,KAAK,UAAU,aAAa,KAAK,MAAM,KAAK,IAAI;AAAA,EAC/D;AACD;AAuJO,SAAS,WACf,kBAoBD;AACC,SAAO,CACN,GACA,MAC8D;AAC9D,UAAM,EAAE,MAAM,OAAO,IAAI,uBAAoC,GAAG,CAAC;AACjE,WAAO,IAAI;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
package/sqlite-core/dialect.cjs
CHANGED
|
@@ -620,6 +620,9 @@ class SQLiteDialect {
|
|
|
620
620
|
case "SQLiteNumericBigInt": {
|
|
621
621
|
return import_sql2.sql`cast(${name} as text) as ${import_sql2.sql.identifier(key)}`;
|
|
622
622
|
}
|
|
623
|
+
case "SQLiteCustomColumn": {
|
|
624
|
+
return import_sql2.sql`${column.jsonWrapName(name, import_sql2.sql)} as ${import_sql2.sql.identifier(key)}`;
|
|
625
|
+
}
|
|
623
626
|
default: {
|
|
624
627
|
return import_sql2.sql`${name} as ${import_sql2.sql.identifier(key)}`;
|
|
625
628
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sqlite-core/dialect.ts"],"sourcesContent":["import * as V1 from '~/_relations.ts';\nimport { aliasedTable, aliasedTableColumn, mapColumnsInAliasedSQLToAlias, mapColumnsInSQLToAlias } from '~/alias.ts';\nimport { CasingCache } from '~/casing.ts';\nimport type { AnyColumn } from '~/column.ts';\nimport { Column } from '~/column.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { DrizzleError } from '~/errors.ts';\nimport type { MigrationConfig, MigrationMeta } from '~/migrator.ts';\nimport {\n\t// AggregatedField,\n\ttype AnyRelations,\n\ttype BuildRelationalQueryResult,\n\ttype ColumnWithTSName,\n\ttype DBQueryConfig,\n\tgetTableAsAliasSQL,\n\tOne,\n\ttype Relation,\n\trelationExtrasToSQL,\n\trelationsFilterToSQL,\n\trelationsOrderToSQL,\n\trelationToSQL,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n\ttype WithContainer,\n} from '~/relations.ts';\nimport type { Name, Placeholder, SQLWrapper, View } from '~/sql/index.ts';\nimport { and, eq, isSQLWrapper } from '~/sql/index.ts';\nimport { Param, type QueryWithTypings, SQL, sql, type SQLChunk } from '~/sql/sql.ts';\nimport { SQLiteColumn } from '~/sqlite-core/columns/index.ts';\nimport type {\n\tAnySQLiteSelectQueryBuilder,\n\tSQLiteDeleteConfig,\n\tSQLiteInsertConfig,\n\tSQLiteUpdateConfig,\n} from '~/sqlite-core/query-builders/index.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { Columns, getTableName, getTableUniqueName, Table } from '~/table.ts';\nimport { type Casing, orderSelectedFields, type UpdateSet } from '~/utils.ts';\nimport { ViewBaseConfig } from '~/view-common.ts';\nimport type {\n\tSelectedFieldsOrdered,\n\tSQLiteSelectConfig,\n\tSQLiteSelectJoinConfig,\n} from './query-builders/select.types.ts';\nimport type { SQLiteSession } from './session.ts';\nimport { SQLiteViewBase } from './view-base.ts';\nimport type { SQLiteView } from './view.ts';\n\nexport interface SQLiteDialectConfig {\n\tcasing?: Casing;\n}\n\nexport abstract class SQLiteDialect {\n\tstatic readonly [entityKind]: string = 'SQLiteDialect';\n\n\t/** @internal */\n\treadonly casing: CasingCache;\n\n\tconstructor(config?: SQLiteDialectConfig) {\n\t\tthis.casing = new CasingCache(config?.casing);\n\t}\n\n\tescapeName(name: string): string {\n\t\treturn `\"${name}\"`;\n\t}\n\n\tescapeParam(_num: number): string {\n\t\treturn '?';\n\t}\n\n\tescapeString(str: string): string {\n\t\treturn `'${str.replace(/'/g, \"''\")}'`;\n\t}\n\n\tprivate buildWithCTE(queries: Subquery[] | undefined): SQL | undefined {\n\t\tif (!queries?.length) return undefined;\n\n\t\tconst withSqlChunks = [sql`with `];\n\t\tfor (const [i, w] of queries.entries()) {\n\t\t\twithSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);\n\t\t\tif (i < queries.length - 1) {\n\t\t\t\twithSqlChunks.push(sql`, `);\n\t\t\t}\n\t\t}\n\t\twithSqlChunks.push(sql` `);\n\t\treturn sql.join(withSqlChunks);\n\t}\n\n\tbuildDeleteQuery({ table, where, returning, withList, limit, orderBy }: SQLiteDeleteConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}delete from ${table}${whereSql}${returningSql}${orderBySql}${limitSql}`;\n\t}\n\n\tbuildUpdateSet(table: SQLiteTable, set: UpdateSet): SQL {\n\t\tconst tableColumns = table[Table.Symbol.Columns];\n\n\t\tconst columnNames = Object.keys(tableColumns).filter((colName) =>\n\t\t\tset[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined\n\t\t);\n\n\t\tconst setSize = columnNames.length;\n\t\treturn sql.join(columnNames.flatMap((colName, i) => {\n\t\t\tconst col = tableColumns[colName]!;\n\n\t\t\tconst value = set[colName] ?? sql.param(col.onUpdateFn!(), col);\n\t\t\tconst res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;\n\n\t\t\tif (i < setSize - 1) {\n\t\t\t\treturn [res, sql.raw(', ')];\n\t\t\t}\n\t\t\treturn [res];\n\t\t}));\n\t}\n\n\tbuildUpdateQuery({ table, set, where, returning, withList, joins, from, limit, orderBy }: SQLiteUpdateConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst setSql = this.buildUpdateSet(table, set);\n\n\t\tconst fromSql = from && sql.join([sql.raw(' from '), this.buildFromTable(from)]);\n\n\t\tconst joinsSql = this.buildJoins(joins);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}update ${table} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;\n\t}\n\n\t/**\n\t * Builds selection SQL with provided fields/expressions\n\t *\n\t * Examples:\n\t *\n\t * `select <selection> from`\n\t *\n\t * `insert ... returning <selection>`\n\t *\n\t * If `isSingleTable` is true, then columns won't be prefixed with table name\n\t */\n\tprivate buildSelection(\n\t\tfields: SelectedFieldsOrdered,\n\t\t{ isSingleTable = false }: { isSingleTable?: boolean } = {},\n\t): SQL {\n\t\tconst columnsLen = fields.length;\n\n\t\tconst chunks = fields\n\t\t\t.flatMap(({ field }, i) => {\n\t\t\t\tconst chunk: SQLChunk[] = [];\n\n\t\t\t\tif (is(field, SQL.Aliased) && field.isSelectionField) {\n\t\t\t\t\tchunk.push(sql.identifier(field.fieldAlias));\n\t\t\t\t} else if (is(field, SQL.Aliased) || is(field, SQL)) {\n\t\t\t\t\tconst query = is(field, SQL.Aliased) ? field.sql : field;\n\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(\n\t\t\t\t\t\t\tnew SQL(\n\t\t\t\t\t\t\t\tquery.queryChunks.map((c) => {\n\t\t\t\t\t\t\t\t\tif (is(c, Column)) {\n\t\t\t\t\t\t\t\t\t\treturn sql.identifier(this.casing.getColumnCasing(c));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn c;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(query);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (is(field, SQL.Aliased)) {\n\t\t\t\t\t\tchunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);\n\t\t\t\t\t}\n\t\t\t\t} else if (is(field, Column)) {\n\t\t\t\t\tconst tableName = field.table[Table.Symbol.Name];\n\t\t\t\t\tif (field.columnType === 'SQLiteNumericBigInt') {\n\t\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\t\tchunk.push(sql`cast(${sql.identifier(this.casing.getColumnCasing(field))} as text)`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchunk.push(\n\t\t\t\t\t\t\t\tsql`cast(${sql.identifier(tableName)}.${sql.identifier(this.casing.getColumnCasing(field))} as text)`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\t\tchunk.push(sql.identifier(this.casing.getColumnCasing(field)));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchunk.push(sql`${sql.identifier(tableName)}.${sql.identifier(this.casing.getColumnCasing(field))}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (i < columnsLen - 1) {\n\t\t\t\t\tchunk.push(sql`, `);\n\t\t\t\t}\n\n\t\t\t\treturn chunk;\n\t\t\t});\n\n\t\treturn sql.join(chunks);\n\t}\n\n\tprivate buildJoins(joins: SQLiteSelectJoinConfig[] | undefined): SQL | undefined {\n\t\tif (!joins || joins.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst joinsArray: SQL[] = [];\n\n\t\tif (joins) {\n\t\t\tfor (const [index, joinMeta] of joins.entries()) {\n\t\t\t\tif (index === 0) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t\tconst table = joinMeta.table;\n\n\t\t\t\tif (is(table, SQLiteTable)) {\n\t\t\t\t\tconst tableName = table[SQLiteTable.Symbol.Name];\n\t\t\t\t\tconst tableSchema = table[SQLiteTable.Symbol.Schema];\n\t\t\t\t\tconst origTableName = table[SQLiteTable.Symbol.OriginalName];\n\t\t\t\t\tconst alias = tableName === origTableName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : undefined}${\n\t\t\t\t\t\t\tsql.identifier(origTableName)\n\t\t\t\t\t\t}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join ${table} on ${joinMeta.on}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (index < joins.length - 1) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn sql.join(joinsArray);\n\t}\n\n\tprivate buildLimit(limit: number | Placeholder | undefined): SQL | undefined {\n\t\treturn typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\t}\n\n\tprivate buildOrderBy(orderBy: (SQLiteColumn | SQL | SQL.Aliased)[] | undefined): SQL | undefined {\n\t\tconst orderByList: (SQLiteColumn | SQL | SQL.Aliased)[] = [];\n\n\t\tif (orderBy) {\n\t\t\tfor (const [index, orderByValue] of orderBy.entries()) {\n\t\t\t\torderByList.push(orderByValue);\n\n\t\t\t\tif (index < orderBy.length - 1) {\n\t\t\t\t\torderByList.push(sql`, `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : undefined;\n\t}\n\n\tprivate buildFromTable(\n\t\ttable: SQL | Subquery | SQLiteViewBase | SQLiteTable | undefined,\n\t): SQL | Subquery | SQLiteViewBase | SQLiteTable | undefined {\n\t\tif (is(table, Table) && table[Table.Symbol.IsAlias]) {\n\t\t\treturn sql`${sql`${sql.identifier(table[Table.Symbol.Schema] ?? '')}.`.if(table[Table.Symbol.Schema])}${\n\t\t\t\tsql.identifier(table[Table.Symbol.OriginalName])\n\t\t\t} ${sql.identifier(table[Table.Symbol.Name])}`;\n\t\t}\n\n\t\treturn table;\n\t}\n\n\tbuildSelectQuery(\n\t\t{\n\t\t\twithList,\n\t\t\tfields,\n\t\t\tfieldsFlat,\n\t\t\twhere,\n\t\t\thaving,\n\t\t\ttable,\n\t\t\tjoins,\n\t\t\torderBy,\n\t\t\tgroupBy,\n\t\t\tlimit,\n\t\t\toffset,\n\t\t\tdistinct,\n\t\t\tsetOperators,\n\t\t}: SQLiteSelectConfig,\n\t): SQL {\n\t\tconst fieldsList = fieldsFlat ?? orderSelectedFields<SQLiteColumn>(fields);\n\t\tfor (const f of fieldsList) {\n\t\t\tif (\n\t\t\t\tis(f.field, Column)\n\t\t\t\t&& getTableName(f.field.table)\n\t\t\t\t\t!== (is(table, Subquery)\n\t\t\t\t\t\t? table._.alias\n\t\t\t\t\t\t: is(table, SQLiteViewBase)\n\t\t\t\t\t\t? table[ViewBaseConfig].name\n\t\t\t\t\t\t: is(table, SQL)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: getTableName(table))\n\t\t\t\t&& !((table) =>\n\t\t\t\t\tjoins?.some(({ alias }) =>\n\t\t\t\t\t\talias === (table[Table.Symbol.IsAlias] ? getTableName(table) : table[Table.Symbol.BaseName])\n\t\t\t\t\t))(f.field.table)\n\t\t\t) {\n\t\t\t\tconst tableName = getTableName(f.field.table);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Your \"${\n\t\t\t\t\t\tf.path.join('->')\n\t\t\t\t\t}\" field references a column \"${tableName}\".\"${f.field.name}\", but the table \"${tableName}\" is not part of the query! Did you forget to join it?`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst isSingleTable = !joins || joins.length === 0;\n\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst distinctSql = distinct ? sql` distinct` : undefined;\n\n\t\tconst selection = this.buildSelection(fieldsList, { isSingleTable });\n\n\t\tconst tableSql = this.buildFromTable(table);\n\n\t\tconst joinsSql = this.buildJoins(joins);\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst havingSql = having ? sql` having ${having}` : undefined;\n\n\t\tconst groupByList: (SQL | AnyColumn | SQL.Aliased)[] = [];\n\t\tif (groupBy) {\n\t\t\tfor (const [index, groupByValue] of groupBy.entries()) {\n\t\t\t\tgroupByList.push(groupByValue);\n\n\t\t\t\tif (index < groupBy.length - 1) {\n\t\t\t\t\tgroupByList.push(sql`, `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst groupBySql = groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\tconst finalQuery =\n\t\t\tsql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}`;\n\n\t\tif (setOperators.length > 0) {\n\t\t\treturn this.buildSetOperations(finalQuery, setOperators);\n\t\t}\n\n\t\treturn finalQuery;\n\t}\n\n\tbuildSetOperations(leftSelect: SQL, setOperators: SQLiteSelectConfig['setOperators']): SQL {\n\t\tconst [setOperator, ...rest] = setOperators;\n\n\t\tif (!setOperator) {\n\t\t\tthrow new Error('Cannot pass undefined values to any set operator');\n\t\t}\n\n\t\tif (rest.length === 0) {\n\t\t\treturn this.buildSetOperationQuery({ leftSelect, setOperator });\n\t\t}\n\n\t\t// Some recursive magic here\n\t\treturn this.buildSetOperations(\n\t\t\tthis.buildSetOperationQuery({ leftSelect, setOperator }),\n\t\t\trest,\n\t\t);\n\t}\n\n\tbuildSetOperationQuery({\n\t\tleftSelect,\n\t\tsetOperator: { type, isAll, rightSelect, limit, orderBy, offset },\n\t}: { leftSelect: SQL; setOperator: SQLiteSelectConfig['setOperators'][number] }): SQL {\n\t\t// SQLite doesn't support parenthesis in set operations\n\t\tconst leftChunk = sql`${leftSelect.getSQL()} `;\n\t\tconst rightChunk = sql`${rightSelect.getSQL()}`;\n\n\t\tlet orderBySql;\n\t\tif (orderBy && orderBy.length > 0) {\n\t\t\tconst orderByValues: (SQL<unknown> | Name)[] = [];\n\n\t\t\t// The next bit is necessary because the sql operator replaces ${table.column} with `table`.`column`\n\t\t\t// which is invalid Sql syntax, Table from one of the SELECTs cannot be used in global ORDER clause\n\t\t\tfor (const singleOrderBy of orderBy) {\n\t\t\t\tif (is(singleOrderBy, SQLiteColumn)) {\n\t\t\t\t\torderByValues.push(sql.identifier(singleOrderBy.name));\n\t\t\t\t} else if (is(singleOrderBy, SQL)) {\n\t\t\t\t\tfor (let i = 0; i < singleOrderBy.queryChunks.length; i++) {\n\t\t\t\t\t\tconst chunk = singleOrderBy.queryChunks[i];\n\n\t\t\t\t\t\tif (is(chunk, SQLiteColumn)) {\n\t\t\t\t\t\t\tsingleOrderBy.queryChunks[i] = sql.identifier(this.casing.getColumnCasing(chunk));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\torderByValues.push(sql`${singleOrderBy}`);\n\t\t\t\t} else {\n\t\t\t\t\torderByValues.push(sql`${singleOrderBy}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\torderBySql = sql` order by ${sql.join(orderByValues, sql`, `)}`;\n\t\t}\n\n\t\tconst limitSql = typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\n\t\tconst operatorChunk = sql.raw(`${type} ${isAll ? 'all ' : ''}`);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\treturn sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;\n\t}\n\n\tbuildInsertQuery(\n\t\t{ table, values: valuesOrSelect, onConflict, returning, withList, select }: SQLiteInsertConfig,\n\t): SQL {\n\t\t// const isSingleValue = values.length === 1;\n\t\tconst valuesSqlList: ((SQLChunk | SQL)[] | SQL)[] = [];\n\t\tconst columns: Record<string, SQLiteColumn> = table[Table.Symbol.Columns];\n\n\t\tconst colEntries: [string, SQLiteColumn][] = Object.entries(columns).filter(([_, col]) =>\n\t\t\t!col.shouldDisableInsert()\n\t\t);\n\t\tconst insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));\n\n\t\tif (select) {\n\t\t\tconst select = valuesOrSelect as AnySQLiteSelectQueryBuilder | SQL;\n\n\t\t\tif (is(select, SQL)) {\n\t\t\t\tvaluesSqlList.push(select);\n\t\t\t} else {\n\t\t\t\tvaluesSqlList.push(select.getSQL());\n\t\t\t}\n\t\t} else {\n\t\t\tconst values = valuesOrSelect as Record<string, Param | SQL>[];\n\t\t\tvaluesSqlList.push(sql.raw('values '));\n\n\t\t\tfor (const [valueIndex, value] of values.entries()) {\n\t\t\t\tconst valueList: (SQLChunk | SQL)[] = [];\n\t\t\t\tfor (const [fieldName, col] of colEntries) {\n\t\t\t\t\tconst colValue = value[fieldName];\n\t\t\t\t\tif (colValue === undefined || (is(colValue, Param) && colValue.value === undefined)) {\n\t\t\t\t\t\tlet defaultValue;\n\t\t\t\t\t\tif (col.default !== null && col.default !== undefined) {\n\t\t\t\t\t\t\tdefaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);\n\t\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\t\t} else if (col.defaultFn !== undefined) {\n\t\t\t\t\t\t\tconst defaultFnResult = col.defaultFn();\n\t\t\t\t\t\t\tdefaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);\n\t\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\t\t} else if (!col.default && col.onUpdateFn !== undefined) {\n\t\t\t\t\t\t\tconst onUpdateFnResult = col.onUpdateFn();\n\t\t\t\t\t\t\tdefaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdefaultValue = sql`null`;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvalueList.push(defaultValue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalueList.push(colValue);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvaluesSqlList.push(valueList);\n\t\t\t\tif (valueIndex < values.length - 1) {\n\t\t\t\t\tvaluesSqlList.push(sql`, `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst valuesSql = sql.join(valuesSqlList);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst onConflictSql = onConflict?.length\n\t\t\t? sql.join(onConflict)\n\t\t\t: undefined;\n\n\t\t// if (isSingleValue && valuesSqlList.length === 0){\n\t\t// \treturn sql`insert into ${table} default values ${onConflictSql}${returningSql}`;\n\t\t// }\n\n\t\treturn sql`${withSql}insert into ${table} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;\n\t}\n\n\tsqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings {\n\t\treturn sql.toQuery({\n\t\t\tcasing: this.casing,\n\t\t\tescapeName: this.escapeName,\n\t\t\tescapeParam: this.escapeParam,\n\t\t\tescapeString: this.escapeString,\n\t\t\tinvokeSource,\n\t\t});\n\t}\n\n\t/** @deprecated */\n\t_buildRelationalQuery({\n\t\tfullSchema,\n\t\tschema,\n\t\ttableNamesMap,\n\t\ttable,\n\t\ttableConfig,\n\t\tqueryConfig: config,\n\t\ttableAlias,\n\t\tnestedQueryRelation,\n\t\tjoinOn,\n\t}: {\n\t\tfullSchema: Record<string, unknown>;\n\t\tschema: V1.TablesRelationalConfig;\n\t\ttableNamesMap: Record<string, string>;\n\t\ttable: SQLiteTable;\n\t\ttableConfig: V1.TableRelationalConfig;\n\t\tqueryConfig: true | V1.DBQueryConfig<'many', true>;\n\t\ttableAlias: string;\n\t\tnestedQueryRelation?: V1.Relation;\n\t\tjoinOn?: SQL;\n\t}): V1.BuildRelationalQueryResult<SQLiteTable, SQLiteColumn> {\n\t\tlet selection: V1.BuildRelationalQueryResult<SQLiteTable, SQLiteColumn>['selection'] = [];\n\t\tlet limit, offset, orderBy: SQLiteSelectConfig['orderBy'] = [], where;\n\t\tconst joins: SQLiteSelectJoinConfig[] = [];\n\n\t\tif (config === true) {\n\t\t\tconst selectionEntries = Object.entries(tableConfig.columns);\n\t\t\tselection = selectionEntries.map((\n\t\t\t\t[key, value],\n\t\t\t) => ({\n\t\t\t\tdbKey: value.name,\n\t\t\t\ttsKey: key,\n\t\t\t\tfield: aliasedTableColumn(value as SQLiteColumn, tableAlias),\n\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\tisJson: false,\n\t\t\t\tselection: [],\n\t\t\t}));\n\t\t} else {\n\t\t\tconst aliasedColumns = Object.fromEntries(\n\t\t\t\tObject.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),\n\t\t\t);\n\n\t\t\tif (config.where) {\n\t\t\t\tconst whereSql = typeof config.where === 'function'\n\t\t\t\t\t? config.where(aliasedColumns, V1.getOperators())\n\t\t\t\t\t: config.where;\n\t\t\t\twhere = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);\n\t\t\t}\n\n\t\t\tconst fieldsSelection: { tsKey: string; value: SQLiteColumn | SQL.Aliased }[] = [];\n\t\t\tlet selectedColumns: string[] = [];\n\n\t\t\t// Figure out which columns to select\n\t\t\tif (config.columns) {\n\t\t\t\tlet isIncludeMode = false;\n\n\t\t\t\tfor (const [field, value] of Object.entries(config.columns)) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field in tableConfig.columns) {\n\t\t\t\t\t\tif (!isIncludeMode && value === true) {\n\t\t\t\t\t\t\tisIncludeMode = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tselectedColumns.push(field);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (selectedColumns.length > 0) {\n\t\t\t\t\tselectedColumns = isIncludeMode\n\t\t\t\t\t\t? selectedColumns.filter((c) => config.columns?.[c] === true)\n\t\t\t\t\t\t: Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Select all columns if selection is not specified\n\t\t\t\tselectedColumns = Object.keys(tableConfig.columns);\n\t\t\t}\n\n\t\t\tfor (const field of selectedColumns) {\n\t\t\t\tconst column = tableConfig.columns[field]! as SQLiteColumn;\n\t\t\t\tfieldsSelection.push({ tsKey: field, value: column });\n\t\t\t}\n\n\t\t\tlet selectedRelations: {\n\t\t\t\ttsKey: string;\n\t\t\t\tqueryConfig: true | V1.DBQueryConfig<'many', false>;\n\t\t\t\trelation: V1.Relation;\n\t\t\t}[] = [];\n\n\t\t\t// Figure out which relations to select\n\t\t\tif (config.with) {\n\t\t\t\tselectedRelations = Object.entries(config.with)\n\t\t\t\t\t.filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])\n\t\t\t\t\t.map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));\n\t\t\t}\n\n\t\t\tlet extras;\n\n\t\t\t// Figure out which extras to select\n\t\t\tif (config.extras) {\n\t\t\t\textras = typeof config.extras === 'function'\n\t\t\t\t\t? config.extras(aliasedColumns, { sql })\n\t\t\t\t\t: config.extras;\n\t\t\t\tfor (const [tsKey, value] of Object.entries(extras)) {\n\t\t\t\t\tfieldsSelection.push({\n\t\t\t\t\t\ttsKey,\n\t\t\t\t\t\tvalue: mapColumnsInAliasedSQLToAlias(value, tableAlias),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Transform `fieldsSelection` into `selection`\n\t\t\t// `fieldsSelection` shouldn't be used after this point\n\t\t\tfor (const { tsKey, value } of fieldsSelection) {\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,\n\t\t\t\t\ttsKey,\n\t\t\t\t\tfield: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,\n\t\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\t\tisJson: false,\n\t\t\t\t\tselection: [],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet orderByOrig = typeof config.orderBy === 'function'\n\t\t\t\t? config.orderBy(aliasedColumns, V1.getOrderByOperators())\n\t\t\t\t: config.orderBy ?? [];\n\t\t\tif (!Array.isArray(orderByOrig)) {\n\t\t\t\torderByOrig = [orderByOrig];\n\t\t\t}\n\t\t\torderBy = orderByOrig.map((orderByValue) => {\n\t\t\t\tif (is(orderByValue, Column)) {\n\t\t\t\t\treturn aliasedTableColumn(orderByValue, tableAlias) as SQLiteColumn;\n\t\t\t\t}\n\t\t\t\treturn mapColumnsInSQLToAlias(orderByValue, tableAlias);\n\t\t\t});\n\n\t\t\tlimit = config.limit;\n\t\t\toffset = config.offset;\n\n\t\t\t// Process all relations\n\t\t\tfor (\n\t\t\t\tconst {\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tqueryConfig: selectedRelationConfigValue,\n\t\t\t\t\trelation,\n\t\t\t\t} of selectedRelations\n\t\t\t) {\n\t\t\t\tconst normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);\n\t\t\t\tconst relationTableName = getTableUniqueName(relation.referencedTable);\n\t\t\t\tconst relationTableTsName = tableNamesMap[relationTableName]!;\n\t\t\t\tconst relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;\n\t\t\t\t// const relationTable = schema[relationTableTsName]!;\n\t\t\t\tconst joinOn = and(\n\t\t\t\t\t...normalizedRelation.fields.map((field, i) =>\n\t\t\t\t\t\teq(\n\t\t\t\t\t\t\taliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),\n\t\t\t\t\t\t\taliasedTableColumn(field, tableAlias),\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tconst builtRelation = this._buildRelationalQuery({\n\t\t\t\t\tfullSchema,\n\t\t\t\t\tschema,\n\t\t\t\t\ttableNamesMap,\n\t\t\t\t\ttable: fullSchema[relationTableTsName] as SQLiteTable,\n\t\t\t\t\ttableConfig: schema[relationTableTsName]!,\n\t\t\t\t\tqueryConfig: is(relation, V1.One)\n\t\t\t\t\t\t? (selectedRelationConfigValue === true\n\t\t\t\t\t\t\t? { limit: 1 }\n\t\t\t\t\t\t\t: { ...selectedRelationConfigValue, limit: 1 })\n\t\t\t\t\t\t: selectedRelationConfigValue,\n\t\t\t\t\ttableAlias: relationTableAlias,\n\t\t\t\t\tjoinOn,\n\t\t\t\t\tnestedQueryRelation: relation,\n\t\t\t\t});\n\t\t\t\tconst field = (sql`(${builtRelation.sql})`).as(selectedRelationTsKey);\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: selectedRelationTsKey,\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tfield,\n\t\t\t\t\trelationTableTsKey: relationTableTsName,\n\t\t\t\t\tisJson: true,\n\t\t\t\t\tselection: builtRelation.selection,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (selection.length === 0) {\n\t\t\tthrow new DrizzleError({\n\t\t\t\tmessage:\n\t\t\t\t\t`No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\"). You need to have at least one item in \"columns\", \"with\" or \"extras\". If you need to select all columns, omit the \"columns\" key or set it to undefined.`,\n\t\t\t});\n\t\t}\n\n\t\tlet result;\n\n\t\twhere = and(joinOn, where);\n\n\t\tif (nestedQueryRelation) {\n\t\t\tlet field = sql`json_array(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field }) =>\n\t\t\t\t\t\tis(field, SQLiteColumn)\n\t\t\t\t\t\t\t? sql.identifier(this.casing.getColumnCasing(field))\n\t\t\t\t\t\t\t: is(field, SQL.Aliased)\n\t\t\t\t\t\t\t? field.sql\n\t\t\t\t\t\t\t: field\n\t\t\t\t\t),\n\t\t\t\t\tsql`, `,\n\t\t\t\t)\n\t\t\t})`;\n\t\t\tif (is(nestedQueryRelation, V1.Many)) {\n\t\t\t\tfield = sql`coalesce(json_group_array(${field}), json_array())`;\n\t\t\t}\n\t\t\tconst nestedSelection = [{\n\t\t\t\tdbKey: 'data',\n\t\t\t\ttsKey: 'data',\n\t\t\t\tfield: field.as('data'),\n\t\t\t\tisJson: true,\n\t\t\t\trelationTableTsKey: tableConfig.tsName,\n\t\t\t\tselection,\n\t\t\t}];\n\n\t\t\tconst needsSubquery = limit !== undefined || offset !== undefined || orderBy.length > 0;\n\n\t\t\tif (needsSubquery) {\n\t\t\t\tresult = this.buildSelectQuery({\n\t\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\t\tfields: {},\n\t\t\t\t\tfieldsFlat: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\tfield: sql.raw('*'),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\twhere,\n\t\t\t\t\tlimit,\n\t\t\t\t\toffset,\n\t\t\t\t\torderBy,\n\t\t\t\t\tsetOperators: [],\n\t\t\t\t});\n\n\t\t\t\twhere = undefined;\n\t\t\t\tlimit = undefined;\n\t\t\t\toffset = undefined;\n\t\t\t\torderBy = undefined;\n\t\t\t} else {\n\t\t\t\tresult = aliasedTable(table, tableAlias);\n\t\t\t}\n\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: is(result, SQLiteTable) ? result : new Subquery(result, {}, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: nestedSelection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t} else {\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: selection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttableTsKey: tableConfig.tsName,\n\t\t\tsql: result,\n\t\t\tselection,\n\t\t};\n\t}\n\n\tprivate nestedSelectionerror() {\n\t\tthrow new DrizzleError({\n\t\t\tmessage: `Views with nested selections are not supported by the relational query builder`,\n\t\t});\n\t}\n\n\tprivate buildRqbColumn(table: Table | View, column: unknown, key: string) {\n\t\tif (is(column, Column)) {\n\t\t\tconst name = sql`${table}.${sql.identifier(this.casing.getColumnCasing(column))}`;\n\n\t\t\tswitch (column.columnType) {\n\t\t\t\tcase 'SQLiteBigInt':\n\t\t\t\tcase 'SQLiteBlobJson':\n\t\t\t\tcase 'SQLiteBlobBuffer': {\n\t\t\t\t\treturn sql`hex(${name}) as ${sql.identifier(key)}`;\n\t\t\t\t}\n\n\t\t\t\tcase 'SQLiteNumeric':\n\t\t\t\tcase 'SQLiteNumericNumber':\n\t\t\t\tcase 'SQLiteNumericBigInt': {\n\t\t\t\t\treturn sql`cast(${name} as text) as ${sql.identifier(key)}`;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn sql`${name} as ${sql.identifier(key)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn sql`${table}.${\n\t\t\tis(column, SQL.Aliased)\n\t\t\t\t? sql.identifier(column.fieldAlias)\n\t\t\t\t: isSQLWrapper(column)\n\t\t\t\t? sql.identifier(key)\n\t\t\t\t: this.nestedSelectionerror()\n\t\t} as ${sql.identifier(key)}`;\n\t}\n\n\tprivate unwrapAllColumns = (table: Table | View, selection: BuildRelationalQueryResult['selection']) => {\n\t\treturn sql.join(\n\t\t\tObject.entries(table[Columns]).map(([k, v]) => {\n\t\t\t\tselection.push({\n\t\t\t\t\tkey: k,\n\t\t\t\t\tfield: v as Column | SQL | SQLWrapper | SQL.Aliased,\n\t\t\t\t});\n\n\t\t\t\treturn this.buildRqbColumn(table, v, k);\n\t\t\t}),\n\t\t\tsql`, `,\n\t\t);\n\t};\n\n\tprivate getSelectedTableColumns = (table: Table | View, columns: Record<string, boolean | undefined>) => {\n\t\tconst selectedColumns: ColumnWithTSName[] = [];\n\t\tconst columnContainer = table[Columns];\n\t\tconst entries = Object.entries(columns);\n\n\t\tlet colSelectionMode: boolean | undefined;\n\t\tfor (const [k, v] of entries) {\n\t\t\tif (v === undefined) continue;\n\t\t\tcolSelectionMode = colSelectionMode || v;\n\n\t\t\tif (v) {\n\t\t\t\tconst column = columnContainer[k]!;\n\n\t\t\t\tselectedColumns.push({\n\t\t\t\t\tcolumn: column as Column | SQL | SQLWrapper | SQL.Aliased,\n\t\t\t\t\ttsName: k,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (colSelectionMode === false) {\n\t\t\tfor (const [k, v] of Object.entries(columnContainer)) {\n\t\t\t\tif (columns[k] === false) continue;\n\n\t\t\t\tselectedColumns.push({\n\t\t\t\t\tcolumn: v as Column | SQL | SQLWrapper | SQL.Aliased | Table,\n\t\t\t\t\ttsName: k,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn selectedColumns;\n\t};\n\n\tprivate buildColumns = (\n\t\ttable: SQLiteTable | SQLiteView,\n\t\tselection: BuildRelationalQueryResult['selection'],\n\t\tparams?: DBQueryConfig<'many'>,\n\t) =>\n\t\tparams?.columns\n\t\t\t? (() => {\n\t\t\t\tconst columnIdentifiers: SQL[] = [];\n\n\t\t\t\tconst selectedColumns = this.getSelectedTableColumns(table, params?.columns);\n\n\t\t\t\tfor (const { column, tsName } of selectedColumns) {\n\t\t\t\t\tcolumnIdentifiers.push(this.buildRqbColumn(table, column, tsName));\n\t\t\t\t\tselection.push({\n\t\t\t\t\t\tkey: tsName,\n\t\t\t\t\t\tfield: column,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn columnIdentifiers.length\n\t\t\t\t\t? sql.join(columnIdentifiers, sql`, `)\n\t\t\t\t\t: undefined;\n\t\t\t})()\n\t\t\t: this.unwrapAllColumns(table, selection);\n\n\tbuildRelationalQuery(\n\t\t{\n\t\t\ttables,\n\t\t\tschema,\n\t\t\ttableNamesMap,\n\t\t\ttable,\n\t\t\ttableConfig,\n\t\t\tqueryConfig: config,\n\t\t\trelationWhere,\n\t\t\tmode,\n\t\t\tisNested,\n\t\t\terrorPath,\n\t\t\tdepth,\n\t\t\tthroughJoin,\n\t\t\tjsonb,\n\t\t}: {\n\t\t\ttables: Record<string, SQLiteTable | SQLiteView>;\n\t\t\tschema: TablesRelationalConfig;\n\t\t\ttableNamesMap: Record<string, string>;\n\t\t\ttable: SQLiteTable | SQLiteView;\n\t\t\ttableConfig: TableRelationalConfig;\n\t\t\tqueryConfig?: DBQueryConfig<'many'> | true;\n\t\t\trelationWhere?: SQL;\n\t\t\tmode: 'first' | 'many';\n\t\t\tisNested?: boolean;\n\t\t\terrorPath?: string;\n\t\t\tdepth?: number;\n\t\t\tthroughJoin?: SQL;\n\t\t\tjsonb: SQL;\n\t\t},\n\t): BuildRelationalQueryResult {\n\t\tconst selection: BuildRelationalQueryResult['selection'] = [];\n\t\tconst isSingle = mode === 'first';\n\t\tconst params = config === true ? undefined : config;\n\t\tconst currentPath = errorPath ?? '';\n\t\tconst currentDepth = depth ?? 0;\n\t\tif (!currentDepth) table = aliasedTable(table, `d${currentDepth}`);\n\n\t\tconst limit = isSingle ? 1 : params?.limit;\n\t\tconst offset = params?.offset;\n\n\t\tconst columns = this.buildColumns(table, selection, params);\n\n\t\tconst where: SQL | undefined = (params?.where && relationWhere)\n\t\t\t? and(\n\t\t\t\trelationsFilterToSQL(table, params.where, tableConfig.relations, schema, tableNamesMap, this.casing),\n\t\t\t\trelationWhere,\n\t\t\t)\n\t\t\t: params?.where\n\t\t\t? relationsFilterToSQL(table, params.where, tableConfig.relations, schema, tableNamesMap, this.casing)\n\t\t\t: relationWhere;\n\t\tconst order = params?.orderBy ? relationsOrderToSQL(table, params.orderBy) : undefined;\n\t\tconst extras = params?.extras ? relationExtrasToSQL(table, params.extras) : undefined;\n\t\tif (extras) selection.push(...extras.selection);\n\n\t\tconst joins = params\n\t\t\t? (() => {\n\t\t\t\tconst { with: joins } = params as WithContainer;\n\t\t\t\tif (!joins) return;\n\n\t\t\t\tconst withEntries = Object.entries(joins).filter(([_, v]) => v);\n\t\t\t\tif (!withEntries.length) return;\n\n\t\t\t\treturn sql.join(\n\t\t\t\t\twithEntries.map(([k, join]) => {\n\t\t\t\t\t\t// if (is(tableConfig.relations[k]!, AggregatedField)) {\n\t\t\t\t\t\t// \tconst relation = tableConfig.relations[k]!;\n\n\t\t\t\t\t\t// \trelation.onTable(table);\n\t\t\t\t\t\t// \tconst query = relation.getSQL();\n\n\t\t\t\t\t\t// \tselection.push({\n\t\t\t\t\t\t// \t\tkey: k,\n\t\t\t\t\t\t// \t\tfield: relation,\n\t\t\t\t\t\t// \t});\n\n\t\t\t\t\t\t// \treturn sql`(${query}) as ${sql.identifier(k)}`;\n\t\t\t\t\t\t// }\n\n\t\t\t\t\t\tconst relation = tableConfig.relations[k]! as Relation;\n\t\t\t\t\t\tconst isSingle = is(relation, One);\n\t\t\t\t\t\tconst targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);\n\t\t\t\t\t\tconst throughTable = relation.throughTable\n\t\t\t\t\t\t\t? aliasedTable(relation.throughTable, `tr${currentDepth}`)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tconst { filter, joinCondition } = relationToSQL(\n\t\t\t\t\t\t\tthis.casing,\n\t\t\t\t\t\t\trelation,\n\t\t\t\t\t\t\ttable,\n\t\t\t\t\t\t\ttargetTable,\n\t\t\t\t\t\t\tthroughTable,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst throughJoin = throughTable\n\t\t\t\t\t\t\t? sql` inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition!}`\n\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\t\tconst innerQuery = this.buildRelationalQuery({\n\t\t\t\t\t\t\ttable: targetTable as SQLiteTable | SQLiteView,\n\t\t\t\t\t\t\tmode: isSingle ? 'first' : 'many',\n\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\tqueryConfig: join as DBQueryConfig,\n\t\t\t\t\t\t\ttableConfig: schema[tableNamesMap[getTableUniqueName(relation.targetTable)]!]!,\n\t\t\t\t\t\t\ttableNamesMap,\n\t\t\t\t\t\t\ttables,\n\t\t\t\t\t\t\trelationWhere: filter,\n\t\t\t\t\t\t\tisNested: true,\n\t\t\t\t\t\t\terrorPath: `${currentPath.length ? `${currentPath}.` : ''}${k}`,\n\t\t\t\t\t\t\tdepth: currentDepth + 1,\n\t\t\t\t\t\t\tthroughJoin,\n\t\t\t\t\t\t\tjsonb,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tselection.push({\n\t\t\t\t\t\t\tfield: targetTable,\n\t\t\t\t\t\t\tkey: k,\n\t\t\t\t\t\t\tselection: innerQuery.selection,\n\t\t\t\t\t\t\tisArray: !isSingle,\n\t\t\t\t\t\t\tisOptional: ((relation as One<any, any>).optional ?? false)\n\t\t\t\t\t\t\t\t|| (join !== true && !!(join as Exclude<typeof join, boolean | undefined>).where),\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tconst jsonColumns = sql.join(\n\t\t\t\t\t\t\tinnerQuery.selection.map((s) => {\n\t\t\t\t\t\t\t\treturn sql`${sql.raw(this.escapeString(s.key))}, ${\n\t\t\t\t\t\t\t\t\ts.selection ? sql`${jsonb}(${sql.identifier(s.key)})` : sql.identifier(s.key)\n\t\t\t\t\t\t\t\t}`;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tsql`, `,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst json = isNested ? jsonb : sql`json`;\n\n\t\t\t\t\t\tconst joinQuery = isSingle\n\t\t\t\t\t\t\t? sql`(select ${json}_object(${jsonColumns}) as ${sql.identifier('r')} from (${innerQuery.sql}) as ${\n\t\t\t\t\t\t\t\tsql.identifier('t')\n\t\t\t\t\t\t\t}) as ${sql.identifier(k)}`\n\t\t\t\t\t\t\t: sql`coalesce((select ${json}_group_array(json_object(${jsonColumns})) as ${\n\t\t\t\t\t\t\t\tsql.identifier('r')\n\t\t\t\t\t\t\t} from (${innerQuery.sql}) as ${sql.identifier('t')}), ${jsonb}_array()) as ${sql.identifier(k)}`;\n\n\t\t\t\t\t\treturn joinQuery;\n\t\t\t\t\t}),\n\t\t\t\t\tsql`, `,\n\t\t\t\t);\n\t\t\t})()\n\t\t\t: undefined;\n\n\t\tconst selectionArr = [columns, extras?.sql, joins].filter((e) => e !== undefined);\n\t\tif (!selectionArr.length) {\n\t\t\tthrow new DrizzleError({\n\t\t\t\tmessage: `No fields selected for table \"${tableConfig.tsName}\"${currentPath ? ` (\"${currentPath}\")` : ''}`,\n\t\t\t});\n\t\t}\n\t\tconst selectionSet = sql.join(selectionArr, sql`, `);\n\n\t\tconst query = sql`select ${selectionSet} from ${getTableAsAliasSQL(table)}${throughJoin}${\n\t\t\tsql` where ${where}`.if(where)\n\t\t}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== undefined)}${\n\t\t\tsql` offset ${offset}`.if(offset !== undefined)\n\t\t}`;\n\n\t\treturn {\n\t\t\tsql: query,\n\t\t\tselection,\n\t\t};\n\t}\n}\n\nexport class SQLiteSyncDialect extends SQLiteDialect {\n\tstatic override readonly [entityKind]: string = 'SQLiteSyncDialect';\n\n\tmigrate(\n\t\tmigrations: MigrationMeta[],\n\t\tsession: SQLiteSession<\n\t\t\t'sync',\n\t\t\tunknown,\n\t\t\tRecord<string, unknown>,\n\t\t\tAnyRelations,\n\t\t\tTablesRelationalConfig,\n\t\t\tV1.TablesRelationalConfig\n\t\t>,\n\t\tconfig?: string | MigrationConfig,\n\t): void {\n\t\tconst migrationsTable = config === undefined\n\t\t\t? '__drizzle_migrations'\n\t\t\t: typeof config === 'string'\n\t\t\t? '__drizzle_migrations'\n\t\t\t: config.migrationsTable ?? '__drizzle_migrations';\n\n\t\tconst migrationTableCreate = sql`\n\t\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\t\tid SERIAL PRIMARY KEY,\n\t\t\t\thash text NOT NULL,\n\t\t\t\tcreated_at numeric\n\t\t\t)\n\t\t`;\n\t\tsession.run(migrationTableCreate);\n\n\t\tconst dbMigrations = session.values<[number, string, string]>(\n\t\t\tsql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`,\n\t\t);\n\n\t\tconst lastDbMigration = dbMigrations[0] ?? undefined;\n\t\tsession.run(sql`BEGIN`);\n\n\t\ttry {\n\t\t\tfor (const migration of migrations) {\n\t\t\t\tif (!lastDbMigration || Number(lastDbMigration[2])! < migration.folderMillis) {\n\t\t\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\t\t\tsession.run(sql.raw(stmt));\n\t\t\t\t\t}\n\t\t\t\t\tsession.run(\n\t\t\t\t\t\tsql`INSERT INTO ${\n\t\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t\t} (\"hash\", \"created_at\") VALUES(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsession.run(sql`COMMIT`);\n\t\t} catch (e) {\n\t\t\tsession.run(sql`ROLLBACK`);\n\t\t\tthrow e;\n\t\t}\n\t}\n}\n\nexport class SQLiteAsyncDialect extends SQLiteDialect {\n\tstatic override readonly [entityKind]: string = 'SQLiteAsyncDialect';\n\n\tasync migrate(\n\t\tmigrations: MigrationMeta[],\n\t\tsession: SQLiteSession<\n\t\t\t'async',\n\t\t\tunknown,\n\t\t\tRecord<string, unknown>,\n\t\t\tAnyRelations,\n\t\t\tTablesRelationalConfig,\n\t\t\tV1.TablesRelationalConfig\n\t\t>,\n\t\tconfig?: string | MigrationConfig,\n\t): Promise<void> {\n\t\tconst migrationsTable = config === undefined\n\t\t\t? '__drizzle_migrations'\n\t\t\t: typeof config === 'string'\n\t\t\t? '__drizzle_migrations'\n\t\t\t: config.migrationsTable ?? '__drizzle_migrations';\n\n\t\tconst migrationTableCreate = sql`\n\t\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\t\tid SERIAL PRIMARY KEY,\n\t\t\t\thash text NOT NULL,\n\t\t\t\tcreated_at numeric\n\t\t\t)\n\t\t`;\n\t\tawait session.run(migrationTableCreate);\n\n\t\tconst dbMigrations = await session.values<[number, string, string]>(\n\t\t\tsql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`,\n\t\t);\n\n\t\tconst lastDbMigration = dbMigrations[0] ?? undefined;\n\n\t\tawait session.transaction(async (tx) => {\n\t\t\tfor (const migration of migrations) {\n\t\t\t\tif (!lastDbMigration || Number(lastDbMigration[2])! < migration.folderMillis) {\n\t\t\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\t\t\tawait tx.run(sql.raw(stmt));\n\t\t\t\t\t}\n\t\t\t\t\tawait tx.run(\n\t\t\t\t\t\tsql`INSERT INTO ${\n\t\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t\t} (\"hash\", \"created_at\") VALUES(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,EAEhD,MAAM,QACL,YACA,SAQA,QACgB;AAChB,UAAM,kBAAkB,WAAW,SAChC,yBACA,OAAO,WAAW,WAClB,yBACA,OAAO,mBAAmB;AAE7B,UAAM,uBAAuB;AAAA,gCACC,gBAAI,WAAW,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAM7D,UAAM,QAAQ,IAAI,oBAAoB;AAEtC,UAAM,eAAe,MAAM,QAAQ;AAAA,MAClC,mDAAuC,gBAAI,WAAW,eAAe,CAAC;AAAA,IACvE;AAEA,UAAM,kBAAkB,aAAa,CAAC,KAAK;AAE3C,UAAM,QAAQ,YAAY,OAAO,OAAO;AACvC,iBAAW,aAAa,YAAY;AACnC,YAAI,CAAC,mBAAmB,OAAO,gBAAgB,CAAC,CAAC,IAAK,UAAU,cAAc;AAC7E,qBAAW,QAAQ,UAAU,KAAK;AACjC,kBAAM,GAAG,IAAI,gBAAI,IAAI,IAAI,CAAC;AAAA,UAC3B;AACA,gBAAM,GAAG;AAAA,YACR,8BACC,gBAAI,WAAW,eAAe,CAC/B,kCAAkC,UAAU,IAAI,KAAK,UAAU,YAAY;AAAA,UAC5E;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAC;AAAA,EACF;AACD;","names":["import_sql","import_table","table","select","sql","joinOn","field","joins","isSingle","throughJoin"]}
|
|
1
|
+
{"version":3,"sources":["../../src/sqlite-core/dialect.ts"],"sourcesContent":["import * as V1 from '~/_relations.ts';\nimport { aliasedTable, aliasedTableColumn, mapColumnsInAliasedSQLToAlias, mapColumnsInSQLToAlias } from '~/alias.ts';\nimport { CasingCache } from '~/casing.ts';\nimport type { AnyColumn } from '~/column.ts';\nimport { Column } from '~/column.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { DrizzleError } from '~/errors.ts';\nimport type { MigrationConfig, MigrationMeta } from '~/migrator.ts';\nimport {\n\t// AggregatedField,\n\ttype AnyRelations,\n\ttype BuildRelationalQueryResult,\n\ttype ColumnWithTSName,\n\ttype DBQueryConfig,\n\tgetTableAsAliasSQL,\n\tOne,\n\ttype Relation,\n\trelationExtrasToSQL,\n\trelationsFilterToSQL,\n\trelationsOrderToSQL,\n\trelationToSQL,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n\ttype WithContainer,\n} from '~/relations.ts';\nimport type { Name, Placeholder, SQLWrapper, View } from '~/sql/index.ts';\nimport { and, eq, isSQLWrapper } from '~/sql/index.ts';\nimport { Param, type QueryWithTypings, SQL, sql, type SQLChunk } from '~/sql/sql.ts';\nimport { SQLiteColumn, type SQLiteCustomColumn } from '~/sqlite-core/columns/index.ts';\nimport type {\n\tAnySQLiteSelectQueryBuilder,\n\tSQLiteDeleteConfig,\n\tSQLiteInsertConfig,\n\tSQLiteUpdateConfig,\n} from '~/sqlite-core/query-builders/index.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { Columns, getTableName, getTableUniqueName, Table } from '~/table.ts';\nimport { type Casing, orderSelectedFields, type UpdateSet } from '~/utils.ts';\nimport { ViewBaseConfig } from '~/view-common.ts';\nimport type {\n\tSelectedFieldsOrdered,\n\tSQLiteSelectConfig,\n\tSQLiteSelectJoinConfig,\n} from './query-builders/select.types.ts';\nimport type { SQLiteSession } from './session.ts';\nimport { SQLiteViewBase } from './view-base.ts';\nimport type { SQLiteView } from './view.ts';\n\nexport interface SQLiteDialectConfig {\n\tcasing?: Casing;\n}\n\nexport abstract class SQLiteDialect {\n\tstatic readonly [entityKind]: string = 'SQLiteDialect';\n\n\t/** @internal */\n\treadonly casing: CasingCache;\n\n\tconstructor(config?: SQLiteDialectConfig) {\n\t\tthis.casing = new CasingCache(config?.casing);\n\t}\n\n\tescapeName(name: string): string {\n\t\treturn `\"${name}\"`;\n\t}\n\n\tescapeParam(_num: number): string {\n\t\treturn '?';\n\t}\n\n\tescapeString(str: string): string {\n\t\treturn `'${str.replace(/'/g, \"''\")}'`;\n\t}\n\n\tprivate buildWithCTE(queries: Subquery[] | undefined): SQL | undefined {\n\t\tif (!queries?.length) return undefined;\n\n\t\tconst withSqlChunks = [sql`with `];\n\t\tfor (const [i, w] of queries.entries()) {\n\t\t\twithSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);\n\t\t\tif (i < queries.length - 1) {\n\t\t\t\twithSqlChunks.push(sql`, `);\n\t\t\t}\n\t\t}\n\t\twithSqlChunks.push(sql` `);\n\t\treturn sql.join(withSqlChunks);\n\t}\n\n\tbuildDeleteQuery({ table, where, returning, withList, limit, orderBy }: SQLiteDeleteConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}delete from ${table}${whereSql}${returningSql}${orderBySql}${limitSql}`;\n\t}\n\n\tbuildUpdateSet(table: SQLiteTable, set: UpdateSet): SQL {\n\t\tconst tableColumns = table[Table.Symbol.Columns];\n\n\t\tconst columnNames = Object.keys(tableColumns).filter((colName) =>\n\t\t\tset[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined\n\t\t);\n\n\t\tconst setSize = columnNames.length;\n\t\treturn sql.join(columnNames.flatMap((colName, i) => {\n\t\t\tconst col = tableColumns[colName]!;\n\n\t\t\tconst value = set[colName] ?? sql.param(col.onUpdateFn!(), col);\n\t\t\tconst res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;\n\n\t\t\tif (i < setSize - 1) {\n\t\t\t\treturn [res, sql.raw(', ')];\n\t\t\t}\n\t\t\treturn [res];\n\t\t}));\n\t}\n\n\tbuildUpdateQuery({ table, set, where, returning, withList, joins, from, limit, orderBy }: SQLiteUpdateConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst setSql = this.buildUpdateSet(table, set);\n\n\t\tconst fromSql = from && sql.join([sql.raw(' from '), this.buildFromTable(from)]);\n\n\t\tconst joinsSql = this.buildJoins(joins);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}update ${table} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;\n\t}\n\n\t/**\n\t * Builds selection SQL with provided fields/expressions\n\t *\n\t * Examples:\n\t *\n\t * `select <selection> from`\n\t *\n\t * `insert ... returning <selection>`\n\t *\n\t * If `isSingleTable` is true, then columns won't be prefixed with table name\n\t */\n\tprivate buildSelection(\n\t\tfields: SelectedFieldsOrdered,\n\t\t{ isSingleTable = false }: { isSingleTable?: boolean } = {},\n\t): SQL {\n\t\tconst columnsLen = fields.length;\n\n\t\tconst chunks = fields\n\t\t\t.flatMap(({ field }, i) => {\n\t\t\t\tconst chunk: SQLChunk[] = [];\n\n\t\t\t\tif (is(field, SQL.Aliased) && field.isSelectionField) {\n\t\t\t\t\tchunk.push(sql.identifier(field.fieldAlias));\n\t\t\t\t} else if (is(field, SQL.Aliased) || is(field, SQL)) {\n\t\t\t\t\tconst query = is(field, SQL.Aliased) ? field.sql : field;\n\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(\n\t\t\t\t\t\t\tnew SQL(\n\t\t\t\t\t\t\t\tquery.queryChunks.map((c) => {\n\t\t\t\t\t\t\t\t\tif (is(c, Column)) {\n\t\t\t\t\t\t\t\t\t\treturn sql.identifier(this.casing.getColumnCasing(c));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn c;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(query);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (is(field, SQL.Aliased)) {\n\t\t\t\t\t\tchunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);\n\t\t\t\t\t}\n\t\t\t\t} else if (is(field, Column)) {\n\t\t\t\t\tconst tableName = field.table[Table.Symbol.Name];\n\t\t\t\t\tif (field.columnType === 'SQLiteNumericBigInt') {\n\t\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\t\tchunk.push(sql`cast(${sql.identifier(this.casing.getColumnCasing(field))} as text)`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchunk.push(\n\t\t\t\t\t\t\t\tsql`cast(${sql.identifier(tableName)}.${sql.identifier(this.casing.getColumnCasing(field))} as text)`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\t\tchunk.push(sql.identifier(this.casing.getColumnCasing(field)));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchunk.push(sql`${sql.identifier(tableName)}.${sql.identifier(this.casing.getColumnCasing(field))}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (i < columnsLen - 1) {\n\t\t\t\t\tchunk.push(sql`, `);\n\t\t\t\t}\n\n\t\t\t\treturn chunk;\n\t\t\t});\n\n\t\treturn sql.join(chunks);\n\t}\n\n\tprivate buildJoins(joins: SQLiteSelectJoinConfig[] | undefined): SQL | undefined {\n\t\tif (!joins || joins.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst joinsArray: SQL[] = [];\n\n\t\tif (joins) {\n\t\t\tfor (const [index, joinMeta] of joins.entries()) {\n\t\t\t\tif (index === 0) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t\tconst table = joinMeta.table;\n\n\t\t\t\tif (is(table, SQLiteTable)) {\n\t\t\t\t\tconst tableName = table[SQLiteTable.Symbol.Name];\n\t\t\t\t\tconst tableSchema = table[SQLiteTable.Symbol.Schema];\n\t\t\t\t\tconst origTableName = table[SQLiteTable.Symbol.OriginalName];\n\t\t\t\t\tconst alias = tableName === origTableName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : undefined}${\n\t\t\t\t\t\t\tsql.identifier(origTableName)\n\t\t\t\t\t\t}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join ${table} on ${joinMeta.on}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (index < joins.length - 1) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn sql.join(joinsArray);\n\t}\n\n\tprivate buildLimit(limit: number | Placeholder | undefined): SQL | undefined {\n\t\treturn typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\t}\n\n\tprivate buildOrderBy(orderBy: (SQLiteColumn | SQL | SQL.Aliased)[] | undefined): SQL | undefined {\n\t\tconst orderByList: (SQLiteColumn | SQL | SQL.Aliased)[] = [];\n\n\t\tif (orderBy) {\n\t\t\tfor (const [index, orderByValue] of orderBy.entries()) {\n\t\t\t\torderByList.push(orderByValue);\n\n\t\t\t\tif (index < orderBy.length - 1) {\n\t\t\t\t\torderByList.push(sql`, `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : undefined;\n\t}\n\n\tprivate buildFromTable(\n\t\ttable: SQL | Subquery | SQLiteViewBase | SQLiteTable | undefined,\n\t): SQL | Subquery | SQLiteViewBase | SQLiteTable | undefined {\n\t\tif (is(table, Table) && table[Table.Symbol.IsAlias]) {\n\t\t\treturn sql`${sql`${sql.identifier(table[Table.Symbol.Schema] ?? '')}.`.if(table[Table.Symbol.Schema])}${\n\t\t\t\tsql.identifier(table[Table.Symbol.OriginalName])\n\t\t\t} ${sql.identifier(table[Table.Symbol.Name])}`;\n\t\t}\n\n\t\treturn table;\n\t}\n\n\tbuildSelectQuery(\n\t\t{\n\t\t\twithList,\n\t\t\tfields,\n\t\t\tfieldsFlat,\n\t\t\twhere,\n\t\t\thaving,\n\t\t\ttable,\n\t\t\tjoins,\n\t\t\torderBy,\n\t\t\tgroupBy,\n\t\t\tlimit,\n\t\t\toffset,\n\t\t\tdistinct,\n\t\t\tsetOperators,\n\t\t}: SQLiteSelectConfig,\n\t): SQL {\n\t\tconst fieldsList = fieldsFlat ?? orderSelectedFields<SQLiteColumn>(fields);\n\t\tfor (const f of fieldsList) {\n\t\t\tif (\n\t\t\t\tis(f.field, Column)\n\t\t\t\t&& getTableName(f.field.table)\n\t\t\t\t\t!== (is(table, Subquery)\n\t\t\t\t\t\t? table._.alias\n\t\t\t\t\t\t: is(table, SQLiteViewBase)\n\t\t\t\t\t\t? table[ViewBaseConfig].name\n\t\t\t\t\t\t: is(table, SQL)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: getTableName(table))\n\t\t\t\t&& !((table) =>\n\t\t\t\t\tjoins?.some(({ alias }) =>\n\t\t\t\t\t\talias === (table[Table.Symbol.IsAlias] ? getTableName(table) : table[Table.Symbol.BaseName])\n\t\t\t\t\t))(f.field.table)\n\t\t\t) {\n\t\t\t\tconst tableName = getTableName(f.field.table);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Your \"${\n\t\t\t\t\t\tf.path.join('->')\n\t\t\t\t\t}\" field references a column \"${tableName}\".\"${f.field.name}\", but the table \"${tableName}\" is not part of the query! Did you forget to join it?`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst isSingleTable = !joins || joins.length === 0;\n\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst distinctSql = distinct ? sql` distinct` : undefined;\n\n\t\tconst selection = this.buildSelection(fieldsList, { isSingleTable });\n\n\t\tconst tableSql = this.buildFromTable(table);\n\n\t\tconst joinsSql = this.buildJoins(joins);\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst havingSql = having ? sql` having ${having}` : undefined;\n\n\t\tconst groupByList: (SQL | AnyColumn | SQL.Aliased)[] = [];\n\t\tif (groupBy) {\n\t\t\tfor (const [index, groupByValue] of groupBy.entries()) {\n\t\t\t\tgroupByList.push(groupByValue);\n\n\t\t\t\tif (index < groupBy.length - 1) {\n\t\t\t\t\tgroupByList.push(sql`, `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst groupBySql = groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\tconst finalQuery =\n\t\t\tsql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}`;\n\n\t\tif (setOperators.length > 0) {\n\t\t\treturn this.buildSetOperations(finalQuery, setOperators);\n\t\t}\n\n\t\treturn finalQuery;\n\t}\n\n\tbuildSetOperations(leftSelect: SQL, setOperators: SQLiteSelectConfig['setOperators']): SQL {\n\t\tconst [setOperator, ...rest] = setOperators;\n\n\t\tif (!setOperator) {\n\t\t\tthrow new Error('Cannot pass undefined values to any set operator');\n\t\t}\n\n\t\tif (rest.length === 0) {\n\t\t\treturn this.buildSetOperationQuery({ leftSelect, setOperator });\n\t\t}\n\n\t\t// Some recursive magic here\n\t\treturn this.buildSetOperations(\n\t\t\tthis.buildSetOperationQuery({ leftSelect, setOperator }),\n\t\t\trest,\n\t\t);\n\t}\n\n\tbuildSetOperationQuery({\n\t\tleftSelect,\n\t\tsetOperator: { type, isAll, rightSelect, limit, orderBy, offset },\n\t}: { leftSelect: SQL; setOperator: SQLiteSelectConfig['setOperators'][number] }): SQL {\n\t\t// SQLite doesn't support parenthesis in set operations\n\t\tconst leftChunk = sql`${leftSelect.getSQL()} `;\n\t\tconst rightChunk = sql`${rightSelect.getSQL()}`;\n\n\t\tlet orderBySql;\n\t\tif (orderBy && orderBy.length > 0) {\n\t\t\tconst orderByValues: (SQL<unknown> | Name)[] = [];\n\n\t\t\t// The next bit is necessary because the sql operator replaces ${table.column} with `table`.`column`\n\t\t\t// which is invalid Sql syntax, Table from one of the SELECTs cannot be used in global ORDER clause\n\t\t\tfor (const singleOrderBy of orderBy) {\n\t\t\t\tif (is(singleOrderBy, SQLiteColumn)) {\n\t\t\t\t\torderByValues.push(sql.identifier(singleOrderBy.name));\n\t\t\t\t} else if (is(singleOrderBy, SQL)) {\n\t\t\t\t\tfor (let i = 0; i < singleOrderBy.queryChunks.length; i++) {\n\t\t\t\t\t\tconst chunk = singleOrderBy.queryChunks[i];\n\n\t\t\t\t\t\tif (is(chunk, SQLiteColumn)) {\n\t\t\t\t\t\t\tsingleOrderBy.queryChunks[i] = sql.identifier(this.casing.getColumnCasing(chunk));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\torderByValues.push(sql`${singleOrderBy}`);\n\t\t\t\t} else {\n\t\t\t\t\torderByValues.push(sql`${singleOrderBy}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\torderBySql = sql` order by ${sql.join(orderByValues, sql`, `)}`;\n\t\t}\n\n\t\tconst limitSql = typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\n\t\tconst operatorChunk = sql.raw(`${type} ${isAll ? 'all ' : ''}`);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\treturn sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;\n\t}\n\n\tbuildInsertQuery(\n\t\t{ table, values: valuesOrSelect, onConflict, returning, withList, select }: SQLiteInsertConfig,\n\t): SQL {\n\t\t// const isSingleValue = values.length === 1;\n\t\tconst valuesSqlList: ((SQLChunk | SQL)[] | SQL)[] = [];\n\t\tconst columns: Record<string, SQLiteColumn> = table[Table.Symbol.Columns];\n\n\t\tconst colEntries: [string, SQLiteColumn][] = Object.entries(columns).filter(([_, col]) =>\n\t\t\t!col.shouldDisableInsert()\n\t\t);\n\t\tconst insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));\n\n\t\tif (select) {\n\t\t\tconst select = valuesOrSelect as AnySQLiteSelectQueryBuilder | SQL;\n\n\t\t\tif (is(select, SQL)) {\n\t\t\t\tvaluesSqlList.push(select);\n\t\t\t} else {\n\t\t\t\tvaluesSqlList.push(select.getSQL());\n\t\t\t}\n\t\t} else {\n\t\t\tconst values = valuesOrSelect as Record<string, Param | SQL>[];\n\t\t\tvaluesSqlList.push(sql.raw('values '));\n\n\t\t\tfor (const [valueIndex, value] of values.entries()) {\n\t\t\t\tconst valueList: (SQLChunk | SQL)[] = [];\n\t\t\t\tfor (const [fieldName, col] of colEntries) {\n\t\t\t\t\tconst colValue = value[fieldName];\n\t\t\t\t\tif (colValue === undefined || (is(colValue, Param) && colValue.value === undefined)) {\n\t\t\t\t\t\tlet defaultValue;\n\t\t\t\t\t\tif (col.default !== null && col.default !== undefined) {\n\t\t\t\t\t\t\tdefaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);\n\t\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\t\t} else if (col.defaultFn !== undefined) {\n\t\t\t\t\t\t\tconst defaultFnResult = col.defaultFn();\n\t\t\t\t\t\t\tdefaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);\n\t\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\t\t} else if (!col.default && col.onUpdateFn !== undefined) {\n\t\t\t\t\t\t\tconst onUpdateFnResult = col.onUpdateFn();\n\t\t\t\t\t\t\tdefaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdefaultValue = sql`null`;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvalueList.push(defaultValue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalueList.push(colValue);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvaluesSqlList.push(valueList);\n\t\t\t\tif (valueIndex < values.length - 1) {\n\t\t\t\t\tvaluesSqlList.push(sql`, `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst valuesSql = sql.join(valuesSqlList);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst onConflictSql = onConflict?.length\n\t\t\t? sql.join(onConflict)\n\t\t\t: undefined;\n\n\t\t// if (isSingleValue && valuesSqlList.length === 0){\n\t\t// \treturn sql`insert into ${table} default values ${onConflictSql}${returningSql}`;\n\t\t// }\n\n\t\treturn sql`${withSql}insert into ${table} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;\n\t}\n\n\tsqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings {\n\t\treturn sql.toQuery({\n\t\t\tcasing: this.casing,\n\t\t\tescapeName: this.escapeName,\n\t\t\tescapeParam: this.escapeParam,\n\t\t\tescapeString: this.escapeString,\n\t\t\tinvokeSource,\n\t\t});\n\t}\n\n\t/** @deprecated */\n\t_buildRelationalQuery({\n\t\tfullSchema,\n\t\tschema,\n\t\ttableNamesMap,\n\t\ttable,\n\t\ttableConfig,\n\t\tqueryConfig: config,\n\t\ttableAlias,\n\t\tnestedQueryRelation,\n\t\tjoinOn,\n\t}: {\n\t\tfullSchema: Record<string, unknown>;\n\t\tschema: V1.TablesRelationalConfig;\n\t\ttableNamesMap: Record<string, string>;\n\t\ttable: SQLiteTable;\n\t\ttableConfig: V1.TableRelationalConfig;\n\t\tqueryConfig: true | V1.DBQueryConfig<'many', true>;\n\t\ttableAlias: string;\n\t\tnestedQueryRelation?: V1.Relation;\n\t\tjoinOn?: SQL;\n\t}): V1.BuildRelationalQueryResult<SQLiteTable, SQLiteColumn> {\n\t\tlet selection: V1.BuildRelationalQueryResult<SQLiteTable, SQLiteColumn>['selection'] = [];\n\t\tlet limit, offset, orderBy: SQLiteSelectConfig['orderBy'] = [], where;\n\t\tconst joins: SQLiteSelectJoinConfig[] = [];\n\n\t\tif (config === true) {\n\t\t\tconst selectionEntries = Object.entries(tableConfig.columns);\n\t\t\tselection = selectionEntries.map((\n\t\t\t\t[key, value],\n\t\t\t) => ({\n\t\t\t\tdbKey: value.name,\n\t\t\t\ttsKey: key,\n\t\t\t\tfield: aliasedTableColumn(value as SQLiteColumn, tableAlias),\n\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\tisJson: false,\n\t\t\t\tselection: [],\n\t\t\t}));\n\t\t} else {\n\t\t\tconst aliasedColumns = Object.fromEntries(\n\t\t\t\tObject.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),\n\t\t\t);\n\n\t\t\tif (config.where) {\n\t\t\t\tconst whereSql = typeof config.where === 'function'\n\t\t\t\t\t? config.where(aliasedColumns, V1.getOperators())\n\t\t\t\t\t: config.where;\n\t\t\t\twhere = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);\n\t\t\t}\n\n\t\t\tconst fieldsSelection: { tsKey: string; value: SQLiteColumn | SQL.Aliased }[] = [];\n\t\t\tlet selectedColumns: string[] = [];\n\n\t\t\t// Figure out which columns to select\n\t\t\tif (config.columns) {\n\t\t\t\tlet isIncludeMode = false;\n\n\t\t\t\tfor (const [field, value] of Object.entries(config.columns)) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field in tableConfig.columns) {\n\t\t\t\t\t\tif (!isIncludeMode && value === true) {\n\t\t\t\t\t\t\tisIncludeMode = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tselectedColumns.push(field);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (selectedColumns.length > 0) {\n\t\t\t\t\tselectedColumns = isIncludeMode\n\t\t\t\t\t\t? selectedColumns.filter((c) => config.columns?.[c] === true)\n\t\t\t\t\t\t: Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Select all columns if selection is not specified\n\t\t\t\tselectedColumns = Object.keys(tableConfig.columns);\n\t\t\t}\n\n\t\t\tfor (const field of selectedColumns) {\n\t\t\t\tconst column = tableConfig.columns[field]! as SQLiteColumn;\n\t\t\t\tfieldsSelection.push({ tsKey: field, value: column });\n\t\t\t}\n\n\t\t\tlet selectedRelations: {\n\t\t\t\ttsKey: string;\n\t\t\t\tqueryConfig: true | V1.DBQueryConfig<'many', false>;\n\t\t\t\trelation: V1.Relation;\n\t\t\t}[] = [];\n\n\t\t\t// Figure out which relations to select\n\t\t\tif (config.with) {\n\t\t\t\tselectedRelations = Object.entries(config.with)\n\t\t\t\t\t.filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])\n\t\t\t\t\t.map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));\n\t\t\t}\n\n\t\t\tlet extras;\n\n\t\t\t// Figure out which extras to select\n\t\t\tif (config.extras) {\n\t\t\t\textras = typeof config.extras === 'function'\n\t\t\t\t\t? config.extras(aliasedColumns, { sql })\n\t\t\t\t\t: config.extras;\n\t\t\t\tfor (const [tsKey, value] of Object.entries(extras)) {\n\t\t\t\t\tfieldsSelection.push({\n\t\t\t\t\t\ttsKey,\n\t\t\t\t\t\tvalue: mapColumnsInAliasedSQLToAlias(value, tableAlias),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Transform `fieldsSelection` into `selection`\n\t\t\t// `fieldsSelection` shouldn't be used after this point\n\t\t\tfor (const { tsKey, value } of fieldsSelection) {\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,\n\t\t\t\t\ttsKey,\n\t\t\t\t\tfield: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,\n\t\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\t\tisJson: false,\n\t\t\t\t\tselection: [],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet orderByOrig = typeof config.orderBy === 'function'\n\t\t\t\t? config.orderBy(aliasedColumns, V1.getOrderByOperators())\n\t\t\t\t: config.orderBy ?? [];\n\t\t\tif (!Array.isArray(orderByOrig)) {\n\t\t\t\torderByOrig = [orderByOrig];\n\t\t\t}\n\t\t\torderBy = orderByOrig.map((orderByValue) => {\n\t\t\t\tif (is(orderByValue, Column)) {\n\t\t\t\t\treturn aliasedTableColumn(orderByValue, tableAlias) as SQLiteColumn;\n\t\t\t\t}\n\t\t\t\treturn mapColumnsInSQLToAlias(orderByValue, tableAlias);\n\t\t\t});\n\n\t\t\tlimit = config.limit;\n\t\t\toffset = config.offset;\n\n\t\t\t// Process all relations\n\t\t\tfor (\n\t\t\t\tconst {\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tqueryConfig: selectedRelationConfigValue,\n\t\t\t\t\trelation,\n\t\t\t\t} of selectedRelations\n\t\t\t) {\n\t\t\t\tconst normalizedRelation = V1.normalizeRelation(schema, tableNamesMap, relation);\n\t\t\t\tconst relationTableName = getTableUniqueName(relation.referencedTable);\n\t\t\t\tconst relationTableTsName = tableNamesMap[relationTableName]!;\n\t\t\t\tconst relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;\n\t\t\t\t// const relationTable = schema[relationTableTsName]!;\n\t\t\t\tconst joinOn = and(\n\t\t\t\t\t...normalizedRelation.fields.map((field, i) =>\n\t\t\t\t\t\teq(\n\t\t\t\t\t\t\taliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),\n\t\t\t\t\t\t\taliasedTableColumn(field, tableAlias),\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tconst builtRelation = this._buildRelationalQuery({\n\t\t\t\t\tfullSchema,\n\t\t\t\t\tschema,\n\t\t\t\t\ttableNamesMap,\n\t\t\t\t\ttable: fullSchema[relationTableTsName] as SQLiteTable,\n\t\t\t\t\ttableConfig: schema[relationTableTsName]!,\n\t\t\t\t\tqueryConfig: is(relation, V1.One)\n\t\t\t\t\t\t? (selectedRelationConfigValue === true\n\t\t\t\t\t\t\t? { limit: 1 }\n\t\t\t\t\t\t\t: { ...selectedRelationConfigValue, limit: 1 })\n\t\t\t\t\t\t: selectedRelationConfigValue,\n\t\t\t\t\ttableAlias: relationTableAlias,\n\t\t\t\t\tjoinOn,\n\t\t\t\t\tnestedQueryRelation: relation,\n\t\t\t\t});\n\t\t\t\tconst field = (sql`(${builtRelation.sql})`).as(selectedRelationTsKey);\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: selectedRelationTsKey,\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tfield,\n\t\t\t\t\trelationTableTsKey: relationTableTsName,\n\t\t\t\t\tisJson: true,\n\t\t\t\t\tselection: builtRelation.selection,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (selection.length === 0) {\n\t\t\tthrow new DrizzleError({\n\t\t\t\tmessage:\n\t\t\t\t\t`No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\"). You need to have at least one item in \"columns\", \"with\" or \"extras\". If you need to select all columns, omit the \"columns\" key or set it to undefined.`,\n\t\t\t});\n\t\t}\n\n\t\tlet result;\n\n\t\twhere = and(joinOn, where);\n\n\t\tif (nestedQueryRelation) {\n\t\t\tlet field = sql`json_array(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field }) =>\n\t\t\t\t\t\tis(field, SQLiteColumn)\n\t\t\t\t\t\t\t? sql.identifier(this.casing.getColumnCasing(field))\n\t\t\t\t\t\t\t: is(field, SQL.Aliased)\n\t\t\t\t\t\t\t? field.sql\n\t\t\t\t\t\t\t: field\n\t\t\t\t\t),\n\t\t\t\t\tsql`, `,\n\t\t\t\t)\n\t\t\t})`;\n\t\t\tif (is(nestedQueryRelation, V1.Many)) {\n\t\t\t\tfield = sql`coalesce(json_group_array(${field}), json_array())`;\n\t\t\t}\n\t\t\tconst nestedSelection = [{\n\t\t\t\tdbKey: 'data',\n\t\t\t\ttsKey: 'data',\n\t\t\t\tfield: field.as('data'),\n\t\t\t\tisJson: true,\n\t\t\t\trelationTableTsKey: tableConfig.tsName,\n\t\t\t\tselection,\n\t\t\t}];\n\n\t\t\tconst needsSubquery = limit !== undefined || offset !== undefined || orderBy.length > 0;\n\n\t\t\tif (needsSubquery) {\n\t\t\t\tresult = this.buildSelectQuery({\n\t\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\t\tfields: {},\n\t\t\t\t\tfieldsFlat: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\tfield: sql.raw('*'),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\twhere,\n\t\t\t\t\tlimit,\n\t\t\t\t\toffset,\n\t\t\t\t\torderBy,\n\t\t\t\t\tsetOperators: [],\n\t\t\t\t});\n\n\t\t\t\twhere = undefined;\n\t\t\t\tlimit = undefined;\n\t\t\t\toffset = undefined;\n\t\t\t\torderBy = undefined;\n\t\t\t} else {\n\t\t\t\tresult = aliasedTable(table, tableAlias);\n\t\t\t}\n\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: is(result, SQLiteTable) ? result : new Subquery(result, {}, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: nestedSelection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t} else {\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: selection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttableTsKey: tableConfig.tsName,\n\t\t\tsql: result,\n\t\t\tselection,\n\t\t};\n\t}\n\n\tprivate nestedSelectionerror() {\n\t\tthrow new DrizzleError({\n\t\t\tmessage: `Views with nested selections are not supported by the relational query builder`,\n\t\t});\n\t}\n\n\tprivate buildRqbColumn(table: Table | View, column: unknown, key: string) {\n\t\tif (is(column, Column)) {\n\t\t\tconst name = sql`${table}.${sql.identifier(this.casing.getColumnCasing(column))}`;\n\n\t\t\tswitch (column.columnType) {\n\t\t\t\tcase 'SQLiteBigInt':\n\t\t\t\tcase 'SQLiteBlobJson':\n\t\t\t\tcase 'SQLiteBlobBuffer': {\n\t\t\t\t\treturn sql`hex(${name}) as ${sql.identifier(key)}`;\n\t\t\t\t}\n\n\t\t\t\tcase 'SQLiteNumeric':\n\t\t\t\tcase 'SQLiteNumericNumber':\n\t\t\t\tcase 'SQLiteNumericBigInt': {\n\t\t\t\t\treturn sql`cast(${name} as text) as ${sql.identifier(key)}`;\n\t\t\t\t}\n\n\t\t\t\tcase 'SQLiteCustomColumn': {\n\t\t\t\t\treturn sql`${(<SQLiteCustomColumn<any>> column).jsonWrapName(name, sql)} as ${sql.identifier(key)}`;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn sql`${name} as ${sql.identifier(key)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn sql`${table}.${\n\t\t\tis(column, SQL.Aliased)\n\t\t\t\t? sql.identifier(column.fieldAlias)\n\t\t\t\t: isSQLWrapper(column)\n\t\t\t\t? sql.identifier(key)\n\t\t\t\t: this.nestedSelectionerror()\n\t\t} as ${sql.identifier(key)}`;\n\t}\n\n\tprivate unwrapAllColumns = (table: Table | View, selection: BuildRelationalQueryResult['selection']) => {\n\t\treturn sql.join(\n\t\t\tObject.entries(table[Columns]).map(([k, v]) => {\n\t\t\t\tselection.push({\n\t\t\t\t\tkey: k,\n\t\t\t\t\tfield: v as Column | SQL | SQLWrapper | SQL.Aliased,\n\t\t\t\t});\n\n\t\t\t\treturn this.buildRqbColumn(table, v, k);\n\t\t\t}),\n\t\t\tsql`, `,\n\t\t);\n\t};\n\n\tprivate getSelectedTableColumns = (table: Table | View, columns: Record<string, boolean | undefined>) => {\n\t\tconst selectedColumns: ColumnWithTSName[] = [];\n\t\tconst columnContainer = table[Columns];\n\t\tconst entries = Object.entries(columns);\n\n\t\tlet colSelectionMode: boolean | undefined;\n\t\tfor (const [k, v] of entries) {\n\t\t\tif (v === undefined) continue;\n\t\t\tcolSelectionMode = colSelectionMode || v;\n\n\t\t\tif (v) {\n\t\t\t\tconst column = columnContainer[k]!;\n\n\t\t\t\tselectedColumns.push({\n\t\t\t\t\tcolumn: column as Column | SQL | SQLWrapper | SQL.Aliased,\n\t\t\t\t\ttsName: k,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (colSelectionMode === false) {\n\t\t\tfor (const [k, v] of Object.entries(columnContainer)) {\n\t\t\t\tif (columns[k] === false) continue;\n\n\t\t\t\tselectedColumns.push({\n\t\t\t\t\tcolumn: v as Column | SQL | SQLWrapper | SQL.Aliased | Table,\n\t\t\t\t\ttsName: k,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn selectedColumns;\n\t};\n\n\tprivate buildColumns = (\n\t\ttable: SQLiteTable | SQLiteView,\n\t\tselection: BuildRelationalQueryResult['selection'],\n\t\tparams?: DBQueryConfig<'many'>,\n\t) =>\n\t\tparams?.columns\n\t\t\t? (() => {\n\t\t\t\tconst columnIdentifiers: SQL[] = [];\n\n\t\t\t\tconst selectedColumns = this.getSelectedTableColumns(table, params?.columns);\n\n\t\t\t\tfor (const { column, tsName } of selectedColumns) {\n\t\t\t\t\tcolumnIdentifiers.push(this.buildRqbColumn(table, column, tsName));\n\t\t\t\t\tselection.push({\n\t\t\t\t\t\tkey: tsName,\n\t\t\t\t\t\tfield: column,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn columnIdentifiers.length\n\t\t\t\t\t? sql.join(columnIdentifiers, sql`, `)\n\t\t\t\t\t: undefined;\n\t\t\t})()\n\t\t\t: this.unwrapAllColumns(table, selection);\n\n\tbuildRelationalQuery(\n\t\t{\n\t\t\ttables,\n\t\t\tschema,\n\t\t\ttableNamesMap,\n\t\t\ttable,\n\t\t\ttableConfig,\n\t\t\tqueryConfig: config,\n\t\t\trelationWhere,\n\t\t\tmode,\n\t\t\tisNested,\n\t\t\terrorPath,\n\t\t\tdepth,\n\t\t\tthroughJoin,\n\t\t\tjsonb,\n\t\t}: {\n\t\t\ttables: Record<string, SQLiteTable | SQLiteView>;\n\t\t\tschema: TablesRelationalConfig;\n\t\t\ttableNamesMap: Record<string, string>;\n\t\t\ttable: SQLiteTable | SQLiteView;\n\t\t\ttableConfig: TableRelationalConfig;\n\t\t\tqueryConfig?: DBQueryConfig<'many'> | true;\n\t\t\trelationWhere?: SQL;\n\t\t\tmode: 'first' | 'many';\n\t\t\tisNested?: boolean;\n\t\t\terrorPath?: string;\n\t\t\tdepth?: number;\n\t\t\tthroughJoin?: SQL;\n\t\t\tjsonb: SQL;\n\t\t},\n\t): BuildRelationalQueryResult {\n\t\tconst selection: BuildRelationalQueryResult['selection'] = [];\n\t\tconst isSingle = mode === 'first';\n\t\tconst params = config === true ? undefined : config;\n\t\tconst currentPath = errorPath ?? '';\n\t\tconst currentDepth = depth ?? 0;\n\t\tif (!currentDepth) table = aliasedTable(table, `d${currentDepth}`);\n\n\t\tconst limit = isSingle ? 1 : params?.limit;\n\t\tconst offset = params?.offset;\n\n\t\tconst columns = this.buildColumns(table, selection, params);\n\n\t\tconst where: SQL | undefined = (params?.where && relationWhere)\n\t\t\t? and(\n\t\t\t\trelationsFilterToSQL(table, params.where, tableConfig.relations, schema, tableNamesMap, this.casing),\n\t\t\t\trelationWhere,\n\t\t\t)\n\t\t\t: params?.where\n\t\t\t? relationsFilterToSQL(table, params.where, tableConfig.relations, schema, tableNamesMap, this.casing)\n\t\t\t: relationWhere;\n\t\tconst order = params?.orderBy ? relationsOrderToSQL(table, params.orderBy) : undefined;\n\t\tconst extras = params?.extras ? relationExtrasToSQL(table, params.extras) : undefined;\n\t\tif (extras) selection.push(...extras.selection);\n\n\t\tconst joins = params\n\t\t\t? (() => {\n\t\t\t\tconst { with: joins } = params as WithContainer;\n\t\t\t\tif (!joins) return;\n\n\t\t\t\tconst withEntries = Object.entries(joins).filter(([_, v]) => v);\n\t\t\t\tif (!withEntries.length) return;\n\n\t\t\t\treturn sql.join(\n\t\t\t\t\twithEntries.map(([k, join]) => {\n\t\t\t\t\t\t// if (is(tableConfig.relations[k]!, AggregatedField)) {\n\t\t\t\t\t\t// \tconst relation = tableConfig.relations[k]!;\n\n\t\t\t\t\t\t// \trelation.onTable(table);\n\t\t\t\t\t\t// \tconst query = relation.getSQL();\n\n\t\t\t\t\t\t// \tselection.push({\n\t\t\t\t\t\t// \t\tkey: k,\n\t\t\t\t\t\t// \t\tfield: relation,\n\t\t\t\t\t\t// \t});\n\n\t\t\t\t\t\t// \treturn sql`(${query}) as ${sql.identifier(k)}`;\n\t\t\t\t\t\t// }\n\n\t\t\t\t\t\tconst relation = tableConfig.relations[k]! as Relation;\n\t\t\t\t\t\tconst isSingle = is(relation, One);\n\t\t\t\t\t\tconst targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);\n\t\t\t\t\t\tconst throughTable = relation.throughTable\n\t\t\t\t\t\t\t? aliasedTable(relation.throughTable, `tr${currentDepth}`)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tconst { filter, joinCondition } = relationToSQL(\n\t\t\t\t\t\t\tthis.casing,\n\t\t\t\t\t\t\trelation,\n\t\t\t\t\t\t\ttable,\n\t\t\t\t\t\t\ttargetTable,\n\t\t\t\t\t\t\tthroughTable,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst throughJoin = throughTable\n\t\t\t\t\t\t\t? sql` inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition!}`\n\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\t\tconst innerQuery = this.buildRelationalQuery({\n\t\t\t\t\t\t\ttable: targetTable as SQLiteTable | SQLiteView,\n\t\t\t\t\t\t\tmode: isSingle ? 'first' : 'many',\n\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\tqueryConfig: join as DBQueryConfig,\n\t\t\t\t\t\t\ttableConfig: schema[tableNamesMap[getTableUniqueName(relation.targetTable)]!]!,\n\t\t\t\t\t\t\ttableNamesMap,\n\t\t\t\t\t\t\ttables,\n\t\t\t\t\t\t\trelationWhere: filter,\n\t\t\t\t\t\t\tisNested: true,\n\t\t\t\t\t\t\terrorPath: `${currentPath.length ? `${currentPath}.` : ''}${k}`,\n\t\t\t\t\t\t\tdepth: currentDepth + 1,\n\t\t\t\t\t\t\tthroughJoin,\n\t\t\t\t\t\t\tjsonb,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tselection.push({\n\t\t\t\t\t\t\tfield: targetTable,\n\t\t\t\t\t\t\tkey: k,\n\t\t\t\t\t\t\tselection: innerQuery.selection,\n\t\t\t\t\t\t\tisArray: !isSingle,\n\t\t\t\t\t\t\tisOptional: ((relation as One<any, any>).optional ?? false)\n\t\t\t\t\t\t\t\t|| (join !== true && !!(join as Exclude<typeof join, boolean | undefined>).where),\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tconst jsonColumns = sql.join(\n\t\t\t\t\t\t\tinnerQuery.selection.map((s) => {\n\t\t\t\t\t\t\t\treturn sql`${sql.raw(this.escapeString(s.key))}, ${\n\t\t\t\t\t\t\t\t\ts.selection ? sql`${jsonb}(${sql.identifier(s.key)})` : sql.identifier(s.key)\n\t\t\t\t\t\t\t\t}`;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tsql`, `,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst json = isNested ? jsonb : sql`json`;\n\n\t\t\t\t\t\tconst joinQuery = isSingle\n\t\t\t\t\t\t\t? sql`(select ${json}_object(${jsonColumns}) as ${sql.identifier('r')} from (${innerQuery.sql}) as ${\n\t\t\t\t\t\t\t\tsql.identifier('t')\n\t\t\t\t\t\t\t}) as ${sql.identifier(k)}`\n\t\t\t\t\t\t\t: sql`coalesce((select ${json}_group_array(json_object(${jsonColumns})) as ${\n\t\t\t\t\t\t\t\tsql.identifier('r')\n\t\t\t\t\t\t\t} from (${innerQuery.sql}) as ${sql.identifier('t')}), ${jsonb}_array()) as ${sql.identifier(k)}`;\n\n\t\t\t\t\t\treturn joinQuery;\n\t\t\t\t\t}),\n\t\t\t\t\tsql`, `,\n\t\t\t\t);\n\t\t\t})()\n\t\t\t: undefined;\n\n\t\tconst selectionArr = [columns, extras?.sql, joins].filter((e) => e !== undefined);\n\t\tif (!selectionArr.length) {\n\t\t\tthrow new DrizzleError({\n\t\t\t\tmessage: `No fields selected for table \"${tableConfig.tsName}\"${currentPath ? ` (\"${currentPath}\")` : ''}`,\n\t\t\t});\n\t\t}\n\t\tconst selectionSet = sql.join(selectionArr, sql`, `);\n\n\t\tconst query = sql`select ${selectionSet} from ${getTableAsAliasSQL(table)}${throughJoin}${\n\t\t\tsql` where ${where}`.if(where)\n\t\t}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== undefined)}${\n\t\t\tsql` offset ${offset}`.if(offset !== undefined)\n\t\t}`;\n\n\t\treturn {\n\t\t\tsql: query,\n\t\t\tselection,\n\t\t};\n\t}\n}\n\nexport class SQLiteSyncDialect extends SQLiteDialect {\n\tstatic override readonly [entityKind]: string = 'SQLiteSyncDialect';\n\n\tmigrate(\n\t\tmigrations: MigrationMeta[],\n\t\tsession: SQLiteSession<\n\t\t\t'sync',\n\t\t\tunknown,\n\t\t\tRecord<string, unknown>,\n\t\t\tAnyRelations,\n\t\t\tTablesRelationalConfig,\n\t\t\tV1.TablesRelationalConfig\n\t\t>,\n\t\tconfig?: string | MigrationConfig,\n\t): void {\n\t\tconst migrationsTable = config === undefined\n\t\t\t? '__drizzle_migrations'\n\t\t\t: typeof config === 'string'\n\t\t\t? '__drizzle_migrations'\n\t\t\t: config.migrationsTable ?? '__drizzle_migrations';\n\n\t\tconst migrationTableCreate = sql`\n\t\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\t\tid SERIAL PRIMARY KEY,\n\t\t\t\thash text NOT NULL,\n\t\t\t\tcreated_at numeric\n\t\t\t)\n\t\t`;\n\t\tsession.run(migrationTableCreate);\n\n\t\tconst dbMigrations = session.values<[number, string, string]>(\n\t\t\tsql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`,\n\t\t);\n\n\t\tconst lastDbMigration = dbMigrations[0] ?? undefined;\n\t\tsession.run(sql`BEGIN`);\n\n\t\ttry {\n\t\t\tfor (const migration of migrations) {\n\t\t\t\tif (!lastDbMigration || Number(lastDbMigration[2])! < migration.folderMillis) {\n\t\t\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\t\t\tsession.run(sql.raw(stmt));\n\t\t\t\t\t}\n\t\t\t\t\tsession.run(\n\t\t\t\t\t\tsql`INSERT INTO ${\n\t\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t\t} (\"hash\", \"created_at\") VALUES(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsession.run(sql`COMMIT`);\n\t\t} catch (e) {\n\t\t\tsession.run(sql`ROLLBACK`);\n\t\t\tthrow e;\n\t\t}\n\t}\n}\n\nexport class SQLiteAsyncDialect extends SQLiteDialect {\n\tstatic override readonly [entityKind]: string = 'SQLiteAsyncDialect';\n\n\tasync migrate(\n\t\tmigrations: MigrationMeta[],\n\t\tsession: SQLiteSession<\n\t\t\t'async',\n\t\t\tunknown,\n\t\t\tRecord<string, unknown>,\n\t\t\tAnyRelations,\n\t\t\tTablesRelationalConfig,\n\t\t\tV1.TablesRelationalConfig\n\t\t>,\n\t\tconfig?: string | MigrationConfig,\n\t): Promise<void> {\n\t\tconst migrationsTable = config === undefined\n\t\t\t? '__drizzle_migrations'\n\t\t\t: typeof config === 'string'\n\t\t\t? '__drizzle_migrations'\n\t\t\t: config.migrationsTable ?? '__drizzle_migrations';\n\n\t\tconst migrationTableCreate = sql`\n\t\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\t\tid SERIAL PRIMARY KEY,\n\t\t\t\thash text NOT NULL,\n\t\t\t\tcreated_at numeric\n\t\t\t)\n\t\t`;\n\t\tawait session.run(migrationTableCreate);\n\n\t\tconst dbMigrations = await session.values<[number, string, string]>(\n\t\t\tsql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`,\n\t\t);\n\n\t\tconst lastDbMigration = dbMigrations[0] ?? undefined;\n\n\t\tawait session.transaction(async (tx) => {\n\t\t\tfor (const migration of migrations) {\n\t\t\t\tif (!lastDbMigration || Number(lastDbMigration[2])! < migration.folderMillis) {\n\t\t\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\t\t\tawait tx.run(sql.raw(stmt));\n\t\t\t\t\t}\n\t\t\t\t\tawait tx.run(\n\t\t\t\t\t\tsql`INSERT INTO ${\n\t\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t\t} (\"hash\", \"created_at\") VALUES(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,mBAAwG;AACxG,oBAA4B;AAE5B,oBAAuB;AACvB,oBAA+B;AAC/B,oBAA6B;AAE7B,uBAgBO;AAEP,iBAAsC;AACtC,IAAAA,cAAsE;AACtE,qBAAsD;AAOtD,mBAA4B;AAC5B,sBAAyB;AACzB,IAAAC,gBAAiE;AACjE,mBAAiE;AACjE,yBAA+B;AAO/B,uBAA+B;AAOxB,MAAe,cAAc;AAAA,EACnC,QAAiB,wBAAU,IAAY;AAAA;AAAA,EAG9B;AAAA,EAET,YAAY,QAA8B;AACzC,SAAK,SAAS,IAAI,0BAAY,QAAQ,MAAM;AAAA,EAC7C;AAAA,EAEA,WAAW,MAAsB;AAChC,WAAO,IAAI,IAAI;AAAA,EAChB;AAAA,EAEA,YAAY,MAAsB;AACjC,WAAO;AAAA,EACR;AAAA,EAEA,aAAa,KAAqB;AACjC,WAAO,IAAI,IAAI,QAAQ,MAAM,IAAI,CAAC;AAAA,EACnC;AAAA,EAEQ,aAAa,SAAkD;AACtE,QAAI,CAAC,SAAS;AAAQ,aAAO;AAE7B,UAAM,gBAAgB,CAAC,sBAAU;AACjC,eAAW,CAAC,GAAG,CAAC,KAAK,QAAQ,QAAQ,GAAG;AACvC,oBAAc,K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]}
|
package/sqlite-core/dialect.js
CHANGED
|
@@ -592,6 +592,9 @@ class SQLiteDialect {
|
|
|
592
592
|
case "SQLiteNumericBigInt": {
|
|
593
593
|
return sql`cast(${name} as text) as ${sql.identifier(key)}`;
|
|
594
594
|
}
|
|
595
|
+
case "SQLiteCustomColumn": {
|
|
596
|
+
return sql`${column.jsonWrapName(name, sql)} as ${sql.identifier(key)}`;
|
|
597
|
+
}
|
|
595
598
|
default: {
|
|
596
599
|
return sql`${name} as ${sql.identifier(key)}`;
|
|
597
600
|
}
|