drizzle-orm 0.28.7-d3fbe4a → 0.29.0-9091d23
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/{alias-cf8e03cd.mjs → alias-aa343af5.cjs} +965 -945
- package/alias-aa343af5.cjs.map +1 -0
- package/{index-1899b9ae.cjs → alias-f3b5fd3d.mjs} +1328 -2821
- package/alias-f3b5fd3d.mjs.map +1 -0
- package/alias.d.cts +1 -1
- package/alias.d.mts +1 -1
- package/alias.d.ts +1 -1
- package/aws-data-api/pg/index.cjs +33 -23
- package/aws-data-api/pg/index.cjs.map +1 -1
- package/aws-data-api/pg/index.mjs +2 -2
- package/batch.d.cts +5 -7
- package/batch.d.mts +5 -7
- package/batch.d.ts +5 -7
- package/better-sqlite3/index.cjs +32 -30
- package/better-sqlite3/index.cjs.map +1 -1
- package/better-sqlite3/index.mjs +15 -19
- package/better-sqlite3/index.mjs.map +1 -1
- package/better-sqlite3/session.d.cts +2 -4
- package/better-sqlite3/session.d.mts +2 -4
- package/better-sqlite3/session.d.ts +2 -4
- package/bun-sqlite/index.cjs +32 -30
- package/bun-sqlite/index.cjs.map +1 -1
- package/bun-sqlite/index.mjs +15 -19
- package/bun-sqlite/index.mjs.map +1 -1
- package/bun-sqlite/session.d.cts +2 -4
- package/bun-sqlite/session.d.mts +2 -4
- package/bun-sqlite/session.d.ts +2 -4
- package/d1/driver.d.cts +3 -3
- package/d1/driver.d.mts +3 -3
- package/d1/driver.d.ts +3 -3
- package/d1/index.cjs +182 -107
- package/d1/index.cjs.map +1 -1
- package/d1/index.mjs +158 -93
- package/d1/index.mjs.map +1 -1
- package/d1/session.d.cts +11 -8
- package/d1/session.d.mts +11 -8
- package/d1/session.d.ts +11 -8
- package/errors.d.cts +4 -2
- package/errors.d.mts +4 -2
- package/errors.d.ts +4 -2
- package/index.cjs +132 -102
- package/index.cjs.map +1 -1
- package/index.d.cts +1 -0
- package/index.d.mts +1 -0
- package/index.d.ts +1 -0
- package/index.mjs +2 -2
- package/libsql/driver.d.cts +2 -2
- package/libsql/driver.d.mts +2 -2
- package/libsql/driver.d.ts +2 -2
- package/libsql/index.cjs +95 -103
- package/libsql/index.cjs.map +1 -1
- package/libsql/index.mjs +78 -95
- package/libsql/index.mjs.map +1 -1
- package/libsql/session.d.cts +13 -8
- package/libsql/session.d.mts +13 -8
- package/libsql/session.d.ts +13 -8
- package/mysql-core/columns/bigint.d.cts +15 -6
- package/mysql-core/columns/bigint.d.mts +15 -6
- package/mysql-core/columns/bigint.d.ts +15 -6
- package/mysql-core/columns/int.d.cts +7 -4
- package/mysql-core/columns/int.d.mts +7 -4
- package/mysql-core/columns/int.d.ts +7 -4
- package/mysql-core/columns/mediumint.d.cts +5 -4
- package/mysql-core/columns/mediumint.d.mts +5 -4
- package/mysql-core/columns/mediumint.d.ts +5 -4
- package/mysql-core/columns/smallint.d.cts +5 -4
- package/mysql-core/columns/smallint.d.mts +5 -4
- package/mysql-core/columns/smallint.d.ts +5 -4
- package/mysql-core/columns/tinyint.d.cts +5 -4
- package/mysql-core/columns/tinyint.d.mts +5 -4
- package/mysql-core/columns/tinyint.d.ts +5 -4
- package/mysql-core/db.d.cts +3 -3
- package/mysql-core/db.d.mts +3 -3
- package/mysql-core/db.d.ts +3 -3
- package/mysql-core/foreign-keys.d.cts +3 -0
- package/mysql-core/foreign-keys.d.mts +3 -0
- package/mysql-core/foreign-keys.d.ts +3 -0
- package/mysql-core/index.cjs +950 -173
- package/mysql-core/index.cjs.map +1 -1
- package/mysql-core/index.d.cts +1 -0
- package/mysql-core/index.d.mts +1 -0
- package/mysql-core/index.d.ts +1 -0
- package/mysql-core/index.mjs +46 -31
- package/mysql-core/index.mjs.map +1 -1
- package/mysql-core/primary-keys.d.cts +15 -2
- package/mysql-core/primary-keys.d.mts +15 -2
- package/mysql-core/primary-keys.d.ts +15 -2
- package/mysql-core/query-builders/delete.d.cts +22 -13
- package/mysql-core/query-builders/delete.d.mts +22 -13
- package/mysql-core/query-builders/delete.d.ts +22 -13
- package/mysql-core/query-builders/insert.d.cts +27 -19
- package/mysql-core/query-builders/insert.d.mts +27 -19
- package/mysql-core/query-builders/insert.d.ts +27 -19
- package/mysql-core/query-builders/query-builder.d.cts +1 -1
- package/mysql-core/query-builders/query-builder.d.mts +1 -1
- package/mysql-core/query-builders/query-builder.d.ts +1 -1
- package/mysql-core/query-builders/query.d.cts +5 -5
- package/mysql-core/query-builders/query.d.mts +5 -5
- package/mysql-core/query-builders/query.d.ts +5 -5
- package/mysql-core/query-builders/select.d.cts +31 -34
- package/mysql-core/query-builders/select.d.mts +31 -34
- package/mysql-core/query-builders/select.d.ts +31 -34
- package/mysql-core/query-builders/select.types.d.cts +30 -11
- package/mysql-core/query-builders/select.types.d.mts +30 -11
- package/mysql-core/query-builders/select.types.d.ts +30 -11
- package/mysql-core/query-builders/update.d.cts +25 -16
- package/mysql-core/query-builders/update.d.mts +25 -16
- package/mysql-core/query-builders/update.d.ts +25 -16
- package/mysql-core/session.d.cts +3 -0
- package/mysql-core/session.d.mts +3 -0
- package/mysql-core/session.d.ts +3 -0
- package/mysql-core/subquery.d.cts +2 -3
- package/mysql-core/subquery.d.mts +2 -3
- package/mysql-core/subquery.d.ts +2 -3
- package/mysql-core/view-common.d.cts +1 -0
- package/mysql-core/view-common.d.mts +1 -0
- package/mysql-core/view-common.d.ts +1 -0
- package/mysql-core/view.d.cts +1 -1
- package/mysql-core/view.d.mts +1 -1
- package/mysql-core/view.d.ts +1 -1
- package/mysql2/index.cjs +44 -32
- package/mysql2/index.cjs.map +1 -1
- package/mysql2/index.mjs +5 -3
- package/mysql2/index.mjs.map +1 -1
- package/neon-http/index.cjs +34 -22
- package/neon-http/index.cjs.map +1 -1
- package/neon-http/index.mjs +2 -2
- package/neon-http/migrator.cjs +7 -8
- package/neon-http/migrator.cjs.map +1 -1
- package/neon-http/migrator.mjs +1 -1
- package/neon-serverless/index.cjs +38 -28
- package/neon-serverless/index.cjs.map +1 -1
- package/neon-serverless/index.mjs +2 -2
- package/node-postgres/index.cjs +43 -33
- package/node-postgres/index.cjs.map +1 -1
- package/node-postgres/index.mjs +2 -2
- package/package.json +1 -1
- package/pg-core/columns/common.d.cts +22 -2
- package/pg-core/columns/common.d.mts +22 -2
- package/pg-core/columns/common.d.ts +22 -2
- package/pg-core/columns/index.d.cts +0 -1
- package/pg-core/columns/index.d.mts +0 -1
- package/pg-core/columns/index.d.ts +0 -1
- package/pg-core/db.d.cts +2 -2
- package/pg-core/db.d.mts +2 -2
- package/pg-core/db.d.ts +2 -2
- package/pg-core/dialect.d.cts +1 -1
- package/pg-core/dialect.d.mts +1 -1
- package/pg-core/dialect.d.ts +1 -1
- package/pg-core/foreign-keys.d.cts +3 -0
- package/pg-core/foreign-keys.d.mts +3 -0
- package/pg-core/foreign-keys.d.ts +3 -0
- package/pg-core/index.cjs +870 -159
- package/pg-core/index.cjs.map +1 -1
- package/pg-core/index.d.cts +2 -0
- package/pg-core/index.d.mts +2 -0
- package/pg-core/index.d.ts +2 -0
- package/pg-core/index.mjs +161 -4
- package/pg-core/index.mjs.map +1 -1
- package/pg-core/primary-keys.d.cts +15 -2
- package/pg-core/primary-keys.d.mts +15 -2
- package/pg-core/primary-keys.d.ts +15 -2
- package/pg-core/query-builders/delete.d.cts +23 -9
- package/pg-core/query-builders/delete.d.mts +23 -9
- package/pg-core/query-builders/delete.d.ts +23 -9
- package/pg-core/query-builders/insert.d.cts +32 -21
- package/pg-core/query-builders/insert.d.mts +32 -21
- package/pg-core/query-builders/insert.d.ts +32 -21
- package/pg-core/query-builders/select.d.cts +36 -34
- package/pg-core/query-builders/select.d.mts +36 -34
- package/pg-core/query-builders/select.d.ts +36 -34
- package/pg-core/query-builders/select.types.d.cts +33 -14
- package/pg-core/query-builders/select.types.d.mts +33 -14
- package/pg-core/query-builders/select.types.d.ts +33 -14
- package/pg-core/query-builders/update.d.cts +26 -15
- package/pg-core/query-builders/update.d.mts +26 -15
- package/pg-core/query-builders/update.d.ts +26 -15
- package/pg-core/utils/array.d.cts +3 -0
- package/pg-core/utils/array.d.mts +3 -0
- package/pg-core/utils/array.d.ts +3 -0
- package/pg-core/utils/index.d.cts +1 -0
- package/pg-core/utils/index.d.mts +1 -0
- package/pg-core/utils/index.d.ts +1 -0
- package/pg-core/utils.d.cts +0 -3
- package/pg-core/utils.d.mts +0 -3
- package/pg-core/utils.d.ts +0 -3
- package/pg-core/view-common.d.cts +1 -0
- package/pg-core/view-common.d.mts +1 -0
- package/pg-core/view-common.d.ts +1 -0
- package/pg-core/view.d.cts +1 -1
- package/pg-core/view.d.mts +1 -1
- package/pg-core/view.d.ts +1 -1
- package/planetscale-serverless/index.cjs +31 -23
- package/planetscale-serverless/index.cjs.map +1 -1
- package/planetscale-serverless/index.mjs +2 -2
- package/postgres-js/index.cjs +33 -24
- package/postgres-js/index.cjs.map +1 -1
- package/postgres-js/index.mjs +2 -2
- package/query-builders/select.types.d.cts +4 -4
- package/query-builders/select.types.d.mts +4 -4
- package/query-builders/select.types.d.ts +4 -4
- package/runnable-query.d.cts +9 -0
- package/runnable-query.d.mts +9 -0
- package/runnable-query.d.ts +9 -0
- package/{view-975e4aa4.cjs → session-433fd851.cjs} +728 -1642
- package/session-433fd851.cjs.map +1 -0
- package/{session-6ea797a6.mjs → session-603b1d82.mjs} +18 -9
- package/session-603b1d82.mjs.map +1 -0
- package/{session-90f70450.cjs → session-87c6f58b.cjs} +466 -838
- package/session-87c6f58b.cjs.map +1 -0
- package/{session-f8888c77.mjs → session-9f87fa5e.mjs} +110 -33
- package/session-9f87fa5e.mjs.map +1 -0
- package/{view-23898f21.mjs → session-cbace11a.mjs} +203 -183
- package/session-cbace11a.mjs.map +1 -0
- package/session-fa66a09c.cjs +482 -0
- package/session-fa66a09c.cjs.map +1 -0
- package/session.d.cts +5 -0
- package/session.d.mts +5 -0
- package/session.d.ts +5 -0
- package/sql/expressions/conditions.d.cts +1 -1
- package/sql/expressions/conditions.d.mts +1 -1
- package/sql/expressions/conditions.d.ts +1 -1
- package/sql/expressions/select.d.cts +1 -1
- package/sql/expressions/select.d.mts +1 -1
- package/sql/expressions/select.d.ts +1 -1
- package/sql/index.d.cts +1 -192
- package/sql/index.d.mts +1 -192
- package/sql/index.d.ts +1 -192
- package/sql/sql.d.cts +192 -0
- package/sql/sql.d.mts +192 -0
- package/sql/sql.d.ts +192 -0
- package/sql-js/index.cjs +37 -34
- package/sql-js/index.cjs.map +1 -1
- package/sql-js/index.mjs +16 -20
- package/sql-js/index.mjs.map +1 -1
- package/sql-js/session.d.cts +2 -4
- package/sql-js/session.d.mts +2 -4
- package/sql-js/session.d.ts +2 -4
- package/sqlite-core/columns/blob.d.cts +1 -1
- package/sqlite-core/columns/blob.d.mts +1 -1
- package/sqlite-core/columns/blob.d.ts +1 -1
- package/sqlite-core/db.d.cts +2 -2
- package/sqlite-core/db.d.mts +2 -2
- package/sqlite-core/db.d.ts +2 -2
- package/sqlite-core/foreign-keys.d.cts +17 -0
- package/sqlite-core/foreign-keys.d.mts +17 -0
- package/sqlite-core/foreign-keys.d.ts +17 -0
- package/sqlite-core/index.cjs +474 -59
- package/sqlite-core/index.cjs.map +1 -1
- package/sqlite-core/index.mjs +18 -10
- package/sqlite-core/index.mjs.map +1 -1
- package/sqlite-core/primary-keys.d.cts +15 -2
- package/sqlite-core/primary-keys.d.mts +15 -2
- package/sqlite-core/primary-keys.d.ts +15 -2
- package/sqlite-core/query-builders/delete.d.cts +37 -18
- package/sqlite-core/query-builders/delete.d.mts +37 -18
- package/sqlite-core/query-builders/delete.d.ts +37 -18
- package/sqlite-core/query-builders/insert.d.cts +42 -28
- package/sqlite-core/query-builders/insert.d.mts +42 -28
- package/sqlite-core/query-builders/insert.d.ts +42 -28
- package/sqlite-core/query-builders/query.d.cts +9 -4
- package/sqlite-core/query-builders/query.d.mts +9 -4
- package/sqlite-core/query-builders/query.d.ts +9 -4
- package/sqlite-core/query-builders/raw.d.cts +13 -3
- package/sqlite-core/query-builders/raw.d.mts +13 -3
- package/sqlite-core/query-builders/raw.d.ts +13 -3
- package/sqlite-core/query-builders/select.d.cts +33 -33
- package/sqlite-core/query-builders/select.d.mts +33 -33
- package/sqlite-core/query-builders/select.d.ts +33 -33
- package/sqlite-core/query-builders/select.types.d.cts +34 -9
- package/sqlite-core/query-builders/select.types.d.mts +34 -9
- package/sqlite-core/query-builders/select.types.d.ts +34 -9
- package/sqlite-core/query-builders/update.d.cts +38 -21
- package/sqlite-core/query-builders/update.d.mts +38 -21
- package/sqlite-core/query-builders/update.d.ts +38 -21
- package/sqlite-core/session.d.cts +20 -26
- package/sqlite-core/session.d.mts +20 -26
- package/sqlite-core/session.d.ts +20 -26
- package/sqlite-core/unique-constraint.d.cts +1 -1
- package/sqlite-core/unique-constraint.d.mts +1 -1
- package/sqlite-core/unique-constraint.d.ts +1 -1
- package/sqlite-core/utils.d.cts +1 -1
- package/sqlite-core/utils.d.mts +1 -1
- package/sqlite-core/utils.d.ts +1 -1
- package/sqlite-core/view-common.d.cts +1 -0
- package/sqlite-core/view-common.d.mts +1 -0
- package/sqlite-core/view-common.d.ts +1 -0
- package/sqlite-core/view.d.cts +1 -2
- package/sqlite-core/view.d.mts +1 -2
- package/sqlite-core/view.d.ts +1 -2
- package/sqlite-proxy/index.cjs +39 -38
- package/sqlite-proxy/index.cjs.map +1 -1
- package/sqlite-proxy/index.mjs +20 -24
- package/sqlite-proxy/index.mjs.map +1 -1
- package/sqlite-proxy/migrator.cjs +3 -3
- package/sqlite-proxy/migrator.mjs +1 -1
- package/sqlite-proxy/session.d.cts +4 -6
- package/sqlite-proxy/session.d.mts +4 -6
- package/sqlite-proxy/session.d.ts +4 -6
- package/table.d.cts +23 -5
- package/table.d.mts +23 -5
- package/table.d.ts +23 -5
- package/vercel-postgres/index.cjs +38 -28
- package/vercel-postgres/index.cjs.map +1 -1
- package/vercel-postgres/index.mjs +2 -2
- package/version.cjs +2 -2
- package/version.mjs +2 -2
- package/view-common.d.cts +1 -0
- package/view-common.d.mts +1 -0
- package/view-common.d.ts +1 -0
- package/view.d.cts +0 -1
- package/view.d.mts +0 -1
- package/view.d.ts +0 -1
- package/alias-cf8e03cd.mjs.map +0 -1
- package/index-1899b9ae.cjs.map +0 -1
- package/pg-core/columns/array.d.cts +0 -26
- package/pg-core/columns/array.d.mts +0 -26
- package/pg-core/columns/array.d.ts +0 -26
- package/session-6ea797a6.mjs.map +0 -1
- package/session-90f70450.cjs.map +0 -1
- package/session-f8888c77.mjs.map +0 -1
- package/view-23898f21.mjs.map +0 -1
- package/view-975e4aa4.cjs.map +0 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
1
3
|
const entityKind = Symbol.for('drizzle:entityKind');
|
|
2
4
|
const hasOwnEntityKind = Symbol.for('drizzle:hasOwnEntityKind');
|
|
3
5
|
function is(value, type) {
|
|
@@ -67,7 +69,72 @@ class Column {
|
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
/** @internal */
|
|
73
|
+
const TableName = Symbol.for('drizzle:Name');
|
|
74
|
+
/** @internal */
|
|
75
|
+
const Schema = Symbol.for('drizzle:Schema');
|
|
76
|
+
/** @internal */
|
|
77
|
+
const Columns = Symbol.for('drizzle:Columns');
|
|
78
|
+
/** @internal */
|
|
79
|
+
const OriginalName = Symbol.for('drizzle:OriginalName');
|
|
80
|
+
/** @internal */
|
|
81
|
+
const BaseName = Symbol.for('drizzle:BaseName');
|
|
82
|
+
/** @internal */
|
|
83
|
+
const IsAlias = Symbol.for('drizzle:IsAlias');
|
|
84
|
+
/** @internal */
|
|
85
|
+
const ExtraConfigBuilder = Symbol.for('drizzle:ExtraConfigBuilder');
|
|
86
|
+
const IsDrizzleTable = Symbol.for('drizzle:IsDrizzleTable');
|
|
87
|
+
class Table {
|
|
88
|
+
static [entityKind] = 'Table';
|
|
89
|
+
/** @internal */
|
|
90
|
+
static Symbol = {
|
|
91
|
+
Name: TableName,
|
|
92
|
+
Schema: Schema,
|
|
93
|
+
OriginalName: OriginalName,
|
|
94
|
+
Columns: Columns,
|
|
95
|
+
BaseName: BaseName,
|
|
96
|
+
IsAlias: IsAlias,
|
|
97
|
+
ExtraConfigBuilder: ExtraConfigBuilder,
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* @internal
|
|
101
|
+
* Can be changed if the table is aliased.
|
|
102
|
+
*/
|
|
103
|
+
[TableName];
|
|
104
|
+
/**
|
|
105
|
+
* @internal
|
|
106
|
+
* Used to store the original name of the table, before any aliasing.
|
|
107
|
+
*/
|
|
108
|
+
[OriginalName];
|
|
109
|
+
/** @internal */
|
|
110
|
+
[Schema];
|
|
111
|
+
/** @internal */
|
|
112
|
+
[Columns];
|
|
113
|
+
/**
|
|
114
|
+
* @internal
|
|
115
|
+
* Used to store the table name before the transformation via the `tableCreator` functions.
|
|
116
|
+
*/
|
|
117
|
+
[BaseName];
|
|
118
|
+
/** @internal */
|
|
119
|
+
[IsAlias] = false;
|
|
120
|
+
/** @internal */
|
|
121
|
+
[ExtraConfigBuilder] = undefined;
|
|
122
|
+
[IsDrizzleTable] = true;
|
|
123
|
+
constructor(name, schema, baseName) {
|
|
124
|
+
this[TableName] = this[OriginalName] = name;
|
|
125
|
+
this[Schema] = schema;
|
|
126
|
+
this[BaseName] = baseName;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function isTable(table) {
|
|
130
|
+
return typeof table === 'object' && table !== null && IsDrizzleTable in table;
|
|
131
|
+
}
|
|
132
|
+
function getTableName(table) {
|
|
133
|
+
return table[TableName];
|
|
134
|
+
}
|
|
135
|
+
|
|
70
136
|
const ViewBaseConfig = Symbol.for('drizzle:ViewBaseConfig');
|
|
137
|
+
|
|
71
138
|
class View {
|
|
72
139
|
static [entityKind] = 'View';
|
|
73
140
|
/** @internal */
|
|
@@ -277,73 +344,6 @@ function iife(fn, ...args) {
|
|
|
277
344
|
return fn(...args);
|
|
278
345
|
}
|
|
279
346
|
|
|
280
|
-
/** @internal */
|
|
281
|
-
const TableName = Symbol.for('drizzle:Name');
|
|
282
|
-
/** @internal */
|
|
283
|
-
const Schema = Symbol.for('drizzle:Schema');
|
|
284
|
-
/** @internal */
|
|
285
|
-
const Columns = Symbol.for('drizzle:Columns');
|
|
286
|
-
/** @internal */
|
|
287
|
-
const OriginalName = Symbol.for('drizzle:OriginalName');
|
|
288
|
-
/** @internal */
|
|
289
|
-
const BaseName = Symbol.for('drizzle:BaseName');
|
|
290
|
-
/** @internal */
|
|
291
|
-
const IsAlias = Symbol.for('drizzle:IsAlias');
|
|
292
|
-
/** @internal */
|
|
293
|
-
const ExtraConfigBuilder = Symbol.for('drizzle:ExtraConfigBuilder');
|
|
294
|
-
const IsDrizzleTable = Symbol.for('drizzle:IsDrizzleTable');
|
|
295
|
-
class Table {
|
|
296
|
-
static [entityKind] = 'Table';
|
|
297
|
-
/** @internal */
|
|
298
|
-
static Symbol = {
|
|
299
|
-
Name: TableName,
|
|
300
|
-
Schema: Schema,
|
|
301
|
-
OriginalName: OriginalName,
|
|
302
|
-
Columns: Columns,
|
|
303
|
-
BaseName: BaseName,
|
|
304
|
-
IsAlias: IsAlias,
|
|
305
|
-
ExtraConfigBuilder: ExtraConfigBuilder,
|
|
306
|
-
};
|
|
307
|
-
/**
|
|
308
|
-
* @internal
|
|
309
|
-
* Can be changed if the table is aliased.
|
|
310
|
-
*/
|
|
311
|
-
[TableName];
|
|
312
|
-
/**
|
|
313
|
-
* @internal
|
|
314
|
-
* Used to store the original name of the table, before any aliasing.
|
|
315
|
-
*/
|
|
316
|
-
[OriginalName];
|
|
317
|
-
/** @internal */
|
|
318
|
-
[Schema];
|
|
319
|
-
/** @internal */
|
|
320
|
-
[Columns];
|
|
321
|
-
/**
|
|
322
|
-
* @internal
|
|
323
|
-
* Used to store the table name before the transformation via the `tableCreator` functions.
|
|
324
|
-
*/
|
|
325
|
-
[BaseName];
|
|
326
|
-
/** @internal */
|
|
327
|
-
[IsAlias] = false;
|
|
328
|
-
/** @internal */
|
|
329
|
-
[ExtraConfigBuilder] = undefined;
|
|
330
|
-
[IsDrizzleTable] = true;
|
|
331
|
-
constructor(name, schema, baseName) {
|
|
332
|
-
this[TableName] = this[OriginalName] = name;
|
|
333
|
-
this[Schema] = schema;
|
|
334
|
-
this[BaseName] = baseName;
|
|
335
|
-
}
|
|
336
|
-
getSQL() {
|
|
337
|
-
return new SQL([this]);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
function isTable(table) {
|
|
341
|
-
return typeof table === 'object' && table !== null && IsDrizzleTable in table;
|
|
342
|
-
}
|
|
343
|
-
function getTableName(table) {
|
|
344
|
-
return table[TableName];
|
|
345
|
-
}
|
|
346
|
-
|
|
347
347
|
class QueryPromise {
|
|
348
348
|
static [entityKind] = 'QueryPromise';
|
|
349
349
|
[Symbol.toStringTag] = 'QueryPromise';
|
|
@@ -375,20 +375,96 @@ const tracer = {
|
|
|
375
375
|
|
|
376
376
|
class DrizzleError extends Error {
|
|
377
377
|
static [entityKind] = 'DrizzleError';
|
|
378
|
-
constructor(message) {
|
|
378
|
+
constructor({ message, cause }) {
|
|
379
379
|
super(message);
|
|
380
380
|
this.name = 'DrizzleError';
|
|
381
|
-
|
|
382
|
-
static wrap(error, message) {
|
|
383
|
-
return error instanceof Error // eslint-disable-line no-instanceof/no-instanceof
|
|
384
|
-
? new DrizzleError(message ? `${message}: ${error.message}` : error.message)
|
|
385
|
-
: new DrizzleError(message ?? String(error));
|
|
381
|
+
this.cause = cause;
|
|
386
382
|
}
|
|
387
383
|
}
|
|
388
384
|
class TransactionRollbackError extends DrizzleError {
|
|
389
385
|
static [entityKind] = 'TransactionRollbackError';
|
|
390
386
|
constructor() {
|
|
391
|
-
super('Rollback');
|
|
387
|
+
super({ message: 'Rollback' });
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// To understand how to use `ColumnBuilder` and `AnyColumnBuilder`, see `Column` and `AnyColumn` documentation.
|
|
392
|
+
class ColumnBuilder {
|
|
393
|
+
static [entityKind] = 'ColumnBuilder';
|
|
394
|
+
config;
|
|
395
|
+
constructor(name, dataType, columnType) {
|
|
396
|
+
this.config = {
|
|
397
|
+
name,
|
|
398
|
+
notNull: false,
|
|
399
|
+
default: undefined,
|
|
400
|
+
hasDefault: false,
|
|
401
|
+
primaryKey: false,
|
|
402
|
+
isUnique: false,
|
|
403
|
+
uniqueName: undefined,
|
|
404
|
+
uniqueType: undefined,
|
|
405
|
+
dataType,
|
|
406
|
+
columnType,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* ```ts
|
|
414
|
+
* const users = pgTable('users', {
|
|
415
|
+
* id: integer('id').$type<UserId>().primaryKey(),
|
|
416
|
+
* details: json('details').$type<UserDetails>().notNull(),
|
|
417
|
+
* });
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
$type() {
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Adds a `not null` clause to the column definition.
|
|
425
|
+
*
|
|
426
|
+
* Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
|
|
427
|
+
*/
|
|
428
|
+
notNull() {
|
|
429
|
+
this.config.notNull = true;
|
|
430
|
+
return this;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Adds a `default <value>` clause to the column definition.
|
|
434
|
+
*
|
|
435
|
+
* Affects the `insert` model of the table - columns *with* `default` are optional on insert.
|
|
436
|
+
*
|
|
437
|
+
* If you need to set a dynamic default value, use {@link $defaultFn} instead.
|
|
438
|
+
*/
|
|
439
|
+
default(value) {
|
|
440
|
+
this.config.default = value;
|
|
441
|
+
this.config.hasDefault = true;
|
|
442
|
+
return this;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Adds a dynamic default value to the column.
|
|
446
|
+
* The function will be called when the row is inserted, and the returned value will be used as the column value.
|
|
447
|
+
*
|
|
448
|
+
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
449
|
+
*/
|
|
450
|
+
$defaultFn(fn) {
|
|
451
|
+
this.config.defaultFn = fn;
|
|
452
|
+
this.config.hasDefault = true;
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Alias for {@link $defaultFn}.
|
|
457
|
+
*/
|
|
458
|
+
$default = this.$defaultFn;
|
|
459
|
+
/**
|
|
460
|
+
* Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
|
|
461
|
+
*
|
|
462
|
+
* In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
|
|
463
|
+
*/
|
|
464
|
+
primaryKey() {
|
|
465
|
+
this.config.primaryKey = true;
|
|
466
|
+
this.config.notNull = true;
|
|
467
|
+
return this;
|
|
392
468
|
}
|
|
393
469
|
}
|
|
394
470
|
|
|
@@ -430,35 +506,6 @@ function pgTableCreator(customizeTableName) {
|
|
|
430
506
|
};
|
|
431
507
|
}
|
|
432
508
|
|
|
433
|
-
class CheckBuilder {
|
|
434
|
-
name;
|
|
435
|
-
value;
|
|
436
|
-
static [entityKind] = 'PgCheckBuilder';
|
|
437
|
-
brand;
|
|
438
|
-
constructor(name, value) {
|
|
439
|
-
this.name = name;
|
|
440
|
-
this.value = value;
|
|
441
|
-
}
|
|
442
|
-
/** @internal */
|
|
443
|
-
build(table) {
|
|
444
|
-
return new Check(table, this);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
class Check {
|
|
448
|
-
table;
|
|
449
|
-
static [entityKind] = 'PgCheck';
|
|
450
|
-
name;
|
|
451
|
-
value;
|
|
452
|
-
constructor(table, builder) {
|
|
453
|
-
this.table = table;
|
|
454
|
-
this.name = builder.name;
|
|
455
|
-
this.value = builder.value;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
function check(name, value) {
|
|
459
|
-
return new CheckBuilder(name, value);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
509
|
class ForeignKeyBuilder {
|
|
463
510
|
static [entityKind] = 'PgForeignKeyBuilder';
|
|
464
511
|
/** @internal */
|
|
@@ -469,8 +516,8 @@ class ForeignKeyBuilder {
|
|
|
469
516
|
_onDelete = 'no action';
|
|
470
517
|
constructor(config, actions) {
|
|
471
518
|
this.reference = () => {
|
|
472
|
-
const { columns, foreignColumns } = config();
|
|
473
|
-
return { columns, foreignTable: foreignColumns[0].table, foreignColumns };
|
|
519
|
+
const { name, columns, foreignColumns } = config();
|
|
520
|
+
return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
|
|
474
521
|
};
|
|
475
522
|
if (actions) {
|
|
476
523
|
this._onUpdate = actions.onUpdate;
|
|
@@ -503,7 +550,7 @@ class ForeignKey {
|
|
|
503
550
|
this.onDelete = builder._onDelete;
|
|
504
551
|
}
|
|
505
552
|
getName() {
|
|
506
|
-
const { columns, foreignColumns } = this.reference();
|
|
553
|
+
const { name, columns, foreignColumns } = this.reference();
|
|
507
554
|
const columnNames = columns.map((column) => column.name);
|
|
508
555
|
const foreignColumnNames = foreignColumns.map((column) => column.name);
|
|
509
556
|
const chunks = [
|
|
@@ -512,13 +559,14 @@ class ForeignKey {
|
|
|
512
559
|
foreignColumns[0].table[PgTable.Symbol.Name],
|
|
513
560
|
...foreignColumnNames,
|
|
514
561
|
];
|
|
515
|
-
return `${chunks.join('_')}_fk`;
|
|
562
|
+
return name ?? `${chunks.join('_')}_fk`;
|
|
516
563
|
}
|
|
517
564
|
}
|
|
518
565
|
function foreignKey(config) {
|
|
519
566
|
function mappedConfig() {
|
|
520
|
-
const { columns, foreignColumns } = config;
|
|
567
|
+
const { name, columns, foreignColumns } = config;
|
|
521
568
|
return {
|
|
569
|
+
name,
|
|
522
570
|
columns,
|
|
523
571
|
foreignColumns,
|
|
524
572
|
};
|
|
@@ -526,132 +574,30 @@ function foreignKey(config) {
|
|
|
526
574
|
return new ForeignKeyBuilder(mappedConfig);
|
|
527
575
|
}
|
|
528
576
|
|
|
529
|
-
|
|
530
|
-
|
|
577
|
+
function unique(name) {
|
|
578
|
+
return new UniqueOnConstraintBuilder(name);
|
|
579
|
+
}
|
|
580
|
+
function uniqueKeyName(table, columns) {
|
|
581
|
+
return `${table[PgTable.Symbol.Name]}_${columns.join('_')}_unique`;
|
|
582
|
+
}
|
|
583
|
+
class UniqueConstraintBuilder {
|
|
531
584
|
name;
|
|
532
|
-
static [entityKind] = '
|
|
533
|
-
|
|
534
|
-
|
|
585
|
+
static [entityKind] = 'PgUniqueConstraintBuilder';
|
|
586
|
+
/** @internal */
|
|
587
|
+
columns;
|
|
588
|
+
/** @internal */
|
|
589
|
+
nullsNotDistinctConfig = false;
|
|
590
|
+
constructor(columns, name) {
|
|
535
591
|
this.name = name;
|
|
592
|
+
this.columns = columns;
|
|
536
593
|
}
|
|
537
|
-
|
|
538
|
-
|
|
594
|
+
nullsNotDistinct() {
|
|
595
|
+
this.nullsNotDistinctConfig = true;
|
|
596
|
+
return this;
|
|
539
597
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
class IndexBuilder {
|
|
545
|
-
static [entityKind] = 'PgIndexBuilder';
|
|
546
|
-
/** @internal */
|
|
547
|
-
config;
|
|
548
|
-
constructor(columns, unique, only, name) {
|
|
549
|
-
this.config = {
|
|
550
|
-
name,
|
|
551
|
-
columns,
|
|
552
|
-
unique,
|
|
553
|
-
only,
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
concurrently() {
|
|
557
|
-
this.config.concurrently = true;
|
|
558
|
-
return this;
|
|
559
|
-
}
|
|
560
|
-
using(method) {
|
|
561
|
-
this.config.using = method;
|
|
562
|
-
return this;
|
|
563
|
-
}
|
|
564
|
-
asc() {
|
|
565
|
-
this.config.order = 'asc';
|
|
566
|
-
return this;
|
|
567
|
-
}
|
|
568
|
-
desc() {
|
|
569
|
-
this.config.order = 'desc';
|
|
570
|
-
return this;
|
|
571
|
-
}
|
|
572
|
-
nullsFirst() {
|
|
573
|
-
this.config.nulls = 'first';
|
|
574
|
-
return this;
|
|
575
|
-
}
|
|
576
|
-
nullsLast() {
|
|
577
|
-
this.config.nulls = 'last';
|
|
578
|
-
return this;
|
|
579
|
-
}
|
|
580
|
-
where(condition) {
|
|
581
|
-
this.config.where = condition;
|
|
582
|
-
return this;
|
|
583
|
-
}
|
|
584
|
-
/** @internal */
|
|
585
|
-
build(table) {
|
|
586
|
-
return new Index(this.config, table);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
class Index {
|
|
590
|
-
static [entityKind] = 'PgIndex';
|
|
591
|
-
config;
|
|
592
|
-
constructor(config, table) {
|
|
593
|
-
this.config = { ...config, table };
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
function index(name) {
|
|
597
|
-
return new IndexBuilderOn(false, name);
|
|
598
|
-
}
|
|
599
|
-
function uniqueIndex(name) {
|
|
600
|
-
return new IndexBuilderOn(true, name);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
function primaryKey(...columns) {
|
|
604
|
-
return new PrimaryKeyBuilder(columns);
|
|
605
|
-
}
|
|
606
|
-
class PrimaryKeyBuilder {
|
|
607
|
-
static [entityKind] = 'PgPrimaryKeyBuilder';
|
|
608
|
-
/** @internal */
|
|
609
|
-
columns;
|
|
610
|
-
constructor(columns) {
|
|
611
|
-
this.columns = columns;
|
|
612
|
-
}
|
|
613
|
-
/** @internal */
|
|
614
|
-
build(table) {
|
|
615
|
-
return new PrimaryKey(table, this.columns);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
class PrimaryKey {
|
|
619
|
-
table;
|
|
620
|
-
static [entityKind] = 'PgPrimaryKey';
|
|
621
|
-
columns;
|
|
622
|
-
constructor(table, columns) {
|
|
623
|
-
this.table = table;
|
|
624
|
-
this.columns = columns;
|
|
625
|
-
}
|
|
626
|
-
getName() {
|
|
627
|
-
return `${this.table[PgTable.Symbol.Name]}_${this.columns.map((column) => column.name).join('_')}_pk`;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
function unique(name) {
|
|
632
|
-
return new UniqueOnConstraintBuilder(name);
|
|
633
|
-
}
|
|
634
|
-
function uniqueKeyName(table, columns) {
|
|
635
|
-
return `${table[PgTable.Symbol.Name]}_${columns.join('_')}_unique`;
|
|
636
|
-
}
|
|
637
|
-
class UniqueConstraintBuilder {
|
|
638
|
-
name;
|
|
639
|
-
static [entityKind] = 'PgUniqueConstraintBuilder';
|
|
640
|
-
/** @internal */
|
|
641
|
-
columns;
|
|
642
|
-
/** @internal */
|
|
643
|
-
nullsNotDistinctConfig = false;
|
|
644
|
-
constructor(columns, name) {
|
|
645
|
-
this.name = name;
|
|
646
|
-
this.columns = columns;
|
|
647
|
-
}
|
|
648
|
-
nullsNotDistinct() {
|
|
649
|
-
this.nullsNotDistinctConfig = true;
|
|
650
|
-
return this;
|
|
651
|
-
}
|
|
652
|
-
/** @internal */
|
|
653
|
-
build(table) {
|
|
654
|
-
return new UniqueConstraint(table, this.columns, this.nullsNotDistinctConfig, this.name);
|
|
598
|
+
/** @internal */
|
|
599
|
+
build(table) {
|
|
600
|
+
return new UniqueConstraint(table, this.columns, this.nullsNotDistinctConfig, this.name);
|
|
655
601
|
}
|
|
656
602
|
}
|
|
657
603
|
class UniqueOnConstraintBuilder {
|
|
@@ -682,59 +628,6 @@ class UniqueConstraint {
|
|
|
682
628
|
}
|
|
683
629
|
}
|
|
684
630
|
|
|
685
|
-
function getTableConfig(table) {
|
|
686
|
-
const columns = Object.values(table[Table.Symbol.Columns]);
|
|
687
|
-
const indexes = [];
|
|
688
|
-
const checks = [];
|
|
689
|
-
const primaryKeys = [];
|
|
690
|
-
const foreignKeys = Object.values(table[PgTable.Symbol.InlineForeignKeys]);
|
|
691
|
-
const uniqueConstraints = [];
|
|
692
|
-
const name = table[Table.Symbol.Name];
|
|
693
|
-
const schema = table[Table.Symbol.Schema];
|
|
694
|
-
const extraConfigBuilder = table[PgTable.Symbol.ExtraConfigBuilder];
|
|
695
|
-
if (extraConfigBuilder !== undefined) {
|
|
696
|
-
const extraConfig = extraConfigBuilder(table[Table.Symbol.Columns]);
|
|
697
|
-
for (const builder of Object.values(extraConfig)) {
|
|
698
|
-
if (is(builder, IndexBuilder)) {
|
|
699
|
-
indexes.push(builder.build(table));
|
|
700
|
-
}
|
|
701
|
-
else if (is(builder, CheckBuilder)) {
|
|
702
|
-
checks.push(builder.build(table));
|
|
703
|
-
}
|
|
704
|
-
else if (is(builder, UniqueConstraintBuilder)) {
|
|
705
|
-
uniqueConstraints.push(builder.build(table));
|
|
706
|
-
}
|
|
707
|
-
else if (is(builder, PrimaryKeyBuilder)) {
|
|
708
|
-
primaryKeys.push(builder.build(table));
|
|
709
|
-
}
|
|
710
|
-
else if (is(builder, ForeignKeyBuilder)) {
|
|
711
|
-
foreignKeys.push(builder.build(table));
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
return {
|
|
716
|
-
columns,
|
|
717
|
-
indexes,
|
|
718
|
-
foreignKeys,
|
|
719
|
-
checks,
|
|
720
|
-
primaryKeys,
|
|
721
|
-
uniqueConstraints,
|
|
722
|
-
name,
|
|
723
|
-
schema,
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
function getViewConfig(view) {
|
|
727
|
-
return {
|
|
728
|
-
...view[ViewBaseConfig],
|
|
729
|
-
...view[PgViewConfig],
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
function getMaterializedViewConfig(view) {
|
|
733
|
-
return {
|
|
734
|
-
...view[ViewBaseConfig],
|
|
735
|
-
...view[PgMaterializedViewConfig],
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
631
|
function parsePgArrayValue(arrayString, startFrom, inQuotes) {
|
|
739
632
|
for (let i = startFrom; i < arrayString.length; i++) {
|
|
740
633
|
const char = arrayString[i];
|
|
@@ -810,86 +703,6 @@ function makePgArray(array) {
|
|
|
810
703
|
}).join(',')}}`;
|
|
811
704
|
}
|
|
812
705
|
|
|
813
|
-
// To understand how to use `ColumnBuilder` and `AnyColumnBuilder`, see `Column` and `AnyColumn` documentation.
|
|
814
|
-
class ColumnBuilder {
|
|
815
|
-
static [entityKind] = 'ColumnBuilder';
|
|
816
|
-
config;
|
|
817
|
-
constructor(name, dataType, columnType) {
|
|
818
|
-
this.config = {
|
|
819
|
-
name,
|
|
820
|
-
notNull: false,
|
|
821
|
-
default: undefined,
|
|
822
|
-
hasDefault: false,
|
|
823
|
-
primaryKey: false,
|
|
824
|
-
isUnique: false,
|
|
825
|
-
uniqueName: undefined,
|
|
826
|
-
uniqueType: undefined,
|
|
827
|
-
dataType,
|
|
828
|
-
columnType,
|
|
829
|
-
};
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
|
|
833
|
-
*
|
|
834
|
-
* @example
|
|
835
|
-
* ```ts
|
|
836
|
-
* const users = pgTable('users', {
|
|
837
|
-
* id: integer('id').$type<UserId>().primaryKey(),
|
|
838
|
-
* details: json('details').$type<UserDetails>().notNull(),
|
|
839
|
-
* });
|
|
840
|
-
* ```
|
|
841
|
-
*/
|
|
842
|
-
$type() {
|
|
843
|
-
return this;
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Adds a `not null` clause to the column definition.
|
|
847
|
-
*
|
|
848
|
-
* Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
|
|
849
|
-
*/
|
|
850
|
-
notNull() {
|
|
851
|
-
this.config.notNull = true;
|
|
852
|
-
return this;
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* Adds a `default <value>` clause to the column definition.
|
|
856
|
-
*
|
|
857
|
-
* Affects the `insert` model of the table - columns *with* `default` are optional on insert.
|
|
858
|
-
*
|
|
859
|
-
* If you need to set a dynamic default value, use {@link $defaultFn} instead.
|
|
860
|
-
*/
|
|
861
|
-
default(value) {
|
|
862
|
-
this.config.default = value;
|
|
863
|
-
this.config.hasDefault = true;
|
|
864
|
-
return this;
|
|
865
|
-
}
|
|
866
|
-
/**
|
|
867
|
-
* Adds a dynamic default value to the column.
|
|
868
|
-
* The function will be called when the row is inserted, and the returned value will be used as the column value.
|
|
869
|
-
*
|
|
870
|
-
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
871
|
-
*/
|
|
872
|
-
$defaultFn(fn) {
|
|
873
|
-
this.config.defaultFn = fn;
|
|
874
|
-
this.config.hasDefault = true;
|
|
875
|
-
return this;
|
|
876
|
-
}
|
|
877
|
-
/**
|
|
878
|
-
* Alias for {@link $defaultFn}.
|
|
879
|
-
*/
|
|
880
|
-
$default = this.$defaultFn;
|
|
881
|
-
/**
|
|
882
|
-
* Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
|
|
883
|
-
*
|
|
884
|
-
* In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
|
|
885
|
-
*/
|
|
886
|
-
primaryKey() {
|
|
887
|
-
this.config.primaryKey = true;
|
|
888
|
-
this.config.notNull = true;
|
|
889
|
-
return this;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
|
|
893
706
|
class PgColumnBuilder extends ColumnBuilder {
|
|
894
707
|
foreignKeyConfigs = [];
|
|
895
708
|
static [entityKind] = 'PgColumnBuilder';
|
|
@@ -937,7 +750,6 @@ class PgColumn extends Column {
|
|
|
937
750
|
this.table = table;
|
|
938
751
|
}
|
|
939
752
|
}
|
|
940
|
-
|
|
941
753
|
class PgArrayBuilder extends PgColumnBuilder {
|
|
942
754
|
static [entityKind] = 'PgArrayBuilder';
|
|
943
755
|
constructor(name, baseBuilder, size) {
|
|
@@ -1387,7 +1199,7 @@ class PgDialect {
|
|
|
1387
1199
|
});
|
|
1388
1200
|
return sql.join(chunks);
|
|
1389
1201
|
}
|
|
1390
|
-
buildSelectQuery({ withList, fields, fieldsFlat, where, having, table, joins, orderBy, groupBy, limit, offset,
|
|
1202
|
+
buildSelectQuery({ withList, fields, fieldsFlat, where, having, table, joins, orderBy, groupBy, limit, offset, lockingClause, distinct, }) {
|
|
1391
1203
|
const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
|
|
1392
1204
|
for (const f of fieldsList) {
|
|
1393
1205
|
if (is(f.field, Column)
|
|
@@ -1475,23 +1287,21 @@ class PgDialect {
|
|
|
1475
1287
|
}
|
|
1476
1288
|
const limitSql = limit ? sql ` limit ${limit}` : undefined;
|
|
1477
1289
|
const offsetSql = offset ? sql ` offset ${offset}` : undefined;
|
|
1478
|
-
const
|
|
1479
|
-
if (
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
clauseSql.append(sql ` skip locked`);
|
|
1490
|
-
}
|
|
1491
|
-
lockingClausesSql.append(clauseSql);
|
|
1290
|
+
const lockingClauseSql = sql.empty();
|
|
1291
|
+
if (lockingClause) {
|
|
1292
|
+
const clauseSql = sql ` for ${sql.raw(lockingClause.strength)}`;
|
|
1293
|
+
if (lockingClause.config.of) {
|
|
1294
|
+
clauseSql.append(sql ` of ${sql.join(Array.isArray(lockingClause.config.of) ? lockingClause.config.of : [lockingClause.config.of], sql `, `)}`);
|
|
1295
|
+
}
|
|
1296
|
+
if (lockingClause.config.noWait) {
|
|
1297
|
+
clauseSql.append(sql ` no wait`);
|
|
1298
|
+
}
|
|
1299
|
+
else if (lockingClause.config.skipLocked) {
|
|
1300
|
+
clauseSql.append(sql ` skip locked`);
|
|
1492
1301
|
}
|
|
1302
|
+
lockingClauseSql.append(clauseSql);
|
|
1493
1303
|
}
|
|
1494
|
-
return sql `${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${
|
|
1304
|
+
return sql `${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClauseSql}`;
|
|
1495
1305
|
}
|
|
1496
1306
|
buildInsertQuery({ table, values, onConflict, returning }) {
|
|
1497
1307
|
const valuesSqlList = [];
|
|
@@ -2186,7 +1996,7 @@ class PgDialect {
|
|
|
2186
1996
|
}
|
|
2187
1997
|
}
|
|
2188
1998
|
if (selection.length === 0) {
|
|
2189
|
-
throw new DrizzleError(`No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")`);
|
|
1999
|
+
throw new DrizzleError({ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")` });
|
|
2190
2000
|
}
|
|
2191
2001
|
let result;
|
|
2192
2002
|
where = and(joinOn, where);
|
|
@@ -2295,7 +2105,7 @@ class PgSelectBuilder {
|
|
|
2295
2105
|
* Specify the table, subquery, or other target that you're
|
|
2296
2106
|
* building a select query against.
|
|
2297
2107
|
*
|
|
2298
|
-
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM|Postgres from documentation}
|
|
2108
|
+
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM | Postgres from documentation}
|
|
2299
2109
|
*/
|
|
2300
2110
|
from(source) {
|
|
2301
2111
|
const isPartialSelect = !!this.fields;
|
|
@@ -2316,7 +2126,7 @@ class PgSelectBuilder {
|
|
|
2316
2126
|
else {
|
|
2317
2127
|
fields = getTableColumns(source);
|
|
2318
2128
|
}
|
|
2319
|
-
return new
|
|
2129
|
+
return new PgSelectBase({
|
|
2320
2130
|
table: source,
|
|
2321
2131
|
fields,
|
|
2322
2132
|
isPartialSelect,
|
|
@@ -2327,7 +2137,7 @@ class PgSelectBuilder {
|
|
|
2327
2137
|
});
|
|
2328
2138
|
}
|
|
2329
2139
|
}
|
|
2330
|
-
class
|
|
2140
|
+
class PgSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
2331
2141
|
static [entityKind] = 'PgSelectQueryBuilder';
|
|
2332
2142
|
_;
|
|
2333
2143
|
config;
|
|
@@ -2461,7 +2271,7 @@ class PgSelectQueryBuilder extends TypedQueryBuilder {
|
|
|
2461
2271
|
* used with GROUP BY and filters rows after they've been
|
|
2462
2272
|
* grouped together and combined.
|
|
2463
2273
|
*
|
|
2464
|
-
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-HAVING|Postgres having clause documentation}
|
|
2274
|
+
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-HAVING | Postgres having clause documentation}
|
|
2465
2275
|
*/
|
|
2466
2276
|
having(having) {
|
|
2467
2277
|
if (typeof having === 'function') {
|
|
@@ -2501,7 +2311,7 @@ class PgSelectQueryBuilder extends TypedQueryBuilder {
|
|
|
2501
2311
|
* db.select().from(people).limit(10);
|
|
2502
2312
|
* ```
|
|
2503
2313
|
*
|
|
2504
|
-
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-LIMIT|Postgres LIMIT documentation}
|
|
2314
|
+
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-LIMIT | Postgres LIMIT documentation}
|
|
2505
2315
|
*/
|
|
2506
2316
|
limit(limit) {
|
|
2507
2317
|
this.config.limit = limit;
|
|
@@ -2527,13 +2337,10 @@ class PgSelectQueryBuilder extends TypedQueryBuilder {
|
|
|
2527
2337
|
* that controls how strictly it acquires exclusive access to
|
|
2528
2338
|
* the rows being queried.
|
|
2529
2339
|
*
|
|
2530
|
-
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE|
|
|
2340
|
+
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE | PostgreSQL locking clause documentation}
|
|
2531
2341
|
*/
|
|
2532
2342
|
for(strength, config = {}) {
|
|
2533
|
-
|
|
2534
|
-
this.config.lockingClauses = [];
|
|
2535
|
-
}
|
|
2536
|
-
this.config.lockingClauses.push({ strength, config });
|
|
2343
|
+
this.config.lockingClause = { strength, config };
|
|
2537
2344
|
return this;
|
|
2538
2345
|
}
|
|
2539
2346
|
/** @internal */
|
|
@@ -2547,8 +2354,15 @@ class PgSelectQueryBuilder extends TypedQueryBuilder {
|
|
|
2547
2354
|
as(alias) {
|
|
2548
2355
|
return new Proxy(new Subquery(this.getSQL(), this.config.fields, alias), new SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }));
|
|
2549
2356
|
}
|
|
2357
|
+
/** @internal */
|
|
2358
|
+
getSelectedFields() {
|
|
2359
|
+
return new Proxy(this.config.fields, new SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }));
|
|
2360
|
+
}
|
|
2361
|
+
$dynamic() {
|
|
2362
|
+
return this;
|
|
2363
|
+
}
|
|
2550
2364
|
}
|
|
2551
|
-
class
|
|
2365
|
+
class PgSelectBase extends PgSelectQueryBuilderBase {
|
|
2552
2366
|
static [entityKind] = 'PgSelect';
|
|
2553
2367
|
_prepare(name) {
|
|
2554
2368
|
const { session, config, dialect, joinsNotNullableMap } = this;
|
|
@@ -2567,7 +2381,7 @@ class PgSelect extends PgSelectQueryBuilder {
|
|
|
2567
2381
|
* the database to remember this query for the given session
|
|
2568
2382
|
* and call it by name, rather than specifying the full query.
|
|
2569
2383
|
*
|
|
2570
|
-
* {@link https://www.postgresql.org/docs/current/sql-prepare.html|Postgres prepare documentation}
|
|
2384
|
+
* {@link https://www.postgresql.org/docs/current/sql-prepare.html | Postgres prepare documentation}
|
|
2571
2385
|
*/
|
|
2572
2386
|
prepare(name) {
|
|
2573
2387
|
return this._prepare(name);
|
|
@@ -2578,7 +2392,7 @@ class PgSelect extends PgSelectQueryBuilder {
|
|
|
2578
2392
|
});
|
|
2579
2393
|
};
|
|
2580
2394
|
}
|
|
2581
|
-
applyMixins(
|
|
2395
|
+
applyMixins(PgSelectBase, [QueryPromise]);
|
|
2582
2396
|
|
|
2583
2397
|
class QueryBuilder {
|
|
2584
2398
|
static [entityKind] = 'PgQueryBuilder';
|
|
@@ -2654,6 +2468,8 @@ class QueryBuilder {
|
|
|
2654
2468
|
}
|
|
2655
2469
|
}
|
|
2656
2470
|
|
|
2471
|
+
const PgViewConfig = Symbol.for('drizzle:PgViewConfig');
|
|
2472
|
+
|
|
2657
2473
|
class DefaultViewBuilderCore {
|
|
2658
2474
|
name;
|
|
2659
2475
|
schema;
|
|
@@ -2830,7 +2646,6 @@ class ManualMaterializedViewBuilder extends MaterializedViewBuilderCore {
|
|
|
2830
2646
|
class PgViewBase extends View {
|
|
2831
2647
|
static [entityKind] = 'PgViewBase';
|
|
2832
2648
|
}
|
|
2833
|
-
const PgViewConfig = Symbol.for('drizzle:PgViewConfig');
|
|
2834
2649
|
class PgView extends PgViewBase {
|
|
2835
2650
|
static [entityKind] = 'PgView';
|
|
2836
2651
|
[PgViewConfig];
|
|
@@ -2878,6 +2693,42 @@ function pgMaterializedView(name, columns) {
|
|
|
2878
2693
|
return pgMaterializedViewWithSchema(name, columns, undefined);
|
|
2879
2694
|
}
|
|
2880
2695
|
|
|
2696
|
+
function primaryKey(...config) {
|
|
2697
|
+
if (config[0].columns) {
|
|
2698
|
+
return new PrimaryKeyBuilder(config[0].columns, config[0].name);
|
|
2699
|
+
}
|
|
2700
|
+
return new PrimaryKeyBuilder(config);
|
|
2701
|
+
}
|
|
2702
|
+
class PrimaryKeyBuilder {
|
|
2703
|
+
static [entityKind] = 'PgPrimaryKeyBuilder';
|
|
2704
|
+
/** @internal */
|
|
2705
|
+
columns;
|
|
2706
|
+
/** @internal */
|
|
2707
|
+
name;
|
|
2708
|
+
constructor(columns, name) {
|
|
2709
|
+
this.columns = columns;
|
|
2710
|
+
this.name = name;
|
|
2711
|
+
}
|
|
2712
|
+
/** @internal */
|
|
2713
|
+
build(table) {
|
|
2714
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
class PrimaryKey {
|
|
2718
|
+
table;
|
|
2719
|
+
static [entityKind] = 'PgPrimaryKey';
|
|
2720
|
+
columns;
|
|
2721
|
+
name;
|
|
2722
|
+
constructor(table, columns, name) {
|
|
2723
|
+
this.table = table;
|
|
2724
|
+
this.columns = columns;
|
|
2725
|
+
this.name = name;
|
|
2726
|
+
}
|
|
2727
|
+
getName() {
|
|
2728
|
+
return this.name ?? `${this.table[PgTable.Symbol.Name]}_${this.columns.map((column) => column.name).join('_')}_pk`;
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2881
2732
|
class Relation {
|
|
2882
2733
|
sourceTable;
|
|
2883
2734
|
referencedTable;
|
|
@@ -3125,43 +2976,445 @@ function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelect
|
|
|
3125
2976
|
return result;
|
|
3126
2977
|
}
|
|
3127
2978
|
|
|
3128
|
-
function bindIfParam(value, column) {
|
|
3129
|
-
if (isDriverValueEncoder(column)
|
|
3130
|
-
&& !isSQLWrapper(value)
|
|
3131
|
-
&& !is(value, Param)
|
|
3132
|
-
&& !is(value, Placeholder)
|
|
3133
|
-
&& !is(value, Column)
|
|
3134
|
-
&& !is(value, Table)
|
|
3135
|
-
&& !is(value, View)) {
|
|
3136
|
-
return new Param(value, column);
|
|
3137
|
-
}
|
|
3138
|
-
return value;
|
|
3139
|
-
}
|
|
3140
2979
|
/**
|
|
3141
|
-
*
|
|
3142
|
-
*
|
|
3143
|
-
*
|
|
3144
|
-
* two NULL values are not equal, so if you want to test
|
|
3145
|
-
* whether a value is null, you may want to use
|
|
3146
|
-
* `isNull` instead.
|
|
3147
|
-
*
|
|
3148
|
-
* ## Examples
|
|
3149
|
-
*
|
|
3150
|
-
* ```ts
|
|
3151
|
-
* // Select cars made by Ford
|
|
3152
|
-
* db.select().from(cars)
|
|
3153
|
-
* .where(eq(cars.make, 'Ford'))
|
|
3154
|
-
* ```
|
|
3155
|
-
*
|
|
3156
|
-
* @see isNull for a way to test equality to NULL.
|
|
2980
|
+
* This class is used to indicate a primitive param value that is used in `sql` tag.
|
|
2981
|
+
* It is only used on type level and is never instantiated at runtime.
|
|
2982
|
+
* If you see a value of this type in the code, its runtime value is actually the primitive param value.
|
|
3157
2983
|
*/
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
}
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
2984
|
+
class FakePrimitiveParam {
|
|
2985
|
+
static [entityKind] = 'FakePrimitiveParam';
|
|
2986
|
+
}
|
|
2987
|
+
function isSQLWrapper(value) {
|
|
2988
|
+
return typeof value === 'object' && value !== null && 'getSQL' in value
|
|
2989
|
+
&& typeof value.getSQL === 'function';
|
|
2990
|
+
}
|
|
2991
|
+
function mergeQueries(queries) {
|
|
2992
|
+
const result = { sql: '', params: [] };
|
|
2993
|
+
for (const query of queries) {
|
|
2994
|
+
result.sql += query.sql;
|
|
2995
|
+
result.params.push(...query.params);
|
|
2996
|
+
if (query.typings?.length) {
|
|
2997
|
+
if (!result.typings) {
|
|
2998
|
+
result.typings = [];
|
|
2999
|
+
}
|
|
3000
|
+
result.typings.push(...query.typings);
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
return result;
|
|
3004
|
+
}
|
|
3005
|
+
class StringChunk {
|
|
3006
|
+
static [entityKind] = 'StringChunk';
|
|
3007
|
+
value;
|
|
3008
|
+
constructor(value) {
|
|
3009
|
+
this.value = Array.isArray(value) ? value : [value];
|
|
3010
|
+
}
|
|
3011
|
+
getSQL() {
|
|
3012
|
+
return new SQL([this]);
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
class SQL {
|
|
3016
|
+
queryChunks;
|
|
3017
|
+
static [entityKind] = 'SQL';
|
|
3018
|
+
/** @internal */
|
|
3019
|
+
decoder = noopDecoder;
|
|
3020
|
+
shouldInlineParams = false;
|
|
3021
|
+
constructor(queryChunks) {
|
|
3022
|
+
this.queryChunks = queryChunks;
|
|
3023
|
+
}
|
|
3024
|
+
append(query) {
|
|
3025
|
+
this.queryChunks.push(...query.queryChunks);
|
|
3026
|
+
return this;
|
|
3027
|
+
}
|
|
3028
|
+
toQuery(config) {
|
|
3029
|
+
return tracer.startActiveSpan('drizzle.buildSQL', (span) => {
|
|
3030
|
+
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
3031
|
+
span?.setAttributes({
|
|
3032
|
+
'drizzle.query.text': query.sql,
|
|
3033
|
+
'drizzle.query.params': JSON.stringify(query.params),
|
|
3034
|
+
});
|
|
3035
|
+
return query;
|
|
3036
|
+
});
|
|
3037
|
+
}
|
|
3038
|
+
buildQueryFromSourceParams(chunks, _config) {
|
|
3039
|
+
const config = Object.assign({}, _config, {
|
|
3040
|
+
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
3041
|
+
paramStartIndex: _config.paramStartIndex || { value: 0 },
|
|
3042
|
+
});
|
|
3043
|
+
const { escapeName, escapeParam, prepareTyping, inlineParams, paramStartIndex, } = config;
|
|
3044
|
+
return mergeQueries(chunks.map((chunk) => {
|
|
3045
|
+
if (is(chunk, StringChunk)) {
|
|
3046
|
+
return { sql: chunk.value.join(''), params: [] };
|
|
3047
|
+
}
|
|
3048
|
+
if (is(chunk, Name)) {
|
|
3049
|
+
return { sql: escapeName(chunk.value), params: [] };
|
|
3050
|
+
}
|
|
3051
|
+
if (chunk === undefined) {
|
|
3052
|
+
return { sql: '', params: [] };
|
|
3053
|
+
}
|
|
3054
|
+
if (Array.isArray(chunk)) {
|
|
3055
|
+
const result = [new StringChunk('(')];
|
|
3056
|
+
for (const [i, p] of chunk.entries()) {
|
|
3057
|
+
result.push(p);
|
|
3058
|
+
if (i < chunk.length - 1) {
|
|
3059
|
+
result.push(new StringChunk(', '));
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
result.push(new StringChunk(')'));
|
|
3063
|
+
return this.buildQueryFromSourceParams(result, config);
|
|
3064
|
+
}
|
|
3065
|
+
if (is(chunk, SQL)) {
|
|
3066
|
+
return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
3067
|
+
...config,
|
|
3068
|
+
inlineParams: inlineParams || chunk.shouldInlineParams,
|
|
3069
|
+
});
|
|
3070
|
+
}
|
|
3071
|
+
if (is(chunk, Table)) {
|
|
3072
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
3073
|
+
const tableName = chunk[Table.Symbol.Name];
|
|
3074
|
+
return {
|
|
3075
|
+
sql: schemaName === undefined
|
|
3076
|
+
? escapeName(tableName)
|
|
3077
|
+
: escapeName(schemaName) + '.' + escapeName(tableName),
|
|
3078
|
+
params: [],
|
|
3079
|
+
};
|
|
3080
|
+
}
|
|
3081
|
+
if (is(chunk, Column)) {
|
|
3082
|
+
return { sql: escapeName(chunk.table[Table.Symbol.Name]) + '.' + escapeName(chunk.name), params: [] };
|
|
3083
|
+
}
|
|
3084
|
+
if (is(chunk, View)) {
|
|
3085
|
+
const schemaName = chunk[ViewBaseConfig].schema;
|
|
3086
|
+
const viewName = chunk[ViewBaseConfig].name;
|
|
3087
|
+
return {
|
|
3088
|
+
sql: schemaName === undefined
|
|
3089
|
+
? escapeName(viewName)
|
|
3090
|
+
: escapeName(schemaName) + '.' + escapeName(viewName),
|
|
3091
|
+
params: [],
|
|
3092
|
+
};
|
|
3093
|
+
}
|
|
3094
|
+
if (is(chunk, Param)) {
|
|
3095
|
+
const mappedValue = (chunk.value === null) ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
3096
|
+
if (is(mappedValue, SQL)) {
|
|
3097
|
+
return this.buildQueryFromSourceParams([mappedValue], config);
|
|
3098
|
+
}
|
|
3099
|
+
if (inlineParams) {
|
|
3100
|
+
return { sql: this.mapInlineParam(mappedValue, config), params: [] };
|
|
3101
|
+
}
|
|
3102
|
+
let typings;
|
|
3103
|
+
if (prepareTyping !== undefined) {
|
|
3104
|
+
typings = [prepareTyping(chunk.encoder)];
|
|
3105
|
+
}
|
|
3106
|
+
return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
|
|
3107
|
+
}
|
|
3108
|
+
if (is(chunk, Placeholder)) {
|
|
3109
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk] };
|
|
3110
|
+
}
|
|
3111
|
+
if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== undefined) {
|
|
3112
|
+
return { sql: escapeName(chunk.fieldAlias), params: [] };
|
|
3113
|
+
}
|
|
3114
|
+
if (is(chunk, Subquery)) {
|
|
3115
|
+
if (chunk[SubqueryConfig].isWith) {
|
|
3116
|
+
return { sql: escapeName(chunk[SubqueryConfig].alias), params: [] };
|
|
3117
|
+
}
|
|
3118
|
+
return this.buildQueryFromSourceParams([
|
|
3119
|
+
new StringChunk('('),
|
|
3120
|
+
chunk[SubqueryConfig].sql,
|
|
3121
|
+
new StringChunk(') '),
|
|
3122
|
+
new Name(chunk[SubqueryConfig].alias),
|
|
3123
|
+
], config);
|
|
3124
|
+
}
|
|
3125
|
+
// if (is(chunk, Placeholder)) {
|
|
3126
|
+
// return {sql: escapeParam}
|
|
3127
|
+
if (isSQLWrapper(chunk)) {
|
|
3128
|
+
return this.buildQueryFromSourceParams([
|
|
3129
|
+
new StringChunk('('),
|
|
3130
|
+
chunk.getSQL(),
|
|
3131
|
+
new StringChunk(')'),
|
|
3132
|
+
], config);
|
|
3133
|
+
}
|
|
3134
|
+
if (is(chunk, Relation)) {
|
|
3135
|
+
return this.buildQueryFromSourceParams([
|
|
3136
|
+
chunk.sourceTable,
|
|
3137
|
+
new StringChunk('.'),
|
|
3138
|
+
sql.identifier(chunk.fieldName),
|
|
3139
|
+
], config);
|
|
3140
|
+
}
|
|
3141
|
+
if (inlineParams) {
|
|
3142
|
+
return { sql: this.mapInlineParam(chunk, config), params: [] };
|
|
3143
|
+
}
|
|
3144
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk] };
|
|
3145
|
+
}));
|
|
3146
|
+
}
|
|
3147
|
+
mapInlineParam(chunk, { escapeString }) {
|
|
3148
|
+
if (chunk === null) {
|
|
3149
|
+
return 'null';
|
|
3150
|
+
}
|
|
3151
|
+
if (typeof chunk === 'number' || typeof chunk === 'boolean') {
|
|
3152
|
+
return chunk.toString();
|
|
3153
|
+
}
|
|
3154
|
+
if (typeof chunk === 'string') {
|
|
3155
|
+
return escapeString(chunk);
|
|
3156
|
+
}
|
|
3157
|
+
if (typeof chunk === 'object') {
|
|
3158
|
+
const mappedValueAsString = chunk.toString();
|
|
3159
|
+
if (mappedValueAsString === '[object Object]') {
|
|
3160
|
+
return escapeString(JSON.stringify(chunk));
|
|
3161
|
+
}
|
|
3162
|
+
return escapeString(mappedValueAsString);
|
|
3163
|
+
}
|
|
3164
|
+
throw new Error('Unexpected param value: ' + chunk);
|
|
3165
|
+
}
|
|
3166
|
+
getSQL() {
|
|
3167
|
+
return this;
|
|
3168
|
+
}
|
|
3169
|
+
as(alias) {
|
|
3170
|
+
// TODO: remove with deprecated overloads
|
|
3171
|
+
if (alias === undefined) {
|
|
3172
|
+
return this;
|
|
3173
|
+
}
|
|
3174
|
+
return new SQL.Aliased(this, alias);
|
|
3175
|
+
}
|
|
3176
|
+
mapWith(decoder) {
|
|
3177
|
+
this.decoder = typeof decoder === 'function' ? { mapFromDriverValue: decoder } : decoder;
|
|
3178
|
+
return this;
|
|
3179
|
+
}
|
|
3180
|
+
inlineParams() {
|
|
3181
|
+
this.shouldInlineParams = true;
|
|
3182
|
+
return this;
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
/**
|
|
3186
|
+
* Any DB name (table, column, index etc.)
|
|
3187
|
+
*/
|
|
3188
|
+
class Name {
|
|
3189
|
+
value;
|
|
3190
|
+
static [entityKind] = 'Name';
|
|
3191
|
+
brand;
|
|
3192
|
+
constructor(value) {
|
|
3193
|
+
this.value = value;
|
|
3194
|
+
}
|
|
3195
|
+
getSQL() {
|
|
3196
|
+
return new SQL([this]);
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
/**
|
|
3200
|
+
* Any DB name (table, column, index etc.)
|
|
3201
|
+
* @deprecated Use `sql.identifier` instead.
|
|
3202
|
+
*/
|
|
3203
|
+
function name(value) {
|
|
3204
|
+
return new Name(value);
|
|
3205
|
+
}
|
|
3206
|
+
function isDriverValueEncoder(value) {
|
|
3207
|
+
return typeof value === 'object' && value !== null && 'mapToDriverValue' in value
|
|
3208
|
+
&& typeof value.mapToDriverValue === 'function';
|
|
3209
|
+
}
|
|
3210
|
+
const noopDecoder = {
|
|
3211
|
+
mapFromDriverValue: (value) => value,
|
|
3212
|
+
};
|
|
3213
|
+
const noopEncoder = {
|
|
3214
|
+
mapToDriverValue: (value) => value,
|
|
3215
|
+
};
|
|
3216
|
+
const noopMapper = {
|
|
3217
|
+
...noopDecoder,
|
|
3218
|
+
...noopEncoder,
|
|
3219
|
+
};
|
|
3220
|
+
/** Parameter value that is optionally bound to an encoder (for example, a column). */
|
|
3221
|
+
class Param {
|
|
3222
|
+
value;
|
|
3223
|
+
encoder;
|
|
3224
|
+
static [entityKind] = 'Param';
|
|
3225
|
+
brand;
|
|
3226
|
+
/**
|
|
3227
|
+
* @param value - Parameter value
|
|
3228
|
+
* @param encoder - Encoder to convert the value to a driver parameter
|
|
3229
|
+
*/
|
|
3230
|
+
constructor(value, encoder = noopEncoder) {
|
|
3231
|
+
this.value = value;
|
|
3232
|
+
this.encoder = encoder;
|
|
3233
|
+
}
|
|
3234
|
+
getSQL() {
|
|
3235
|
+
return new SQL([this]);
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
/** @deprecated Use `sql.param` instead. */
|
|
3239
|
+
function param(value, encoder) {
|
|
3240
|
+
return new Param(value, encoder);
|
|
3241
|
+
}
|
|
3242
|
+
/*
|
|
3243
|
+
The type of `params` is specified as `SQLSourceParam[]`, but that's slightly incorrect -
|
|
3244
|
+
in runtime, users won't pass `FakePrimitiveParam` instances as `params` - they will pass primitive values
|
|
3245
|
+
which will be wrapped in `Param` using `buildChunksFromParam(...)`. That's why the overload
|
|
3246
|
+
specify `params` as `any[]` and not as `SQLSourceParam[]`. This type is used to make our lives easier and
|
|
3247
|
+
the type checker happy.
|
|
3248
|
+
*/
|
|
3249
|
+
function sql(strings, ...params) {
|
|
3250
|
+
const queryChunks = [];
|
|
3251
|
+
if (params.length > 0 || (strings.length > 0 && strings[0] !== '')) {
|
|
3252
|
+
queryChunks.push(new StringChunk(strings[0]));
|
|
3253
|
+
}
|
|
3254
|
+
for (const [paramIndex, param] of params.entries()) {
|
|
3255
|
+
queryChunks.push(param, new StringChunk(strings[paramIndex + 1]));
|
|
3256
|
+
}
|
|
3257
|
+
return new SQL(queryChunks);
|
|
3258
|
+
}
|
|
3259
|
+
(function (sql) {
|
|
3260
|
+
function empty() {
|
|
3261
|
+
return new SQL([]);
|
|
3262
|
+
}
|
|
3263
|
+
sql.empty = empty;
|
|
3264
|
+
/** @deprecated - use `sql.join()` */
|
|
3265
|
+
function fromList(list) {
|
|
3266
|
+
return new SQL(list);
|
|
3267
|
+
}
|
|
3268
|
+
sql.fromList = fromList;
|
|
3269
|
+
/**
|
|
3270
|
+
* Convenience function to create an SQL query from a raw string.
|
|
3271
|
+
* @param str The raw SQL query string.
|
|
3272
|
+
*/
|
|
3273
|
+
function raw(str) {
|
|
3274
|
+
return new SQL([new StringChunk(str)]);
|
|
3275
|
+
}
|
|
3276
|
+
sql.raw = raw;
|
|
3277
|
+
/**
|
|
3278
|
+
* Join a list of SQL chunks with a separator.
|
|
3279
|
+
* @example
|
|
3280
|
+
* ```ts
|
|
3281
|
+
* const query = sql.join([sql`a`, sql`b`, sql`c`]);
|
|
3282
|
+
* // sql`abc`
|
|
3283
|
+
* ```
|
|
3284
|
+
* @example
|
|
3285
|
+
* ```ts
|
|
3286
|
+
* const query = sql.join([sql`a`, sql`b`, sql`c`], sql`, `);
|
|
3287
|
+
* // sql`a, b, c`
|
|
3288
|
+
* ```
|
|
3289
|
+
*/
|
|
3290
|
+
function join(chunks, separator) {
|
|
3291
|
+
const result = [];
|
|
3292
|
+
for (const [i, chunk] of chunks.entries()) {
|
|
3293
|
+
if (i > 0 && separator !== undefined) {
|
|
3294
|
+
result.push(separator);
|
|
3295
|
+
}
|
|
3296
|
+
result.push(chunk);
|
|
3297
|
+
}
|
|
3298
|
+
return new SQL(result);
|
|
3299
|
+
}
|
|
3300
|
+
sql.join = join;
|
|
3301
|
+
/**
|
|
3302
|
+
* Create a SQL chunk that represents a DB identifier (table, column, index etc.).
|
|
3303
|
+
* When used in a query, the identifier will be escaped based on the DB engine.
|
|
3304
|
+
* For example, in PostgreSQL, identifiers are escaped with double quotes.
|
|
3305
|
+
*
|
|
3306
|
+
* **WARNING: This function does not offer any protection against SQL injections, so you must validate any user input beforehand.**
|
|
3307
|
+
*
|
|
3308
|
+
* @example ```ts
|
|
3309
|
+
* const query = sql`SELECT * FROM ${sql.identifier('my-table')}`;
|
|
3310
|
+
* // 'SELECT * FROM "my-table"'
|
|
3311
|
+
* ```
|
|
3312
|
+
*/
|
|
3313
|
+
function identifier(value) {
|
|
3314
|
+
return new Name(value);
|
|
3315
|
+
}
|
|
3316
|
+
sql.identifier = identifier;
|
|
3317
|
+
function placeholder(name) {
|
|
3318
|
+
return new Placeholder(name);
|
|
3319
|
+
}
|
|
3320
|
+
sql.placeholder = placeholder;
|
|
3321
|
+
function param(value, encoder) {
|
|
3322
|
+
return new Param(value, encoder);
|
|
3323
|
+
}
|
|
3324
|
+
sql.param = param;
|
|
3325
|
+
})(sql || (sql = {}));
|
|
3326
|
+
(function (SQL) {
|
|
3327
|
+
class Aliased {
|
|
3328
|
+
sql;
|
|
3329
|
+
fieldAlias;
|
|
3330
|
+
static [entityKind] = 'SQL.Aliased';
|
|
3331
|
+
/** @internal */
|
|
3332
|
+
isSelectionField = false;
|
|
3333
|
+
constructor(sql, fieldAlias) {
|
|
3334
|
+
this.sql = sql;
|
|
3335
|
+
this.fieldAlias = fieldAlias;
|
|
3336
|
+
}
|
|
3337
|
+
getSQL() {
|
|
3338
|
+
return this.sql;
|
|
3339
|
+
}
|
|
3340
|
+
/** @internal */
|
|
3341
|
+
clone() {
|
|
3342
|
+
return new Aliased(this.sql, this.fieldAlias);
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
SQL.Aliased = Aliased;
|
|
3346
|
+
})(SQL || (SQL = {}));
|
|
3347
|
+
class Placeholder {
|
|
3348
|
+
name;
|
|
3349
|
+
static [entityKind] = 'Placeholder';
|
|
3350
|
+
constructor(name) {
|
|
3351
|
+
this.name = name;
|
|
3352
|
+
}
|
|
3353
|
+
getSQL() {
|
|
3354
|
+
return new SQL([this]);
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
/** @deprecated Use `sql.placeholder` instead. */
|
|
3358
|
+
function placeholder(name) {
|
|
3359
|
+
return new Placeholder(name);
|
|
3360
|
+
}
|
|
3361
|
+
function fillPlaceholders(params, values) {
|
|
3362
|
+
return params.map((p) => {
|
|
3363
|
+
if (is(p, Placeholder)) {
|
|
3364
|
+
if (!(p.name in values)) {
|
|
3365
|
+
throw new Error(`No value for placeholder "${p.name}" was provided`);
|
|
3366
|
+
}
|
|
3367
|
+
return values[p.name];
|
|
3368
|
+
}
|
|
3369
|
+
return p;
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3372
|
+
// Defined separately from the Column class to resolve circular dependency
|
|
3373
|
+
Column.prototype.getSQL = function () {
|
|
3374
|
+
return new SQL([this]);
|
|
3375
|
+
};
|
|
3376
|
+
// Defined separately from the Table class to resolve circular dependency
|
|
3377
|
+
Table.prototype.getSQL = function () {
|
|
3378
|
+
return new SQL([this]);
|
|
3379
|
+
};
|
|
3380
|
+
|
|
3381
|
+
function bindIfParam(value, column) {
|
|
3382
|
+
if (isDriverValueEncoder(column)
|
|
3383
|
+
&& !isSQLWrapper(value)
|
|
3384
|
+
&& !is(value, Param)
|
|
3385
|
+
&& !is(value, Placeholder)
|
|
3386
|
+
&& !is(value, Column)
|
|
3387
|
+
&& !is(value, Table)
|
|
3388
|
+
&& !is(value, View)) {
|
|
3389
|
+
return new Param(value, column);
|
|
3390
|
+
}
|
|
3391
|
+
return value;
|
|
3392
|
+
}
|
|
3393
|
+
/**
|
|
3394
|
+
* Test that two values are equal.
|
|
3395
|
+
*
|
|
3396
|
+
* Remember that the SQL standard dictates that
|
|
3397
|
+
* two NULL values are not equal, so if you want to test
|
|
3398
|
+
* whether a value is null, you may want to use
|
|
3399
|
+
* `isNull` instead.
|
|
3400
|
+
*
|
|
3401
|
+
* ## Examples
|
|
3402
|
+
*
|
|
3403
|
+
* ```ts
|
|
3404
|
+
* // Select cars made by Ford
|
|
3405
|
+
* db.select().from(cars)
|
|
3406
|
+
* .where(eq(cars.make, 'Ford'))
|
|
3407
|
+
* ```
|
|
3408
|
+
*
|
|
3409
|
+
* @see isNull for a way to test equality to NULL.
|
|
3410
|
+
*/
|
|
3411
|
+
const eq = (left, right) => {
|
|
3412
|
+
return sql `${left} = ${bindIfParam(right, left)}`;
|
|
3413
|
+
};
|
|
3414
|
+
/**
|
|
3415
|
+
* Test that two values are not equal.
|
|
3416
|
+
*
|
|
3417
|
+
* Remember that the SQL standard dictates that
|
|
3165
3418
|
* two NULL values are not equal, so if you want to test
|
|
3166
3419
|
* whether a value is not null, you may want to use
|
|
3167
3420
|
* `isNotNull` instead.
|
|
@@ -3414,544 +3667,146 @@ function notBetween(column, min, max) {
|
|
|
3414
3667
|
* .where(like(cars.name, '%Turbo%'))
|
|
3415
3668
|
* ```
|
|
3416
3669
|
*
|
|
3417
|
-
* @see ilike for a case-insensitive version of this condition
|
|
3418
|
-
*/
|
|
3419
|
-
function like(column, value) {
|
|
3420
|
-
return sql `${column} like ${value}`;
|
|
3421
|
-
}
|
|
3422
|
-
/**
|
|
3423
|
-
* The inverse of like - this tests that a given column
|
|
3424
|
-
* does not match a pattern, which can include `%` and `_`
|
|
3425
|
-
* characters to match multiple variations. Including `%`
|
|
3426
|
-
* in the pattern matches zero or more characters, and including
|
|
3427
|
-
* `_` will match a single character.
|
|
3428
|
-
*
|
|
3429
|
-
* ## Examples
|
|
3430
|
-
*
|
|
3431
|
-
* ```ts
|
|
3432
|
-
* // Select all cars that don't have "ROver" in their name.
|
|
3433
|
-
* db.select().from(cars)
|
|
3434
|
-
* .where(notLike(cars.name, '%Rover%'))
|
|
3435
|
-
* ```
|
|
3436
|
-
*
|
|
3437
|
-
* @see like for the inverse condition
|
|
3438
|
-
* @see notIlike for a case-insensitive version of this condition
|
|
3439
|
-
*/
|
|
3440
|
-
function notLike(column, value) {
|
|
3441
|
-
return sql `${column} not like ${value}`;
|
|
3442
|
-
}
|
|
3443
|
-
/**
|
|
3444
|
-
* Case-insensitively compare a column to a pattern,
|
|
3445
|
-
* which can include `%` and `_`
|
|
3446
|
-
* characters to match multiple variations. Including `%`
|
|
3447
|
-
* in the pattern matches zero or more characters, and including
|
|
3448
|
-
* `_` will match a single character.
|
|
3449
|
-
*
|
|
3450
|
-
* Unlike like, this performs a case-insensitive comparison.
|
|
3451
|
-
*
|
|
3452
|
-
* ## Examples
|
|
3453
|
-
*
|
|
3454
|
-
* ```ts
|
|
3455
|
-
* // Select all cars with 'Turbo' in their names.
|
|
3456
|
-
* db.select().from(cars)
|
|
3457
|
-
* .where(ilike(cars.name, '%Turbo%'))
|
|
3458
|
-
* ```
|
|
3459
|
-
*
|
|
3460
|
-
* @see like for a case-sensitive version of this condition
|
|
3461
|
-
*/
|
|
3462
|
-
function ilike(column, value) {
|
|
3463
|
-
return sql `${column} ilike ${value}`;
|
|
3464
|
-
}
|
|
3465
|
-
/**
|
|
3466
|
-
* The inverse of ilike - this case-insensitively tests that a given column
|
|
3467
|
-
* does not match a pattern, which can include `%` and `_`
|
|
3468
|
-
* characters to match multiple variations. Including `%`
|
|
3469
|
-
* in the pattern matches zero or more characters, and including
|
|
3470
|
-
* `_` will match a single character.
|
|
3471
|
-
*
|
|
3472
|
-
* ## Examples
|
|
3473
|
-
*
|
|
3474
|
-
* ```ts
|
|
3475
|
-
* // Select all cars that don't have "Rover" in their name.
|
|
3476
|
-
* db.select().from(cars)
|
|
3477
|
-
* .where(notLike(cars.name, '%Rover%'))
|
|
3478
|
-
* ```
|
|
3479
|
-
*
|
|
3480
|
-
* @see ilike for the inverse condition
|
|
3481
|
-
* @see notLike for a case-sensitive version of this condition
|
|
3482
|
-
*/
|
|
3483
|
-
function notIlike(column, value) {
|
|
3484
|
-
return sql `${column} not ilike ${value}`;
|
|
3485
|
-
}
|
|
3486
|
-
function arrayContains(column, values) {
|
|
3487
|
-
if (Array.isArray(values)) {
|
|
3488
|
-
if (values.length === 0) {
|
|
3489
|
-
throw new Error('arrayContains requires at least one value');
|
|
3490
|
-
}
|
|
3491
|
-
const array = sql `${bindIfParam(values, column)}`;
|
|
3492
|
-
return sql `${column} @> ${array}`;
|
|
3493
|
-
}
|
|
3494
|
-
return sql `${column} @> ${bindIfParam(values, column)}`;
|
|
3495
|
-
}
|
|
3496
|
-
function arrayContained(column, values) {
|
|
3497
|
-
if (Array.isArray(values)) {
|
|
3498
|
-
if (values.length === 0) {
|
|
3499
|
-
throw new Error('arrayContained requires at least one value');
|
|
3500
|
-
}
|
|
3501
|
-
const array = sql `${bindIfParam(values, column)}`;
|
|
3502
|
-
return sql `${column} <@ ${array}`;
|
|
3503
|
-
}
|
|
3504
|
-
return sql `${column} <@ ${bindIfParam(values, column)}`;
|
|
3505
|
-
}
|
|
3506
|
-
function arrayOverlaps(column, values) {
|
|
3507
|
-
if (Array.isArray(values)) {
|
|
3508
|
-
if (values.length === 0) {
|
|
3509
|
-
throw new Error('arrayOverlaps requires at least one value');
|
|
3510
|
-
}
|
|
3511
|
-
const array = sql `${bindIfParam(values, column)}`;
|
|
3512
|
-
return sql `${column} && ${array}`;
|
|
3513
|
-
}
|
|
3514
|
-
return sql `${column} && ${bindIfParam(values, column)}`;
|
|
3515
|
-
}
|
|
3516
|
-
|
|
3517
|
-
/**
|
|
3518
|
-
* Used in sorting, this specifies that the given
|
|
3519
|
-
* column or expression should be sorted in ascending
|
|
3520
|
-
* order. By the SQL standard, ascending order is the
|
|
3521
|
-
* default, so it is not usually necessary to specify
|
|
3522
|
-
* ascending sort order.
|
|
3523
|
-
*
|
|
3524
|
-
* ## Examples
|
|
3525
|
-
*
|
|
3526
|
-
* ```ts
|
|
3527
|
-
* // Return cars, starting with the oldest models
|
|
3528
|
-
* // and going in ascending order to the newest.
|
|
3529
|
-
* db.select().from(cars)
|
|
3530
|
-
* .orderBy(asc(cars.year));
|
|
3531
|
-
* ```
|
|
3532
|
-
*
|
|
3533
|
-
* @see desc to sort in descending order
|
|
3670
|
+
* @see ilike for a case-insensitive version of this condition
|
|
3534
3671
|
*/
|
|
3535
|
-
function
|
|
3536
|
-
return sql `${column}
|
|
3672
|
+
function like(column, value) {
|
|
3673
|
+
return sql `${column} like ${value}`;
|
|
3537
3674
|
}
|
|
3538
3675
|
/**
|
|
3539
|
-
*
|
|
3540
|
-
*
|
|
3541
|
-
*
|
|
3676
|
+
* The inverse of like - this tests that a given column
|
|
3677
|
+
* does not match a pattern, which can include `%` and `_`
|
|
3678
|
+
* characters to match multiple variations. Including `%`
|
|
3679
|
+
* in the pattern matches zero or more characters, and including
|
|
3680
|
+
* `_` will match a single character.
|
|
3542
3681
|
*
|
|
3543
3682
|
* ## Examples
|
|
3544
3683
|
*
|
|
3545
3684
|
* ```ts
|
|
3546
|
-
* // Select
|
|
3547
|
-
*
|
|
3548
|
-
*
|
|
3549
|
-
* .orderBy(desc(users.createdAt));
|
|
3685
|
+
* // Select all cars that don't have "ROver" in their name.
|
|
3686
|
+
* db.select().from(cars)
|
|
3687
|
+
* .where(notLike(cars.name, '%Rover%'))
|
|
3550
3688
|
* ```
|
|
3551
3689
|
*
|
|
3552
|
-
* @see
|
|
3553
|
-
|
|
3554
|
-
function desc(column) {
|
|
3555
|
-
return sql `${column} desc`;
|
|
3556
|
-
}
|
|
3557
|
-
|
|
3558
|
-
/**
|
|
3559
|
-
* This class is used to indicate a primitive param value that is used in `sql` tag.
|
|
3560
|
-
* It is only used on type level and is never instantiated at runtime.
|
|
3561
|
-
* If you see a value of this type in the code, its runtime value is actually the primitive param value.
|
|
3690
|
+
* @see like for the inverse condition
|
|
3691
|
+
* @see notIlike for a case-insensitive version of this condition
|
|
3562
3692
|
*/
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
}
|
|
3566
|
-
function isSQLWrapper(value) {
|
|
3567
|
-
return typeof value === 'object' && value !== null && 'getSQL' in value
|
|
3568
|
-
&& typeof value.getSQL === 'function';
|
|
3569
|
-
}
|
|
3570
|
-
function mergeQueries(queries) {
|
|
3571
|
-
const result = { sql: '', params: [] };
|
|
3572
|
-
for (const query of queries) {
|
|
3573
|
-
result.sql += query.sql;
|
|
3574
|
-
result.params.push(...query.params);
|
|
3575
|
-
if (query.typings?.length) {
|
|
3576
|
-
if (!result.typings) {
|
|
3577
|
-
result.typings = [];
|
|
3578
|
-
}
|
|
3579
|
-
result.typings.push(...query.typings);
|
|
3580
|
-
}
|
|
3581
|
-
}
|
|
3582
|
-
return result;
|
|
3583
|
-
}
|
|
3584
|
-
class StringChunk {
|
|
3585
|
-
static [entityKind] = 'StringChunk';
|
|
3586
|
-
value;
|
|
3587
|
-
constructor(value) {
|
|
3588
|
-
this.value = Array.isArray(value) ? value : [value];
|
|
3589
|
-
}
|
|
3590
|
-
getSQL() {
|
|
3591
|
-
return new SQL([this]);
|
|
3592
|
-
}
|
|
3593
|
-
}
|
|
3594
|
-
class SQL {
|
|
3595
|
-
queryChunks;
|
|
3596
|
-
static [entityKind] = 'SQL';
|
|
3597
|
-
/** @internal */
|
|
3598
|
-
decoder = noopDecoder;
|
|
3599
|
-
shouldInlineParams = false;
|
|
3600
|
-
constructor(queryChunks) {
|
|
3601
|
-
this.queryChunks = queryChunks;
|
|
3602
|
-
}
|
|
3603
|
-
append(query) {
|
|
3604
|
-
this.queryChunks.push(...query.queryChunks);
|
|
3605
|
-
return this;
|
|
3606
|
-
}
|
|
3607
|
-
toQuery(config) {
|
|
3608
|
-
return tracer.startActiveSpan('drizzle.buildSQL', (span) => {
|
|
3609
|
-
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
3610
|
-
span?.setAttributes({
|
|
3611
|
-
'drizzle.query.text': query.sql,
|
|
3612
|
-
'drizzle.query.params': JSON.stringify(query.params),
|
|
3613
|
-
});
|
|
3614
|
-
return query;
|
|
3615
|
-
});
|
|
3616
|
-
}
|
|
3617
|
-
buildQueryFromSourceParams(chunks, _config) {
|
|
3618
|
-
const config = Object.assign({}, _config, {
|
|
3619
|
-
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
3620
|
-
paramStartIndex: _config.paramStartIndex || { value: 0 },
|
|
3621
|
-
});
|
|
3622
|
-
const { escapeName, escapeParam, prepareTyping, inlineParams, paramStartIndex, } = config;
|
|
3623
|
-
return mergeQueries(chunks.map((chunk) => {
|
|
3624
|
-
if (is(chunk, StringChunk)) {
|
|
3625
|
-
return { sql: chunk.value.join(''), params: [] };
|
|
3626
|
-
}
|
|
3627
|
-
if (is(chunk, Name)) {
|
|
3628
|
-
return { sql: escapeName(chunk.value), params: [] };
|
|
3629
|
-
}
|
|
3630
|
-
if (chunk === undefined) {
|
|
3631
|
-
return { sql: '', params: [] };
|
|
3632
|
-
}
|
|
3633
|
-
if (Array.isArray(chunk)) {
|
|
3634
|
-
const result = [new StringChunk('(')];
|
|
3635
|
-
for (const [i, p] of chunk.entries()) {
|
|
3636
|
-
result.push(p);
|
|
3637
|
-
if (i < chunk.length - 1) {
|
|
3638
|
-
result.push(new StringChunk(', '));
|
|
3639
|
-
}
|
|
3640
|
-
}
|
|
3641
|
-
result.push(new StringChunk(')'));
|
|
3642
|
-
return this.buildQueryFromSourceParams(result, config);
|
|
3643
|
-
}
|
|
3644
|
-
if (is(chunk, SQL)) {
|
|
3645
|
-
return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
3646
|
-
...config,
|
|
3647
|
-
inlineParams: inlineParams || chunk.shouldInlineParams,
|
|
3648
|
-
});
|
|
3649
|
-
}
|
|
3650
|
-
if (is(chunk, Table)) {
|
|
3651
|
-
const schemaName = chunk[Table.Symbol.Schema];
|
|
3652
|
-
const tableName = chunk[Table.Symbol.Name];
|
|
3653
|
-
return {
|
|
3654
|
-
sql: schemaName === undefined
|
|
3655
|
-
? escapeName(tableName)
|
|
3656
|
-
: escapeName(schemaName) + '.' + escapeName(tableName),
|
|
3657
|
-
params: [],
|
|
3658
|
-
};
|
|
3659
|
-
}
|
|
3660
|
-
if (is(chunk, Column)) {
|
|
3661
|
-
return { sql: escapeName(chunk.table[Table.Symbol.Name]) + '.' + escapeName(chunk.name), params: [] };
|
|
3662
|
-
}
|
|
3663
|
-
if (is(chunk, View)) {
|
|
3664
|
-
const schemaName = chunk[ViewBaseConfig].schema;
|
|
3665
|
-
const viewName = chunk[ViewBaseConfig].name;
|
|
3666
|
-
return {
|
|
3667
|
-
sql: schemaName === undefined
|
|
3668
|
-
? escapeName(viewName)
|
|
3669
|
-
: escapeName(schemaName) + '.' + escapeName(viewName),
|
|
3670
|
-
params: [],
|
|
3671
|
-
};
|
|
3672
|
-
}
|
|
3673
|
-
if (is(chunk, Param)) {
|
|
3674
|
-
const mappedValue = (chunk.value === null) ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
3675
|
-
if (is(mappedValue, SQL)) {
|
|
3676
|
-
return this.buildQueryFromSourceParams([mappedValue], config);
|
|
3677
|
-
}
|
|
3678
|
-
if (inlineParams) {
|
|
3679
|
-
return { sql: this.mapInlineParam(mappedValue, config), params: [] };
|
|
3680
|
-
}
|
|
3681
|
-
let typings;
|
|
3682
|
-
if (prepareTyping !== undefined) {
|
|
3683
|
-
typings = [prepareTyping(chunk.encoder)];
|
|
3684
|
-
}
|
|
3685
|
-
return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
|
|
3686
|
-
}
|
|
3687
|
-
if (is(chunk, Placeholder)) {
|
|
3688
|
-
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk] };
|
|
3689
|
-
}
|
|
3690
|
-
if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== undefined) {
|
|
3691
|
-
return { sql: escapeName(chunk.fieldAlias), params: [] };
|
|
3692
|
-
}
|
|
3693
|
-
if (is(chunk, Subquery)) {
|
|
3694
|
-
if (chunk[SubqueryConfig].isWith) {
|
|
3695
|
-
return { sql: escapeName(chunk[SubqueryConfig].alias), params: [] };
|
|
3696
|
-
}
|
|
3697
|
-
return this.buildQueryFromSourceParams([
|
|
3698
|
-
new StringChunk('('),
|
|
3699
|
-
chunk[SubqueryConfig].sql,
|
|
3700
|
-
new StringChunk(') '),
|
|
3701
|
-
new Name(chunk[SubqueryConfig].alias),
|
|
3702
|
-
], config);
|
|
3703
|
-
}
|
|
3704
|
-
// if (is(chunk, Placeholder)) {
|
|
3705
|
-
// return {sql: escapeParam}
|
|
3706
|
-
if (isSQLWrapper(chunk)) {
|
|
3707
|
-
return this.buildQueryFromSourceParams([
|
|
3708
|
-
new StringChunk('('),
|
|
3709
|
-
chunk.getSQL(),
|
|
3710
|
-
new StringChunk(')'),
|
|
3711
|
-
], config);
|
|
3712
|
-
}
|
|
3713
|
-
if (is(chunk, Relation)) {
|
|
3714
|
-
return this.buildQueryFromSourceParams([
|
|
3715
|
-
chunk.sourceTable,
|
|
3716
|
-
new StringChunk('.'),
|
|
3717
|
-
sql.identifier(chunk.fieldName),
|
|
3718
|
-
], config);
|
|
3719
|
-
}
|
|
3720
|
-
if (inlineParams) {
|
|
3721
|
-
return { sql: this.mapInlineParam(chunk, config), params: [] };
|
|
3722
|
-
}
|
|
3723
|
-
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk] };
|
|
3724
|
-
}));
|
|
3725
|
-
}
|
|
3726
|
-
mapInlineParam(chunk, { escapeString }) {
|
|
3727
|
-
if (chunk === null) {
|
|
3728
|
-
return 'null';
|
|
3729
|
-
}
|
|
3730
|
-
if (typeof chunk === 'number' || typeof chunk === 'boolean') {
|
|
3731
|
-
return chunk.toString();
|
|
3732
|
-
}
|
|
3733
|
-
if (typeof chunk === 'string') {
|
|
3734
|
-
return escapeString(chunk);
|
|
3735
|
-
}
|
|
3736
|
-
if (typeof chunk === 'object') {
|
|
3737
|
-
const mappedValueAsString = chunk.toString();
|
|
3738
|
-
if (mappedValueAsString === '[object Object]') {
|
|
3739
|
-
return escapeString(JSON.stringify(chunk));
|
|
3740
|
-
}
|
|
3741
|
-
return escapeString(mappedValueAsString);
|
|
3742
|
-
}
|
|
3743
|
-
throw new Error('Unexpected param value: ' + chunk);
|
|
3744
|
-
}
|
|
3745
|
-
getSQL() {
|
|
3746
|
-
return this;
|
|
3747
|
-
}
|
|
3748
|
-
as(alias) {
|
|
3749
|
-
// TODO: remove with deprecated overloads
|
|
3750
|
-
if (alias === undefined) {
|
|
3751
|
-
return this;
|
|
3752
|
-
}
|
|
3753
|
-
return new SQL.Aliased(this, alias);
|
|
3754
|
-
}
|
|
3755
|
-
mapWith(decoder) {
|
|
3756
|
-
this.decoder = typeof decoder === 'function' ? { mapFromDriverValue: decoder } : decoder;
|
|
3757
|
-
return this;
|
|
3758
|
-
}
|
|
3759
|
-
inlineParams() {
|
|
3760
|
-
this.shouldInlineParams = true;
|
|
3761
|
-
return this;
|
|
3762
|
-
}
|
|
3693
|
+
function notLike(column, value) {
|
|
3694
|
+
return sql `${column} not like ${value}`;
|
|
3763
3695
|
}
|
|
3764
3696
|
/**
|
|
3765
|
-
*
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3697
|
+
* Case-insensitively compare a column to a pattern,
|
|
3698
|
+
* which can include `%` and `_`
|
|
3699
|
+
* characters to match multiple variations. Including `%`
|
|
3700
|
+
* in the pattern matches zero or more characters, and including
|
|
3701
|
+
* `_` will match a single character.
|
|
3702
|
+
*
|
|
3703
|
+
* Unlike like, this performs a case-insensitive comparison.
|
|
3704
|
+
*
|
|
3705
|
+
* ## Examples
|
|
3706
|
+
*
|
|
3707
|
+
* ```ts
|
|
3708
|
+
* // Select all cars with 'Turbo' in their names.
|
|
3709
|
+
* db.select().from(cars)
|
|
3710
|
+
* .where(ilike(cars.name, '%Turbo%'))
|
|
3711
|
+
* ```
|
|
3712
|
+
*
|
|
3713
|
+
* @see like for a case-sensitive version of this condition
|
|
3714
|
+
*/
|
|
3715
|
+
function ilike(column, value) {
|
|
3716
|
+
return sql `${column} ilike ${value}`;
|
|
3777
3717
|
}
|
|
3778
3718
|
/**
|
|
3779
|
-
*
|
|
3780
|
-
*
|
|
3719
|
+
* The inverse of ilike - this case-insensitively tests that a given column
|
|
3720
|
+
* does not match a pattern, which can include `%` and `_`
|
|
3721
|
+
* characters to match multiple variations. Including `%`
|
|
3722
|
+
* in the pattern matches zero or more characters, and including
|
|
3723
|
+
* `_` will match a single character.
|
|
3724
|
+
*
|
|
3725
|
+
* ## Examples
|
|
3726
|
+
*
|
|
3727
|
+
* ```ts
|
|
3728
|
+
* // Select all cars that don't have "Rover" in their name.
|
|
3729
|
+
* db.select().from(cars)
|
|
3730
|
+
* .where(notLike(cars.name, '%Rover%'))
|
|
3731
|
+
* ```
|
|
3732
|
+
*
|
|
3733
|
+
* @see ilike for the inverse condition
|
|
3734
|
+
* @see notLike for a case-sensitive version of this condition
|
|
3781
3735
|
*/
|
|
3782
|
-
function
|
|
3783
|
-
return
|
|
3784
|
-
}
|
|
3785
|
-
function isDriverValueEncoder(value) {
|
|
3786
|
-
return typeof value === 'object' && value !== null && 'mapToDriverValue' in value
|
|
3787
|
-
&& typeof value.mapToDriverValue === 'function';
|
|
3788
|
-
}
|
|
3789
|
-
const noopDecoder = {
|
|
3790
|
-
mapFromDriverValue: (value) => value,
|
|
3791
|
-
};
|
|
3792
|
-
const noopEncoder = {
|
|
3793
|
-
mapToDriverValue: (value) => value,
|
|
3794
|
-
};
|
|
3795
|
-
const noopMapper = {
|
|
3796
|
-
...noopDecoder,
|
|
3797
|
-
...noopEncoder,
|
|
3798
|
-
};
|
|
3799
|
-
/** Parameter value that is optionally bound to an encoder (for example, a column). */
|
|
3800
|
-
class Param {
|
|
3801
|
-
value;
|
|
3802
|
-
encoder;
|
|
3803
|
-
static [entityKind] = 'Param';
|
|
3804
|
-
brand;
|
|
3805
|
-
/**
|
|
3806
|
-
* @param value - Parameter value
|
|
3807
|
-
* @param encoder - Encoder to convert the value to a driver parameter
|
|
3808
|
-
*/
|
|
3809
|
-
constructor(value, encoder = noopEncoder) {
|
|
3810
|
-
this.value = value;
|
|
3811
|
-
this.encoder = encoder;
|
|
3812
|
-
}
|
|
3813
|
-
getSQL() {
|
|
3814
|
-
return new SQL([this]);
|
|
3815
|
-
}
|
|
3816
|
-
}
|
|
3817
|
-
/** @deprecated Use `sql.param` instead. */
|
|
3818
|
-
function param(value, encoder) {
|
|
3819
|
-
return new Param(value, encoder);
|
|
3736
|
+
function notIlike(column, value) {
|
|
3737
|
+
return sql `${column} not ilike ${value}`;
|
|
3820
3738
|
}
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
function sql(strings, ...params) {
|
|
3829
|
-
const queryChunks = [];
|
|
3830
|
-
if (params.length > 0 || (strings.length > 0 && strings[0] !== '')) {
|
|
3831
|
-
queryChunks.push(new StringChunk(strings[0]));
|
|
3832
|
-
}
|
|
3833
|
-
for (const [paramIndex, param] of params.entries()) {
|
|
3834
|
-
queryChunks.push(param, new StringChunk(strings[paramIndex + 1]));
|
|
3739
|
+
function arrayContains(column, values) {
|
|
3740
|
+
if (Array.isArray(values)) {
|
|
3741
|
+
if (values.length === 0) {
|
|
3742
|
+
throw new Error('arrayContains requires at least one value');
|
|
3743
|
+
}
|
|
3744
|
+
const array = sql `${bindIfParam(values, column)}`;
|
|
3745
|
+
return sql `${column} @> ${array}`;
|
|
3835
3746
|
}
|
|
3836
|
-
return
|
|
3747
|
+
return sql `${column} @> ${bindIfParam(values, column)}`;
|
|
3837
3748
|
}
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
sql.empty = empty;
|
|
3843
|
-
/** @deprecated - use `sql.join()` */
|
|
3844
|
-
function fromList(list) {
|
|
3845
|
-
return new SQL(list);
|
|
3846
|
-
}
|
|
3847
|
-
sql.fromList = fromList;
|
|
3848
|
-
/**
|
|
3849
|
-
* Convenience function to create an SQL query from a raw string.
|
|
3850
|
-
* @param str The raw SQL query string.
|
|
3851
|
-
*/
|
|
3852
|
-
function raw(str) {
|
|
3853
|
-
return new SQL([new StringChunk(str)]);
|
|
3854
|
-
}
|
|
3855
|
-
sql.raw = raw;
|
|
3856
|
-
/**
|
|
3857
|
-
* Join a list of SQL chunks with a separator.
|
|
3858
|
-
* @example
|
|
3859
|
-
* ```ts
|
|
3860
|
-
* const query = sql.join([sql`a`, sql`b`, sql`c`]);
|
|
3861
|
-
* // sql`abc`
|
|
3862
|
-
* ```
|
|
3863
|
-
* @example
|
|
3864
|
-
* ```ts
|
|
3865
|
-
* const query = sql.join([sql`a`, sql`b`, sql`c`], sql`, `);
|
|
3866
|
-
* // sql`a, b, c`
|
|
3867
|
-
* ```
|
|
3868
|
-
*/
|
|
3869
|
-
function join(chunks, separator) {
|
|
3870
|
-
const result = [];
|
|
3871
|
-
for (const [i, chunk] of chunks.entries()) {
|
|
3872
|
-
if (i > 0 && separator !== undefined) {
|
|
3873
|
-
result.push(separator);
|
|
3874
|
-
}
|
|
3875
|
-
result.push(chunk);
|
|
3749
|
+
function arrayContained(column, values) {
|
|
3750
|
+
if (Array.isArray(values)) {
|
|
3751
|
+
if (values.length === 0) {
|
|
3752
|
+
throw new Error('arrayContained requires at least one value');
|
|
3876
3753
|
}
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
sql.join = join;
|
|
3880
|
-
/**
|
|
3881
|
-
* Create a SQL chunk that represents a DB identifier (table, column, index etc.).
|
|
3882
|
-
* When used in a query, the identifier will be escaped based on the DB engine.
|
|
3883
|
-
* For example, in PostgreSQL, identifiers are escaped with double quotes.
|
|
3884
|
-
*
|
|
3885
|
-
* **WARNING: This function does not offer any protection against SQL injections, so you must validate any user input beforehand.**
|
|
3886
|
-
*
|
|
3887
|
-
* @example ```ts
|
|
3888
|
-
* const query = sql`SELECT * FROM ${sql.identifier('my-table')}`;
|
|
3889
|
-
* // 'SELECT * FROM "my-table"'
|
|
3890
|
-
* ```
|
|
3891
|
-
*/
|
|
3892
|
-
function identifier(value) {
|
|
3893
|
-
return new Name(value);
|
|
3894
|
-
}
|
|
3895
|
-
sql.identifier = identifier;
|
|
3896
|
-
function placeholder(name) {
|
|
3897
|
-
return new Placeholder(name);
|
|
3898
|
-
}
|
|
3899
|
-
sql.placeholder = placeholder;
|
|
3900
|
-
function param(value, encoder) {
|
|
3901
|
-
return new Param(value, encoder);
|
|
3754
|
+
const array = sql `${bindIfParam(values, column)}`;
|
|
3755
|
+
return sql `${column} <@ ${array}`;
|
|
3902
3756
|
}
|
|
3903
|
-
sql
|
|
3904
|
-
}
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
static [entityKind] = 'SQL.Aliased';
|
|
3910
|
-
/** @internal */
|
|
3911
|
-
isSelectionField = false;
|
|
3912
|
-
constructor(sql, fieldAlias) {
|
|
3913
|
-
this.sql = sql;
|
|
3914
|
-
this.fieldAlias = fieldAlias;
|
|
3915
|
-
}
|
|
3916
|
-
getSQL() {
|
|
3917
|
-
return this.sql;
|
|
3918
|
-
}
|
|
3919
|
-
/** @internal */
|
|
3920
|
-
clone() {
|
|
3921
|
-
return new Aliased(this.sql, this.fieldAlias);
|
|
3757
|
+
return sql `${column} <@ ${bindIfParam(values, column)}`;
|
|
3758
|
+
}
|
|
3759
|
+
function arrayOverlaps(column, values) {
|
|
3760
|
+
if (Array.isArray(values)) {
|
|
3761
|
+
if (values.length === 0) {
|
|
3762
|
+
throw new Error('arrayOverlaps requires at least one value');
|
|
3922
3763
|
}
|
|
3764
|
+
const array = sql `${bindIfParam(values, column)}`;
|
|
3765
|
+
return sql `${column} && ${array}`;
|
|
3923
3766
|
}
|
|
3924
|
-
|
|
3925
|
-
})(SQL || (SQL = {}));
|
|
3926
|
-
class Placeholder {
|
|
3927
|
-
name;
|
|
3928
|
-
static [entityKind] = 'Placeholder';
|
|
3929
|
-
constructor(name) {
|
|
3930
|
-
this.name = name;
|
|
3931
|
-
}
|
|
3932
|
-
getSQL() {
|
|
3933
|
-
return new SQL([this]);
|
|
3934
|
-
}
|
|
3767
|
+
return sql `${column} && ${bindIfParam(values, column)}`;
|
|
3935
3768
|
}
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3769
|
+
|
|
3770
|
+
/**
|
|
3771
|
+
* Used in sorting, this specifies that the given
|
|
3772
|
+
* column or expression should be sorted in ascending
|
|
3773
|
+
* order. By the SQL standard, ascending order is the
|
|
3774
|
+
* default, so it is not usually necessary to specify
|
|
3775
|
+
* ascending sort order.
|
|
3776
|
+
*
|
|
3777
|
+
* ## Examples
|
|
3778
|
+
*
|
|
3779
|
+
* ```ts
|
|
3780
|
+
* // Return cars, starting with the oldest models
|
|
3781
|
+
* // and going in ascending order to the newest.
|
|
3782
|
+
* db.select().from(cars)
|
|
3783
|
+
* .orderBy(asc(cars.year));
|
|
3784
|
+
* ```
|
|
3785
|
+
*
|
|
3786
|
+
* @see desc to sort in descending order
|
|
3787
|
+
*/
|
|
3788
|
+
function asc(column) {
|
|
3789
|
+
return sql `${column} asc`;
|
|
3939
3790
|
}
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3791
|
+
/**
|
|
3792
|
+
* Used in sorting, this specifies that the given
|
|
3793
|
+
* column or expression should be sorted in descending
|
|
3794
|
+
* order.
|
|
3795
|
+
*
|
|
3796
|
+
* ## Examples
|
|
3797
|
+
*
|
|
3798
|
+
* ```ts
|
|
3799
|
+
* // Select users, with the most recently created
|
|
3800
|
+
* // records coming first.
|
|
3801
|
+
* db.select().from(users)
|
|
3802
|
+
* .orderBy(desc(users.createdAt));
|
|
3803
|
+
* ```
|
|
3804
|
+
*
|
|
3805
|
+
* @see asc to sort in ascending order
|
|
3806
|
+
*/
|
|
3807
|
+
function desc(column) {
|
|
3808
|
+
return sql `${column} desc`;
|
|
3950
3809
|
}
|
|
3951
|
-
// Defined separately from the Column class to resolve circular dependency
|
|
3952
|
-
Column.prototype.getSQL = function () {
|
|
3953
|
-
return new SQL([this]);
|
|
3954
|
-
};
|
|
3955
3810
|
|
|
3956
3811
|
class ColumnAliasProxyHandler {
|
|
3957
3812
|
table;
|
|
@@ -4049,5 +3904,170 @@ function mapColumnsInSQLToAlias(query, alias) {
|
|
|
4049
3904
|
}));
|
|
4050
3905
|
}
|
|
4051
3906
|
|
|
4052
|
-
|
|
4053
|
-
|
|
3907
|
+
exports.BaseName = BaseName;
|
|
3908
|
+
exports.Column = Column;
|
|
3909
|
+
exports.ColumnAliasProxyHandler = ColumnAliasProxyHandler;
|
|
3910
|
+
exports.ColumnBuilder = ColumnBuilder;
|
|
3911
|
+
exports.Columns = Columns;
|
|
3912
|
+
exports.DefaultViewBuilderCore = DefaultViewBuilderCore;
|
|
3913
|
+
exports.DrizzleError = DrizzleError;
|
|
3914
|
+
exports.ExtraConfigBuilder = ExtraConfigBuilder;
|
|
3915
|
+
exports.FakePrimitiveParam = FakePrimitiveParam;
|
|
3916
|
+
exports.ForeignKey = ForeignKey;
|
|
3917
|
+
exports.ForeignKeyBuilder = ForeignKeyBuilder;
|
|
3918
|
+
exports.InlineForeignKeys = InlineForeignKeys;
|
|
3919
|
+
exports.IsAlias = IsAlias;
|
|
3920
|
+
exports.ManualMaterializedViewBuilder = ManualMaterializedViewBuilder;
|
|
3921
|
+
exports.ManualViewBuilder = ManualViewBuilder;
|
|
3922
|
+
exports.Many = Many;
|
|
3923
|
+
exports.MaterializedViewBuilder = MaterializedViewBuilder;
|
|
3924
|
+
exports.MaterializedViewBuilderCore = MaterializedViewBuilderCore;
|
|
3925
|
+
exports.Name = Name;
|
|
3926
|
+
exports.One = One;
|
|
3927
|
+
exports.OriginalName = OriginalName;
|
|
3928
|
+
exports.Param = Param;
|
|
3929
|
+
exports.PgArray = PgArray;
|
|
3930
|
+
exports.PgArrayBuilder = PgArrayBuilder;
|
|
3931
|
+
exports.PgColumn = PgColumn;
|
|
3932
|
+
exports.PgColumnBuilder = PgColumnBuilder;
|
|
3933
|
+
exports.PgDate = PgDate;
|
|
3934
|
+
exports.PgDateBuilder = PgDateBuilder;
|
|
3935
|
+
exports.PgDateString = PgDateString;
|
|
3936
|
+
exports.PgDateStringBuilder = PgDateStringBuilder;
|
|
3937
|
+
exports.PgDialect = PgDialect;
|
|
3938
|
+
exports.PgJson = PgJson;
|
|
3939
|
+
exports.PgJsonBuilder = PgJsonBuilder;
|
|
3940
|
+
exports.PgJsonb = PgJsonb;
|
|
3941
|
+
exports.PgJsonbBuilder = PgJsonbBuilder;
|
|
3942
|
+
exports.PgMaterializedView = PgMaterializedView;
|
|
3943
|
+
exports.PgMaterializedViewConfig = PgMaterializedViewConfig;
|
|
3944
|
+
exports.PgNumeric = PgNumeric;
|
|
3945
|
+
exports.PgNumericBuilder = PgNumericBuilder;
|
|
3946
|
+
exports.PgSelectBase = PgSelectBase;
|
|
3947
|
+
exports.PgSelectBuilder = PgSelectBuilder;
|
|
3948
|
+
exports.PgSelectQueryBuilderBase = PgSelectQueryBuilderBase;
|
|
3949
|
+
exports.PgTable = PgTable;
|
|
3950
|
+
exports.PgTime = PgTime;
|
|
3951
|
+
exports.PgTimeBuilder = PgTimeBuilder;
|
|
3952
|
+
exports.PgTimestamp = PgTimestamp;
|
|
3953
|
+
exports.PgTimestampBuilder = PgTimestampBuilder;
|
|
3954
|
+
exports.PgTimestampString = PgTimestampString;
|
|
3955
|
+
exports.PgTimestampStringBuilder = PgTimestampStringBuilder;
|
|
3956
|
+
exports.PgUUID = PgUUID;
|
|
3957
|
+
exports.PgUUIDBuilder = PgUUIDBuilder;
|
|
3958
|
+
exports.PgView = PgView;
|
|
3959
|
+
exports.PgViewBase = PgViewBase;
|
|
3960
|
+
exports.PgViewConfig = PgViewConfig;
|
|
3961
|
+
exports.Placeholder = Placeholder;
|
|
3962
|
+
exports.PrimaryKey = PrimaryKey;
|
|
3963
|
+
exports.PrimaryKeyBuilder = PrimaryKeyBuilder;
|
|
3964
|
+
exports.QueryBuilder = QueryBuilder;
|
|
3965
|
+
exports.QueryPromise = QueryPromise;
|
|
3966
|
+
exports.Relation = Relation;
|
|
3967
|
+
exports.RelationTableAliasProxyHandler = RelationTableAliasProxyHandler;
|
|
3968
|
+
exports.Relations = Relations;
|
|
3969
|
+
exports.SQL = SQL;
|
|
3970
|
+
exports.Schema = Schema;
|
|
3971
|
+
exports.SelectionProxyHandler = SelectionProxyHandler;
|
|
3972
|
+
exports.StringChunk = StringChunk;
|
|
3973
|
+
exports.Subquery = Subquery;
|
|
3974
|
+
exports.SubqueryConfig = SubqueryConfig;
|
|
3975
|
+
exports.Table = Table;
|
|
3976
|
+
exports.TableAliasProxyHandler = TableAliasProxyHandler;
|
|
3977
|
+
exports.TableName = TableName;
|
|
3978
|
+
exports.TransactionRollbackError = TransactionRollbackError;
|
|
3979
|
+
exports.TypedQueryBuilder = TypedQueryBuilder;
|
|
3980
|
+
exports.UniqueConstraint = UniqueConstraint;
|
|
3981
|
+
exports.UniqueConstraintBuilder = UniqueConstraintBuilder;
|
|
3982
|
+
exports.UniqueOnConstraintBuilder = UniqueOnConstraintBuilder;
|
|
3983
|
+
exports.View = View;
|
|
3984
|
+
exports.ViewBaseConfig = ViewBaseConfig;
|
|
3985
|
+
exports.ViewBuilder = ViewBuilder;
|
|
3986
|
+
exports.WithSubquery = WithSubquery;
|
|
3987
|
+
exports.aliasedRelation = aliasedRelation;
|
|
3988
|
+
exports.aliasedTable = aliasedTable;
|
|
3989
|
+
exports.aliasedTableColumn = aliasedTableColumn;
|
|
3990
|
+
exports.and = and;
|
|
3991
|
+
exports.applyMixins = applyMixins;
|
|
3992
|
+
exports.arrayContained = arrayContained;
|
|
3993
|
+
exports.arrayContains = arrayContains;
|
|
3994
|
+
exports.arrayOverlaps = arrayOverlaps;
|
|
3995
|
+
exports.asc = asc;
|
|
3996
|
+
exports.between = between;
|
|
3997
|
+
exports.bindIfParam = bindIfParam;
|
|
3998
|
+
exports.createMany = createMany;
|
|
3999
|
+
exports.createOne = createOne;
|
|
4000
|
+
exports.createTableRelationsHelpers = createTableRelationsHelpers;
|
|
4001
|
+
exports.date = date;
|
|
4002
|
+
exports.decimal = decimal;
|
|
4003
|
+
exports.desc = desc;
|
|
4004
|
+
exports.entityKind = entityKind;
|
|
4005
|
+
exports.eq = eq;
|
|
4006
|
+
exports.exists = exists;
|
|
4007
|
+
exports.extractTablesRelationalConfig = extractTablesRelationalConfig;
|
|
4008
|
+
exports.fillPlaceholders = fillPlaceholders;
|
|
4009
|
+
exports.foreignKey = foreignKey;
|
|
4010
|
+
exports.getOperators = getOperators;
|
|
4011
|
+
exports.getOrderByOperators = getOrderByOperators;
|
|
4012
|
+
exports.getTableColumns = getTableColumns;
|
|
4013
|
+
exports.getTableLikeName = getTableLikeName;
|
|
4014
|
+
exports.getTableName = getTableName;
|
|
4015
|
+
exports.gt = gt;
|
|
4016
|
+
exports.gte = gte;
|
|
4017
|
+
exports.hasOwnEntityKind = hasOwnEntityKind;
|
|
4018
|
+
exports.iife = iife;
|
|
4019
|
+
exports.ilike = ilike;
|
|
4020
|
+
exports.inArray = inArray;
|
|
4021
|
+
exports.is = is;
|
|
4022
|
+
exports.isDriverValueEncoder = isDriverValueEncoder;
|
|
4023
|
+
exports.isNotNull = isNotNull;
|
|
4024
|
+
exports.isNull = isNull;
|
|
4025
|
+
exports.isSQLWrapper = isSQLWrapper;
|
|
4026
|
+
exports.isTable = isTable;
|
|
4027
|
+
exports.json = json;
|
|
4028
|
+
exports.jsonb = jsonb;
|
|
4029
|
+
exports.like = like;
|
|
4030
|
+
exports.lt = lt;
|
|
4031
|
+
exports.lte = lte;
|
|
4032
|
+
exports.makePgArray = makePgArray;
|
|
4033
|
+
exports.mapColumnsInAliasedSQLToAlias = mapColumnsInAliasedSQLToAlias;
|
|
4034
|
+
exports.mapColumnsInSQLToAlias = mapColumnsInSQLToAlias;
|
|
4035
|
+
exports.mapRelationalRow = mapRelationalRow;
|
|
4036
|
+
exports.mapResultRow = mapResultRow;
|
|
4037
|
+
exports.mapUpdateSet = mapUpdateSet;
|
|
4038
|
+
exports.name = name;
|
|
4039
|
+
exports.ne = ne;
|
|
4040
|
+
exports.noopDecoder = noopDecoder;
|
|
4041
|
+
exports.noopEncoder = noopEncoder;
|
|
4042
|
+
exports.noopMapper = noopMapper;
|
|
4043
|
+
exports.normalizeRelation = normalizeRelation;
|
|
4044
|
+
exports.not = not;
|
|
4045
|
+
exports.notBetween = notBetween;
|
|
4046
|
+
exports.notExists = notExists;
|
|
4047
|
+
exports.notIlike = notIlike;
|
|
4048
|
+
exports.notInArray = notInArray;
|
|
4049
|
+
exports.notLike = notLike;
|
|
4050
|
+
exports.numeric = numeric;
|
|
4051
|
+
exports.or = or;
|
|
4052
|
+
exports.orderSelectedFields = orderSelectedFields;
|
|
4053
|
+
exports.param = param;
|
|
4054
|
+
exports.parsePgArray = parsePgArray;
|
|
4055
|
+
exports.parsePgNestedArray = parsePgNestedArray;
|
|
4056
|
+
exports.pgMaterializedView = pgMaterializedView;
|
|
4057
|
+
exports.pgMaterializedViewWithSchema = pgMaterializedViewWithSchema;
|
|
4058
|
+
exports.pgTable = pgTable;
|
|
4059
|
+
exports.pgTableCreator = pgTableCreator;
|
|
4060
|
+
exports.pgTableWithSchema = pgTableWithSchema;
|
|
4061
|
+
exports.pgView = pgView;
|
|
4062
|
+
exports.pgViewWithSchema = pgViewWithSchema;
|
|
4063
|
+
exports.placeholder = placeholder;
|
|
4064
|
+
exports.primaryKey = primaryKey;
|
|
4065
|
+
exports.relations = relations;
|
|
4066
|
+
exports.sql = sql;
|
|
4067
|
+
exports.time = time;
|
|
4068
|
+
exports.timestamp = timestamp;
|
|
4069
|
+
exports.tracer = tracer;
|
|
4070
|
+
exports.unique = unique;
|
|
4071
|
+
exports.uniqueKeyName = uniqueKeyName;
|
|
4072
|
+
exports.uuid = uuid;
|
|
4073
|
+
//# sourceMappingURL=alias-aa343af5.cjs.map
|