drizzle-orm 0.26.1 → 0.26.2-83ca12d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -0
- package/aws-data-api/pg/index.cjs +8 -7
- package/aws-data-api/pg/index.cjs.map +1 -1
- package/aws-data-api/pg/index.d.ts +65 -6
- package/aws-data-api/pg/index.mjs +18 -3
- package/aws-data-api/pg/index.mjs.map +1 -1
- package/aws-data-api/pg/migrator.d.ts +5 -5
- package/better-sqlite3/index.cjs +9 -8
- package/better-sqlite3/index.cjs.map +1 -1
- package/better-sqlite3/index.d.ts +5 -5
- package/better-sqlite3/index.mjs +13 -3
- package/better-sqlite3/index.mjs.map +1 -1
- package/better-sqlite3/migrator.d.ts +5 -5
- package/bun-sqlite/index.cjs +9 -8
- package/bun-sqlite/index.cjs.map +1 -1
- package/bun-sqlite/index.d.ts +5 -5
- package/bun-sqlite/index.mjs +13 -3
- package/bun-sqlite/index.mjs.map +1 -1
- package/bun-sqlite/migrator.d.ts +5 -5
- package/{column.d-c31e7ad3.d.ts → column.d-66a08b85.d.ts} +2 -1
- package/d1/index.cjs +9 -8
- package/d1/index.cjs.map +1 -1
- package/d1/index.d.ts +5 -5
- package/d1/index.mjs +14 -3
- package/d1/index.mjs.map +1 -1
- package/d1/migrator.d.ts +5 -5
- package/{db.d-132f4f67.d.ts → db.d-7539956f.d.ts} +4 -4
- package/{db.d-2eb7c122.d.ts → db.d-89e25221.d.ts} +4 -5
- package/{driver.d-5c39be67.d.ts → driver.d-1904bc39.d.ts} +2 -2
- package/{driver.d-86800af3.d.ts → driver.d-1d2954cc.d.ts} +2 -2
- package/{driver.d-c201cb6c.d.ts → driver.d-238b678e.d.ts} +2 -2
- package/{driver.d-0d0a6cb7.d.ts → driver.d-33a2c54d.d.ts} +2 -2
- package/{driver.d-323f603a.d.ts → driver.d-8de27d05.d.ts} +2 -2
- package/{driver.d-4469f445.d.ts → driver.d-d334afe8.d.ts} +2 -2
- package/index.cjs +37 -10
- package/index.cjs.map +1 -1
- package/index.d.ts +4 -4
- package/index.mjs +33 -2
- package/index.mjs.map +1 -1
- package/knex/index.d.ts +1 -1
- package/kysely/index.d.ts +1 -1
- package/libsql/index.cjs +9 -8
- package/libsql/index.cjs.map +1 -1
- package/libsql/index.d.ts +5 -5
- package/libsql/index.mjs +16 -3
- package/libsql/index.mjs.map +1 -1
- package/libsql/migrator.d.ts +5 -5
- package/mysql-core/index.cjs +3 -2
- package/mysql-core/index.cjs.map +1 -1
- package/mysql-core/index.d.ts +5 -5
- package/mysql-core/index.mjs +50 -67
- package/mysql-core/index.mjs.map +1 -1
- package/mysql2/index.cjs +9 -8
- package/mysql2/index.cjs.map +1 -1
- package/mysql2/index.d.ts +61 -7
- package/mysql2/index.mjs +18 -3
- package/mysql2/index.mjs.map +1 -1
- package/mysql2/migrator.d.ts +5 -5
- package/neon-serverless/index.cjs +9 -8
- package/neon-serverless/index.cjs.map +1 -1
- package/neon-serverless/index.d.ts +56 -6
- package/neon-serverless/index.mjs +18 -3
- package/neon-serverless/index.mjs.map +1 -1
- package/neon-serverless/migrator.d.ts +5 -5
- package/node-postgres/index.cjs +49 -38
- package/node-postgres/index.cjs.map +1 -1
- package/node-postgres/index.d.ts +53 -6
- package/node-postgres/index.mjs +58 -33
- package/node-postgres/index.mjs.map +1 -1
- package/node-postgres/migrator.d.ts +5 -5
- package/package-1b949c2d.mjs +4 -0
- package/package-1b949c2d.mjs.map +1 -0
- package/package-b95b1bef.cjs +6 -0
- package/package-b95b1bef.cjs.map +1 -0
- package/package.json +31 -230
- package/pg-core/index.cjs +3 -2
- package/pg-core/index.cjs.map +1 -1
- package/pg-core/index.d.ts +5 -5
- package/pg-core/index.mjs +38 -48
- package/pg-core/index.mjs.map +1 -1
- package/planetscale-serverless/index.cjs +9 -8
- package/planetscale-serverless/index.cjs.map +1 -1
- package/planetscale-serverless/index.d.ts +53 -6
- package/planetscale-serverless/index.mjs +17 -5
- package/planetscale-serverless/index.mjs.map +1 -1
- package/planetscale-serverless/migrator.d.ts +5 -5
- package/postgres-js/index.cjs +50 -26
- package/postgres-js/index.cjs.map +1 -1
- package/postgres-js/index.d.ts +46 -6
- package/postgres-js/index.mjs +56 -21
- package/postgres-js/index.mjs.map +1 -1
- package/postgres-js/migrator.d.ts +5 -5
- package/{query-promise.d-3b15626b.d.ts → query-promise.d-afecc38e.d.ts} +2 -2
- package/{relations-23963f0c.cjs → relations-01342313.cjs} +179 -122
- package/relations-01342313.cjs.map +1 -0
- package/{relations-c9e54a8f.mjs → relations-d3070559.mjs} +361 -213
- package/relations-d3070559.mjs.map +1 -0
- package/{select.types.d-34d7f74e.d.ts → select.types.d-1bd49d37.d.ts} +1 -1
- package/{select.types.d-75d13797.d.ts → select.types.d-2d1036d9.d.ts} +3 -3
- package/{session-5f4fc058.mjs → session-108d31ca.mjs} +94 -34
- package/session-108d31ca.mjs.map +1 -0
- package/{session-1beef0bc.mjs → session-3d76708c.mjs} +132 -73
- package/session-3d76708c.mjs.map +1 -0
- package/{session-9c287b9e.cjs → session-6af58e96.cjs} +43 -25
- package/session-6af58e96.cjs.map +1 -0
- package/{session-f1dcefd2.mjs → session-6d53d1de.mjs} +128 -73
- package/session-6d53d1de.mjs.map +1 -0
- package/{session-ce54b9a2.cjs → session-b33c29a1.cjs} +6 -4
- package/session-b33c29a1.cjs.map +1 -0
- package/{session-eb0100ab.cjs → session-f555a31e.cjs} +3 -2
- package/session-f555a31e.cjs.map +1 -0
- package/sql-js/index.cjs +9 -8
- package/sql-js/index.cjs.map +1 -1
- package/sql-js/index.d.ts +5 -5
- package/sql-js/index.mjs +14 -3
- package/sql-js/index.mjs.map +1 -1
- package/sql-js/migrator.d.ts +5 -5
- package/sqlite-core/index.cjs +6 -3
- package/sqlite-core/index.cjs.map +1 -1
- package/sqlite-core/index.d.ts +13 -7
- package/sqlite-core/index.mjs +44 -17
- package/sqlite-core/index.mjs.map +1 -1
- package/sqlite-proxy/index.cjs +13 -12
- package/sqlite-proxy/index.cjs.map +1 -1
- package/sqlite-proxy/index.d.ts +6 -6
- package/sqlite-proxy/index.mjs +16 -7
- package/sqlite-proxy/index.mjs.map +1 -1
- package/sqlite-proxy/migrator.cjs +2 -1
- package/sqlite-proxy/migrator.cjs.map +1 -1
- package/sqlite-proxy/migrator.d.ts +5 -5
- package/sqlite-proxy/migrator.mjs +2 -1
- package/sqlite-proxy/migrator.mjs.map +1 -1
- package/vercel-postgres/index.cjs +9 -8
- package/vercel-postgres/index.cjs.map +1 -1
- package/vercel-postgres/index.d.ts +56 -6
- package/vercel-postgres/index.mjs +18 -3
- package/vercel-postgres/index.mjs.map +1 -1
- package/vercel-postgres/migrator.d.ts +5 -5
- package/version.cjs +2 -2
- package/version.d.ts +1 -1
- package/version.mjs +2 -2
- package/driver.d-19470274.d.ts +0 -46
- package/driver.d-24f23dda.d.ts +0 -52
- package/driver.d-27ec30dc.d.ts +0 -64
- package/driver.d-2880f5a4.d.ts +0 -55
- package/driver.d-2c6c28d2.d.ts +0 -55
- package/driver.d-6fb29dde.d.ts +0 -55
- package/driver.d-f3926c10.d.ts +0 -60
- package/logger-caa1ca6e.cjs +0 -34
- package/logger-caa1ca6e.cjs.map +0 -1
- package/logger-caf75bde.mjs +0 -30
- package/logger-caf75bde.mjs.map +0 -1
- package/relations-23963f0c.cjs.map +0 -1
- package/relations-c9e54a8f.mjs.map +0 -1
- package/session-1beef0bc.mjs.map +0 -1
- package/session-5f4fc058.mjs.map +0 -1
- package/session-9c287b9e.cjs.map +0 -1
- package/session-ce54b9a2.cjs.map +0 -1
- package/session-eb0100ab.cjs.map +0 -1
- package/session-f1dcefd2.mjs.map +0 -1
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import { v as version } from './package-1b949c2d.mjs';
|
|
2
|
+
|
|
1
3
|
/*
|
|
2
4
|
`Column` only accepts a full `ColumnConfig` as its generic.
|
|
3
5
|
To infer parts of the config, use `AnyColumn` that accepts a partial config.
|
|
4
6
|
See `GetColumnData` for example usage of inferring.
|
|
5
7
|
*/
|
|
6
8
|
class Column {
|
|
9
|
+
table;
|
|
10
|
+
name;
|
|
11
|
+
primary;
|
|
12
|
+
notNull;
|
|
13
|
+
default;
|
|
14
|
+
hasDefault;
|
|
15
|
+
config;
|
|
7
16
|
constructor(table, config) {
|
|
8
17
|
this.table = table;
|
|
9
18
|
this.config = config;
|
|
@@ -23,6 +32,8 @@ class Column {
|
|
|
23
32
|
|
|
24
33
|
const ViewBaseConfig = Symbol('ViewBaseConfig');
|
|
25
34
|
class View {
|
|
35
|
+
/** @internal */
|
|
36
|
+
[ViewBaseConfig];
|
|
26
37
|
constructor({ name, schema, selectedFields, query }) {
|
|
27
38
|
this[ViewBaseConfig] = {
|
|
28
39
|
name,
|
|
@@ -38,6 +49,8 @@ class View {
|
|
|
38
49
|
|
|
39
50
|
const SubqueryConfig = Symbol('SubqueryConfig');
|
|
40
51
|
class Subquery {
|
|
52
|
+
/** @internal */
|
|
53
|
+
[SubqueryConfig];
|
|
41
54
|
constructor(sql, selection, alias, isWith = false) {
|
|
42
55
|
this[SubqueryConfig] = {
|
|
43
56
|
sql,
|
|
@@ -50,6 +63,7 @@ class Subquery {
|
|
|
50
63
|
class WithSubquery extends Subquery {
|
|
51
64
|
}
|
|
52
65
|
class SelectionProxyHandler {
|
|
66
|
+
config;
|
|
53
67
|
constructor(config) {
|
|
54
68
|
this.config = { ...config };
|
|
55
69
|
}
|
|
@@ -103,7 +117,6 @@ class SelectionProxyHandler {
|
|
|
103
117
|
}
|
|
104
118
|
}
|
|
105
119
|
|
|
106
|
-
var _a$2, _b$1, _c;
|
|
107
120
|
/** @internal */
|
|
108
121
|
const TableName = Symbol('Name');
|
|
109
122
|
/** @internal */
|
|
@@ -120,28 +133,46 @@ const IsAlias = Symbol('IsAlias');
|
|
|
120
133
|
const ExtraConfigBuilder = Symbol('ExtraConfigBuilder');
|
|
121
134
|
const IsDrizzleTable = Symbol.for('IsDrizzleTable');
|
|
122
135
|
class Table {
|
|
136
|
+
/** @internal */
|
|
137
|
+
static Symbol = {
|
|
138
|
+
Name: TableName,
|
|
139
|
+
Schema: Schema,
|
|
140
|
+
OriginalName: OriginalName,
|
|
141
|
+
Columns: Columns,
|
|
142
|
+
BaseName: BaseName,
|
|
143
|
+
IsAlias: IsAlias,
|
|
144
|
+
ExtraConfigBuilder: ExtraConfigBuilder,
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* @internal
|
|
148
|
+
* Can be changed if the table is aliased.
|
|
149
|
+
*/
|
|
150
|
+
[TableName];
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
* Used to store the original name of the table, before any aliasing.
|
|
154
|
+
*/
|
|
155
|
+
[OriginalName];
|
|
156
|
+
/** @internal */
|
|
157
|
+
[Schema];
|
|
158
|
+
/** @internal */
|
|
159
|
+
[Columns];
|
|
160
|
+
/**
|
|
161
|
+
* @internal
|
|
162
|
+
* Used to store the table name before the transformation via the `tableCreator` functions.
|
|
163
|
+
*/
|
|
164
|
+
[BaseName];
|
|
165
|
+
/** @internal */
|
|
166
|
+
[IsAlias] = false;
|
|
167
|
+
/** @internal */
|
|
168
|
+
[ExtraConfigBuilder] = undefined;
|
|
169
|
+
[IsDrizzleTable] = true;
|
|
123
170
|
constructor(name, schema, baseName) {
|
|
124
|
-
/** @internal */
|
|
125
|
-
this[_a$2] = false;
|
|
126
|
-
/** @internal */
|
|
127
|
-
this[_b$1] = undefined;
|
|
128
|
-
this[_c] = true;
|
|
129
171
|
this[TableName] = this[OriginalName] = name;
|
|
130
172
|
this[Schema] = schema;
|
|
131
173
|
this[BaseName] = baseName;
|
|
132
174
|
}
|
|
133
175
|
}
|
|
134
|
-
_a$2 = IsAlias, _b$1 = ExtraConfigBuilder, _c = IsDrizzleTable;
|
|
135
|
-
/** @internal */
|
|
136
|
-
Table.Symbol = {
|
|
137
|
-
Name: TableName,
|
|
138
|
-
Schema: Schema,
|
|
139
|
-
OriginalName: OriginalName,
|
|
140
|
-
Columns: Columns,
|
|
141
|
-
BaseName: BaseName,
|
|
142
|
-
IsAlias: IsAlias,
|
|
143
|
-
ExtraConfigBuilder: ExtraConfigBuilder,
|
|
144
|
-
};
|
|
145
176
|
function isTable(table) {
|
|
146
177
|
return typeof table === 'object' && table !== null && IsDrizzleTable in table;
|
|
147
178
|
}
|
|
@@ -149,6 +180,158 @@ function getTableName(table) {
|
|
|
149
180
|
return table[TableName];
|
|
150
181
|
}
|
|
151
182
|
|
|
183
|
+
/** @internal */
|
|
184
|
+
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
185
|
+
// Key -> nested object key, value -> table name if all fields in the nested object are from the same table, false otherwise
|
|
186
|
+
const nullifyMap = {};
|
|
187
|
+
const result = columns.reduce((result, { path, field }, columnIndex) => {
|
|
188
|
+
let decoder;
|
|
189
|
+
if (field instanceof Column) {
|
|
190
|
+
decoder = field;
|
|
191
|
+
}
|
|
192
|
+
else if (field instanceof SQL) {
|
|
193
|
+
decoder = field.decoder;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
decoder = field.sql.decoder;
|
|
197
|
+
}
|
|
198
|
+
let node = result;
|
|
199
|
+
for (const [pathChunkIndex, pathChunk] of path.entries()) {
|
|
200
|
+
if (pathChunkIndex < path.length - 1) {
|
|
201
|
+
if (!(pathChunk in node)) {
|
|
202
|
+
node[pathChunk] = {};
|
|
203
|
+
}
|
|
204
|
+
node = node[pathChunk];
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
const rawValue = row[columnIndex];
|
|
208
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
209
|
+
if (joinsNotNullableMap && field instanceof Column && path.length === 2) {
|
|
210
|
+
const objectName = path[0];
|
|
211
|
+
if (!(objectName in nullifyMap)) {
|
|
212
|
+
nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
213
|
+
}
|
|
214
|
+
else if (typeof nullifyMap[objectName] === 'string' && nullifyMap[objectName] !== getTableName(field.table)) {
|
|
215
|
+
nullifyMap[objectName] = false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return result;
|
|
221
|
+
}, {});
|
|
222
|
+
// Nullify all nested objects from nullifyMap that are nullable
|
|
223
|
+
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
224
|
+
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
|
|
225
|
+
if (typeof tableName === 'string' && !joinsNotNullableMap[tableName]) {
|
|
226
|
+
result[objectName] = null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
/** @internal */
|
|
233
|
+
function orderSelectedFields(fields, pathPrefix) {
|
|
234
|
+
return Object.entries(fields).reduce((result, [name, field]) => {
|
|
235
|
+
if (typeof name !== 'string') {
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
const newPath = pathPrefix ? [...pathPrefix, name] : [name];
|
|
239
|
+
if (field instanceof Column
|
|
240
|
+
|| field instanceof SQL
|
|
241
|
+
|| field instanceof SQL.Aliased) {
|
|
242
|
+
result.push({ path: newPath, field });
|
|
243
|
+
}
|
|
244
|
+
else if (field instanceof Table) {
|
|
245
|
+
result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
result.push(...orderSelectedFields(field, newPath));
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}, []);
|
|
252
|
+
}
|
|
253
|
+
/** @internal */
|
|
254
|
+
function mapUpdateSet(table, values) {
|
|
255
|
+
const entries = Object.entries(values)
|
|
256
|
+
.filter(([, value]) => value !== undefined)
|
|
257
|
+
.map(([key, value]) => {
|
|
258
|
+
// eslint-disable-next-line unicorn/prefer-ternary
|
|
259
|
+
if (value instanceof SQL) {
|
|
260
|
+
return [key, value];
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
return [key, new Param(value, table[Table.Symbol.Columns][key])];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
if (entries.length === 0) {
|
|
267
|
+
throw new Error('No values to set');
|
|
268
|
+
}
|
|
269
|
+
return Object.fromEntries(entries);
|
|
270
|
+
}
|
|
271
|
+
/** @internal */
|
|
272
|
+
function applyMixins(baseClass, extendedClasses) {
|
|
273
|
+
for (const extendedClass of extendedClasses) {
|
|
274
|
+
for (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
275
|
+
Object.defineProperty(baseClass.prototype, name, Object.getOwnPropertyDescriptor(extendedClass.prototype, name) || Object.create(null));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function getTableColumns(table) {
|
|
280
|
+
return table[Table.Symbol.Columns];
|
|
281
|
+
}
|
|
282
|
+
/** @internal */
|
|
283
|
+
function getTableLikeName(table) {
|
|
284
|
+
return table instanceof Subquery
|
|
285
|
+
? table[SubqueryConfig].alias
|
|
286
|
+
: table instanceof View
|
|
287
|
+
? table[ViewBaseConfig].name
|
|
288
|
+
: table instanceof SQL
|
|
289
|
+
? undefined
|
|
290
|
+
: table[Table.Symbol.IsAlias]
|
|
291
|
+
? table[Table.Symbol.Name]
|
|
292
|
+
: table[Table.Symbol.BaseName];
|
|
293
|
+
}
|
|
294
|
+
function iife(fn, ...args) {
|
|
295
|
+
return fn(...args);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
let otel;
|
|
299
|
+
let rawTracer;
|
|
300
|
+
try {
|
|
301
|
+
otel = await import('@opentelemetry/api');
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/** @internal */
|
|
309
|
+
const tracer = {
|
|
310
|
+
startActiveSpan(name, fn) {
|
|
311
|
+
if (!otel) {
|
|
312
|
+
return fn();
|
|
313
|
+
}
|
|
314
|
+
if (!rawTracer) {
|
|
315
|
+
rawTracer = otel.trace.getTracer('drizzle-orm', version);
|
|
316
|
+
}
|
|
317
|
+
return iife((otel, rawTracer) => rawTracer.startActiveSpan(name, ((span) => {
|
|
318
|
+
try {
|
|
319
|
+
return fn(span);
|
|
320
|
+
}
|
|
321
|
+
catch (e) {
|
|
322
|
+
span.setStatus({
|
|
323
|
+
code: otel.SpanStatusCode.ERROR,
|
|
324
|
+
message: e instanceof Error ? e.message : 'Unknown error',
|
|
325
|
+
});
|
|
326
|
+
throw e;
|
|
327
|
+
}
|
|
328
|
+
finally {
|
|
329
|
+
span.end();
|
|
330
|
+
}
|
|
331
|
+
})), otel, rawTracer);
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
|
|
152
335
|
function bindIfParam(value, column) {
|
|
153
336
|
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !(value instanceof Param) && !(value instanceof Placeholder)
|
|
154
337
|
&& !(value instanceof Column) && !(value instanceof Table) && !(value instanceof View)) {
|
|
@@ -332,7 +515,7 @@ function exists(subquery) {
|
|
|
332
515
|
* @see exists for the inverse of this test
|
|
333
516
|
*/
|
|
334
517
|
function notExists(subquery) {
|
|
335
|
-
return sql `exists (${subquery})`;
|
|
518
|
+
return sql `not exists (${subquery})`;
|
|
336
519
|
}
|
|
337
520
|
function between(column, min, max) {
|
|
338
521
|
return sql `${column} between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
@@ -481,30 +664,40 @@ function mergeQueries(queries) {
|
|
|
481
664
|
for (const query of queries) {
|
|
482
665
|
result.sql += query.sql;
|
|
483
666
|
result.params.push(...query.params);
|
|
484
|
-
if (
|
|
667
|
+
if (query.typings?.length) {
|
|
668
|
+
result.typings = result.typings || [];
|
|
485
669
|
result.typings.push(...query.typings);
|
|
486
670
|
}
|
|
487
671
|
}
|
|
488
672
|
return result;
|
|
489
673
|
}
|
|
490
674
|
class StringChunk {
|
|
675
|
+
value;
|
|
491
676
|
constructor(value) {
|
|
492
677
|
this.value = Array.isArray(value) ? value : [value];
|
|
493
678
|
}
|
|
494
679
|
}
|
|
495
680
|
class SQL {
|
|
681
|
+
queryChunks;
|
|
682
|
+
/** @internal */
|
|
683
|
+
decoder = noopDecoder;
|
|
684
|
+
shouldInlineParams = false;
|
|
496
685
|
constructor(queryChunks) {
|
|
497
686
|
this.queryChunks = queryChunks;
|
|
498
|
-
/** @internal */
|
|
499
|
-
this.decoder = noopDecoder;
|
|
500
|
-
this.shouldInlineParams = false;
|
|
501
687
|
}
|
|
502
688
|
append(query) {
|
|
503
689
|
this.queryChunks.push(...query.queryChunks);
|
|
504
690
|
return this;
|
|
505
691
|
}
|
|
506
692
|
toQuery(config) {
|
|
507
|
-
return
|
|
693
|
+
return tracer.startActiveSpan('drizzle.buildSQL', (span) => {
|
|
694
|
+
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
695
|
+
span?.setAttributes({
|
|
696
|
+
'drizzle.query.text': query.sql,
|
|
697
|
+
'drizzle.query.params': JSON.stringify(query.params),
|
|
698
|
+
});
|
|
699
|
+
return query;
|
|
700
|
+
});
|
|
508
701
|
}
|
|
509
702
|
buildQueryFromSourceParams(chunks, _config) {
|
|
510
703
|
const config = Object.assign({}, _config, {
|
|
@@ -652,6 +845,8 @@ class SQL {
|
|
|
652
845
|
* Any DB name (table, column, index etc.)
|
|
653
846
|
*/
|
|
654
847
|
class Name {
|
|
848
|
+
value;
|
|
849
|
+
brand;
|
|
655
850
|
constructor(value) {
|
|
656
851
|
this.value = value;
|
|
657
852
|
}
|
|
@@ -679,6 +874,9 @@ const noopMapper = {
|
|
|
679
874
|
};
|
|
680
875
|
/** Parameter value that is optionally bound to an encoder (for example, a column). */
|
|
681
876
|
class Param {
|
|
877
|
+
value;
|
|
878
|
+
encoder;
|
|
879
|
+
brand;
|
|
682
880
|
/**
|
|
683
881
|
* @param value - Parameter value
|
|
684
882
|
* @param encoder - Encoder to convert the value to a driver parameter
|
|
@@ -749,11 +947,13 @@ function sql(strings, ...params) {
|
|
|
749
947
|
})(sql || (sql = {}));
|
|
750
948
|
(function (SQL) {
|
|
751
949
|
class Aliased {
|
|
950
|
+
sql;
|
|
951
|
+
fieldAlias;
|
|
952
|
+
/** @internal */
|
|
953
|
+
isSelectionField = false;
|
|
752
954
|
constructor(sql, fieldAlias) {
|
|
753
955
|
this.sql = sql;
|
|
754
956
|
this.fieldAlias = fieldAlias;
|
|
755
|
-
/** @internal */
|
|
756
|
-
this.isSelectionField = false;
|
|
757
957
|
}
|
|
758
958
|
getSQL() {
|
|
759
959
|
return this.sql;
|
|
@@ -766,6 +966,7 @@ function sql(strings, ...params) {
|
|
|
766
966
|
SQL.Aliased = Aliased;
|
|
767
967
|
})(SQL || (SQL = {}));
|
|
768
968
|
class Placeholder {
|
|
969
|
+
name;
|
|
769
970
|
constructor(name) {
|
|
770
971
|
this.name = name;
|
|
771
972
|
}
|
|
@@ -786,6 +987,7 @@ function fillPlaceholders(params, values) {
|
|
|
786
987
|
}
|
|
787
988
|
|
|
788
989
|
class ColumnAliasProxyHandler {
|
|
990
|
+
table;
|
|
789
991
|
constructor(table) {
|
|
790
992
|
this.table = table;
|
|
791
993
|
}
|
|
@@ -797,6 +999,8 @@ class ColumnAliasProxyHandler {
|
|
|
797
999
|
}
|
|
798
1000
|
}
|
|
799
1001
|
class TableAliasProxyHandler {
|
|
1002
|
+
alias;
|
|
1003
|
+
replaceOriginalName;
|
|
800
1004
|
constructor(alias, replaceOriginalName) {
|
|
801
1005
|
this.alias = alias;
|
|
802
1006
|
this.replaceOriginalName = replaceOriginalName;
|
|
@@ -837,6 +1041,7 @@ class TableAliasProxyHandler {
|
|
|
837
1041
|
}
|
|
838
1042
|
}
|
|
839
1043
|
class RelationTableAliasProxyHandler {
|
|
1044
|
+
alias;
|
|
840
1045
|
constructor(alias) {
|
|
841
1046
|
this.alias = alias;
|
|
842
1047
|
}
|
|
@@ -876,6 +1081,7 @@ function mapColumnsInSQLToAlias(query, alias) {
|
|
|
876
1081
|
|
|
877
1082
|
// To understand how to use `ColumnBuilder` and `AnyColumnBuilder`, see `Column` and `AnyColumn` documentation.
|
|
878
1083
|
class ColumnBuilder {
|
|
1084
|
+
config;
|
|
879
1085
|
constructor(name) {
|
|
880
1086
|
this.config = {
|
|
881
1087
|
name,
|
|
@@ -903,11 +1109,8 @@ class ColumnBuilder {
|
|
|
903
1109
|
}
|
|
904
1110
|
}
|
|
905
1111
|
|
|
906
|
-
var _a$1;
|
|
907
1112
|
class QueryPromise {
|
|
908
|
-
|
|
909
|
-
this[_a$1] = 'QueryPromise';
|
|
910
|
-
}
|
|
1113
|
+
[Symbol.toStringTag] = 'QueryPromise';
|
|
911
1114
|
catch(onRejected) {
|
|
912
1115
|
return this.then(undefined, onRejected);
|
|
913
1116
|
}
|
|
@@ -924,9 +1127,11 @@ class QueryPromise {
|
|
|
924
1127
|
return this.execute().then(onFulfilled, onRejected);
|
|
925
1128
|
}
|
|
926
1129
|
}
|
|
927
|
-
_a$1 = Symbol.toStringTag;
|
|
928
1130
|
|
|
929
1131
|
class CheckBuilder {
|
|
1132
|
+
name;
|
|
1133
|
+
value;
|
|
1134
|
+
brand;
|
|
930
1135
|
constructor(name, value) {
|
|
931
1136
|
this.name = name;
|
|
932
1137
|
this.value = value;
|
|
@@ -937,6 +1142,9 @@ class CheckBuilder {
|
|
|
937
1142
|
}
|
|
938
1143
|
}
|
|
939
1144
|
class Check {
|
|
1145
|
+
table;
|
|
1146
|
+
name;
|
|
1147
|
+
value;
|
|
940
1148
|
constructor(table, builder) {
|
|
941
1149
|
this.table = table;
|
|
942
1150
|
this.name = builder.name;
|
|
@@ -947,23 +1155,18 @@ function check(name, value) {
|
|
|
947
1155
|
return new CheckBuilder(name, value);
|
|
948
1156
|
}
|
|
949
1157
|
|
|
950
|
-
var _a, _b;
|
|
951
1158
|
/** @internal */
|
|
952
1159
|
const InlineForeignKeys = Symbol('InlineForeignKeys');
|
|
953
1160
|
class PgTable extends Table {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1161
|
+
/** @internal */
|
|
1162
|
+
static Symbol = Object.assign({}, Table.Symbol, {
|
|
1163
|
+
InlineForeignKeys: InlineForeignKeys,
|
|
1164
|
+
});
|
|
1165
|
+
/**@internal */
|
|
1166
|
+
[InlineForeignKeys] = [];
|
|
1167
|
+
/** @internal */
|
|
1168
|
+
[Table.Symbol.ExtraConfigBuilder] = undefined;
|
|
961
1169
|
}
|
|
962
|
-
_a = InlineForeignKeys, _b = Table.Symbol.ExtraConfigBuilder;
|
|
963
|
-
/** @internal */
|
|
964
|
-
PgTable.Symbol = Object.assign({}, Table.Symbol, {
|
|
965
|
-
InlineForeignKeys: InlineForeignKeys,
|
|
966
|
-
});
|
|
967
1170
|
/** @internal */
|
|
968
1171
|
function pgTableWithSchema(name, columns, extraConfig, schema, baseName = name) {
|
|
969
1172
|
const rawTable = new PgTable(name, schema, baseName);
|
|
@@ -989,11 +1192,13 @@ function pgTableCreator(customizeTableName) {
|
|
|
989
1192
|
}
|
|
990
1193
|
|
|
991
1194
|
class ForeignKeyBuilder {
|
|
1195
|
+
/** @internal */
|
|
1196
|
+
reference;
|
|
1197
|
+
/** @internal */
|
|
1198
|
+
_onUpdate = 'no action';
|
|
1199
|
+
/** @internal */
|
|
1200
|
+
_onDelete = 'no action';
|
|
992
1201
|
constructor(config, actions) {
|
|
993
|
-
/** @internal */
|
|
994
|
-
this._onUpdate = 'no action';
|
|
995
|
-
/** @internal */
|
|
996
|
-
this._onDelete = 'no action';
|
|
997
1202
|
this.reference = () => {
|
|
998
1203
|
const { columns, foreignColumns } = config();
|
|
999
1204
|
return { columns, foreignTable: foreignColumns[0].table, foreignColumns };
|
|
@@ -1017,6 +1222,10 @@ class ForeignKeyBuilder {
|
|
|
1017
1222
|
}
|
|
1018
1223
|
}
|
|
1019
1224
|
class ForeignKey {
|
|
1225
|
+
table;
|
|
1226
|
+
reference;
|
|
1227
|
+
onUpdate;
|
|
1228
|
+
onDelete;
|
|
1020
1229
|
constructor(table, builder) {
|
|
1021
1230
|
this.table = table;
|
|
1022
1231
|
this.reference = builder.reference;
|
|
@@ -1048,6 +1257,8 @@ function foreignKey(config) {
|
|
|
1048
1257
|
}
|
|
1049
1258
|
|
|
1050
1259
|
class IndexBuilderOn {
|
|
1260
|
+
unique;
|
|
1261
|
+
name;
|
|
1051
1262
|
constructor(unique, name) {
|
|
1052
1263
|
this.unique = unique;
|
|
1053
1264
|
this.name = name;
|
|
@@ -1060,6 +1271,8 @@ class IndexBuilderOn {
|
|
|
1060
1271
|
}
|
|
1061
1272
|
}
|
|
1062
1273
|
class IndexBuilder {
|
|
1274
|
+
/** @internal */
|
|
1275
|
+
config;
|
|
1063
1276
|
constructor(columns, unique, only, name) {
|
|
1064
1277
|
this.config = {
|
|
1065
1278
|
name,
|
|
@@ -1102,6 +1315,7 @@ class IndexBuilder {
|
|
|
1102
1315
|
}
|
|
1103
1316
|
}
|
|
1104
1317
|
class Index {
|
|
1318
|
+
config;
|
|
1105
1319
|
constructor(config, table) {
|
|
1106
1320
|
this.config = { ...config, table };
|
|
1107
1321
|
}
|
|
@@ -1117,6 +1331,8 @@ function primaryKey(...columns) {
|
|
|
1117
1331
|
return new PrimaryKeyBuilder(columns);
|
|
1118
1332
|
}
|
|
1119
1333
|
class PrimaryKeyBuilder {
|
|
1334
|
+
/** @internal */
|
|
1335
|
+
columns;
|
|
1120
1336
|
constructor(columns) {
|
|
1121
1337
|
this.columns = columns;
|
|
1122
1338
|
}
|
|
@@ -1126,6 +1342,8 @@ class PrimaryKeyBuilder {
|
|
|
1126
1342
|
}
|
|
1127
1343
|
}
|
|
1128
1344
|
class PrimaryKey {
|
|
1345
|
+
table;
|
|
1346
|
+
columns;
|
|
1129
1347
|
constructor(table, columns) {
|
|
1130
1348
|
this.table = table;
|
|
1131
1349
|
this.columns = columns;
|
|
@@ -1135,118 +1353,6 @@ class PrimaryKey {
|
|
|
1135
1353
|
}
|
|
1136
1354
|
}
|
|
1137
1355
|
|
|
1138
|
-
/** @internal */
|
|
1139
|
-
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
1140
|
-
// Key -> nested object key, value -> table name if all fields in the nested object are from the same table, false otherwise
|
|
1141
|
-
const nullifyMap = {};
|
|
1142
|
-
const result = columns.reduce((result, { path, field }, columnIndex) => {
|
|
1143
|
-
let decoder;
|
|
1144
|
-
if (field instanceof Column) {
|
|
1145
|
-
decoder = field;
|
|
1146
|
-
}
|
|
1147
|
-
else if (field instanceof SQL) {
|
|
1148
|
-
decoder = field.decoder;
|
|
1149
|
-
}
|
|
1150
|
-
else {
|
|
1151
|
-
decoder = field.sql.decoder;
|
|
1152
|
-
}
|
|
1153
|
-
let node = result;
|
|
1154
|
-
for (const [pathChunkIndex, pathChunk] of path.entries()) {
|
|
1155
|
-
if (pathChunkIndex < path.length - 1) {
|
|
1156
|
-
if (!(pathChunk in node)) {
|
|
1157
|
-
node[pathChunk] = {};
|
|
1158
|
-
}
|
|
1159
|
-
node = node[pathChunk];
|
|
1160
|
-
}
|
|
1161
|
-
else {
|
|
1162
|
-
const rawValue = row[columnIndex];
|
|
1163
|
-
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
1164
|
-
if (joinsNotNullableMap && field instanceof Column && path.length === 2) {
|
|
1165
|
-
const objectName = path[0];
|
|
1166
|
-
if (!(objectName in nullifyMap)) {
|
|
1167
|
-
nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
1168
|
-
}
|
|
1169
|
-
else if (typeof nullifyMap[objectName] === 'string' && nullifyMap[objectName] !== getTableName(field.table)) {
|
|
1170
|
-
nullifyMap[objectName] = false;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
return result;
|
|
1176
|
-
}, {});
|
|
1177
|
-
// Nullify all nested objects from nullifyMap that are nullable
|
|
1178
|
-
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
1179
|
-
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
|
|
1180
|
-
if (typeof tableName === 'string' && !joinsNotNullableMap[tableName]) {
|
|
1181
|
-
result[objectName] = null;
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
return result;
|
|
1186
|
-
}
|
|
1187
|
-
/** @internal */
|
|
1188
|
-
function orderSelectedFields(fields, pathPrefix) {
|
|
1189
|
-
return Object.entries(fields).reduce((result, [name, field]) => {
|
|
1190
|
-
if (typeof name !== 'string') {
|
|
1191
|
-
return result;
|
|
1192
|
-
}
|
|
1193
|
-
const newPath = pathPrefix ? [...pathPrefix, name] : [name];
|
|
1194
|
-
if (field instanceof Column
|
|
1195
|
-
|| field instanceof SQL
|
|
1196
|
-
|| field instanceof SQL.Aliased) {
|
|
1197
|
-
result.push({ path: newPath, field });
|
|
1198
|
-
}
|
|
1199
|
-
else if (field instanceof Table) {
|
|
1200
|
-
result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
|
|
1201
|
-
}
|
|
1202
|
-
else {
|
|
1203
|
-
result.push(...orderSelectedFields(field, newPath));
|
|
1204
|
-
}
|
|
1205
|
-
return result;
|
|
1206
|
-
}, []);
|
|
1207
|
-
}
|
|
1208
|
-
/** @internal */
|
|
1209
|
-
function mapUpdateSet(table, values) {
|
|
1210
|
-
const entries = Object.entries(values)
|
|
1211
|
-
.filter(([, value]) => value !== undefined)
|
|
1212
|
-
.map(([key, value]) => {
|
|
1213
|
-
// eslint-disable-next-line unicorn/prefer-ternary
|
|
1214
|
-
if (value instanceof SQL) {
|
|
1215
|
-
return [key, value];
|
|
1216
|
-
}
|
|
1217
|
-
else {
|
|
1218
|
-
return [key, new Param(value, table[Table.Symbol.Columns][key])];
|
|
1219
|
-
}
|
|
1220
|
-
});
|
|
1221
|
-
if (entries.length === 0) {
|
|
1222
|
-
throw new Error('No values to set');
|
|
1223
|
-
}
|
|
1224
|
-
return Object.fromEntries(entries);
|
|
1225
|
-
}
|
|
1226
|
-
/** @internal */
|
|
1227
|
-
function applyMixins(baseClass, extendedClasses) {
|
|
1228
|
-
for (const extendedClass of extendedClasses) {
|
|
1229
|
-
for (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
1230
|
-
Object.defineProperty(baseClass.prototype, name, Object.getOwnPropertyDescriptor(extendedClass.prototype, name) || Object.create(null));
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
function getTableColumns(table) {
|
|
1235
|
-
return table[Table.Symbol.Columns];
|
|
1236
|
-
}
|
|
1237
|
-
/** @internal */
|
|
1238
|
-
function getTableLikeName(table) {
|
|
1239
|
-
return table instanceof Subquery
|
|
1240
|
-
? table[SubqueryConfig].alias
|
|
1241
|
-
: table instanceof View
|
|
1242
|
-
? table[ViewBaseConfig].name
|
|
1243
|
-
: table instanceof SQL
|
|
1244
|
-
? undefined
|
|
1245
|
-
: table[Table.Symbol.IsAlias]
|
|
1246
|
-
? table[Table.Symbol.Name]
|
|
1247
|
-
: table[Table.Symbol.BaseName];
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
1356
|
class PgDialect {
|
|
1251
1357
|
async migrate(migrations, session) {
|
|
1252
1358
|
const migrationTableCreate = sql `
|
|
@@ -1799,6 +1905,10 @@ class TypedQueryBuilder {
|
|
|
1799
1905
|
}
|
|
1800
1906
|
|
|
1801
1907
|
class PgSelectBuilder {
|
|
1908
|
+
fields;
|
|
1909
|
+
session;
|
|
1910
|
+
dialect;
|
|
1911
|
+
withList;
|
|
1802
1912
|
constructor(fields, session, dialect, withList = []) {
|
|
1803
1913
|
this.fields = fields;
|
|
1804
1914
|
this.session = session;
|
|
@@ -1834,40 +1944,18 @@ class PgSelectBuilder {
|
|
|
1834
1944
|
}
|
|
1835
1945
|
}
|
|
1836
1946
|
class PgSelectQueryBuilder extends TypedQueryBuilder {
|
|
1947
|
+
isPartialSelect;
|
|
1948
|
+
session;
|
|
1949
|
+
dialect;
|
|
1950
|
+
_;
|
|
1951
|
+
config;
|
|
1952
|
+
joinsNotNullableMap;
|
|
1953
|
+
tableName;
|
|
1837
1954
|
constructor(table, fields, isPartialSelect, session, dialect, withList) {
|
|
1838
1955
|
super();
|
|
1839
1956
|
this.isPartialSelect = isPartialSelect;
|
|
1840
1957
|
this.session = session;
|
|
1841
1958
|
this.dialect = dialect;
|
|
1842
|
-
/**
|
|
1843
|
-
* For each row of the table, include
|
|
1844
|
-
* values from a matching row of the joined
|
|
1845
|
-
* table, if there is a matching row. If not,
|
|
1846
|
-
* all of the columns of the joined table
|
|
1847
|
-
* will be set to null.
|
|
1848
|
-
*/
|
|
1849
|
-
this.leftJoin = this.createJoin('left');
|
|
1850
|
-
/**
|
|
1851
|
-
* Includes all of the rows of the joined table.
|
|
1852
|
-
* If there is no matching row in the main table,
|
|
1853
|
-
* all the columns of the main table will be
|
|
1854
|
-
* set to null.
|
|
1855
|
-
*/
|
|
1856
|
-
this.rightJoin = this.createJoin('right');
|
|
1857
|
-
/**
|
|
1858
|
-
* This is the default type of join.
|
|
1859
|
-
*
|
|
1860
|
-
* For each row of the table, the joined table
|
|
1861
|
-
* needs to have a matching row, or it will
|
|
1862
|
-
* be excluded from results.
|
|
1863
|
-
*/
|
|
1864
|
-
this.innerJoin = this.createJoin('inner');
|
|
1865
|
-
/**
|
|
1866
|
-
* Rows from both the main & joined are included,
|
|
1867
|
-
* regardless of whether or not they have matching
|
|
1868
|
-
* rows in the other table.
|
|
1869
|
-
*/
|
|
1870
|
-
this.fullJoin = this.createJoin('full');
|
|
1871
1959
|
this.config = {
|
|
1872
1960
|
withList,
|
|
1873
1961
|
table,
|
|
@@ -1935,6 +2023,35 @@ class PgSelectQueryBuilder extends TypedQueryBuilder {
|
|
|
1935
2023
|
return this;
|
|
1936
2024
|
};
|
|
1937
2025
|
}
|
|
2026
|
+
/**
|
|
2027
|
+
* For each row of the table, include
|
|
2028
|
+
* values from a matching row of the joined
|
|
2029
|
+
* table, if there is a matching row. If not,
|
|
2030
|
+
* all of the columns of the joined table
|
|
2031
|
+
* will be set to null.
|
|
2032
|
+
*/
|
|
2033
|
+
leftJoin = this.createJoin('left');
|
|
2034
|
+
/**
|
|
2035
|
+
* Includes all of the rows of the joined table.
|
|
2036
|
+
* If there is no matching row in the main table,
|
|
2037
|
+
* all the columns of the main table will be
|
|
2038
|
+
* set to null.
|
|
2039
|
+
*/
|
|
2040
|
+
rightJoin = this.createJoin('right');
|
|
2041
|
+
/**
|
|
2042
|
+
* This is the default type of join.
|
|
2043
|
+
*
|
|
2044
|
+
* For each row of the table, the joined table
|
|
2045
|
+
* needs to have a matching row, or it will
|
|
2046
|
+
* be excluded from results.
|
|
2047
|
+
*/
|
|
2048
|
+
innerJoin = this.createJoin('inner');
|
|
2049
|
+
/**
|
|
2050
|
+
* Rows from both the main & joined are included,
|
|
2051
|
+
* regardless of whether or not they have matching
|
|
2052
|
+
* rows in the other table.
|
|
2053
|
+
*/
|
|
2054
|
+
fullJoin = this.createJoin('full');
|
|
1938
2055
|
/**
|
|
1939
2056
|
* Specify a condition to narrow the result set. Multiple
|
|
1940
2057
|
* conditions can be combined with the `and` and `or`
|
|
@@ -2044,20 +2161,17 @@ class PgSelectQueryBuilder extends TypedQueryBuilder {
|
|
|
2044
2161
|
}
|
|
2045
2162
|
}
|
|
2046
2163
|
class PgSelect extends PgSelectQueryBuilder {
|
|
2047
|
-
constructor() {
|
|
2048
|
-
super(...arguments);
|
|
2049
|
-
this.execute = (placeholderValues) => {
|
|
2050
|
-
return this._prepare().execute(placeholderValues);
|
|
2051
|
-
};
|
|
2052
|
-
}
|
|
2053
2164
|
_prepare(name) {
|
|
2054
|
-
|
|
2165
|
+
const { session, config, dialect, joinsNotNullableMap } = this;
|
|
2166
|
+
if (!session) {
|
|
2055
2167
|
throw new Error('Cannot execute a query on a query builder. Please use a database instance instead.');
|
|
2056
2168
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2169
|
+
return tracer.startActiveSpan('drizzle.prepareQuery', () => {
|
|
2170
|
+
const fieldsList = orderSelectedFields(config.fields);
|
|
2171
|
+
const query = session.prepareQuery(dialect.sqlToQuery(this.getSQL()), fieldsList, name);
|
|
2172
|
+
query.joinsNotNullableMap = joinsNotNullableMap;
|
|
2173
|
+
return query;
|
|
2174
|
+
});
|
|
2061
2175
|
}
|
|
2062
2176
|
/**
|
|
2063
2177
|
* Create a prepared statement for this query. This allows
|
|
@@ -2069,10 +2183,16 @@ class PgSelect extends PgSelectQueryBuilder {
|
|
|
2069
2183
|
prepare(name) {
|
|
2070
2184
|
return this._prepare(name);
|
|
2071
2185
|
}
|
|
2186
|
+
execute = (placeholderValues) => {
|
|
2187
|
+
return tracer.startActiveSpan('drizzle.operation', () => {
|
|
2188
|
+
return this._prepare().execute(placeholderValues);
|
|
2189
|
+
});
|
|
2190
|
+
};
|
|
2072
2191
|
}
|
|
2073
2192
|
applyMixins(PgSelect, [QueryPromise]);
|
|
2074
2193
|
|
|
2075
2194
|
class QueryBuilder {
|
|
2195
|
+
dialect;
|
|
2076
2196
|
$with(alias) {
|
|
2077
2197
|
const queryBuilder = this;
|
|
2078
2198
|
return {
|
|
@@ -2104,11 +2224,13 @@ class QueryBuilder {
|
|
|
2104
2224
|
}
|
|
2105
2225
|
|
|
2106
2226
|
class DefaultViewBuilderCore {
|
|
2227
|
+
name;
|
|
2228
|
+
schema;
|
|
2107
2229
|
constructor(name, schema) {
|
|
2108
2230
|
this.name = name;
|
|
2109
2231
|
this.schema = schema;
|
|
2110
|
-
this.config = {};
|
|
2111
2232
|
}
|
|
2233
|
+
config = {};
|
|
2112
2234
|
with(config) {
|
|
2113
2235
|
this.config.with = config;
|
|
2114
2236
|
return this;
|
|
@@ -2138,6 +2260,7 @@ class ViewBuilder extends DefaultViewBuilderCore {
|
|
|
2138
2260
|
}
|
|
2139
2261
|
}
|
|
2140
2262
|
class ManualViewBuilder extends DefaultViewBuilderCore {
|
|
2263
|
+
columns;
|
|
2141
2264
|
constructor(name, columns, schema) {
|
|
2142
2265
|
super(name, schema);
|
|
2143
2266
|
this.columns = getTableColumns(pgTable(name, columns));
|
|
@@ -2176,11 +2299,13 @@ class ManualViewBuilder extends DefaultViewBuilderCore {
|
|
|
2176
2299
|
}
|
|
2177
2300
|
}
|
|
2178
2301
|
class MaterializedViewBuilderCore {
|
|
2302
|
+
name;
|
|
2303
|
+
schema;
|
|
2179
2304
|
constructor(name, schema) {
|
|
2180
2305
|
this.name = name;
|
|
2181
2306
|
this.schema = schema;
|
|
2182
|
-
this.config = {};
|
|
2183
2307
|
}
|
|
2308
|
+
config = {};
|
|
2184
2309
|
using(using) {
|
|
2185
2310
|
this.config.using = using;
|
|
2186
2311
|
return this;
|
|
@@ -2227,6 +2352,7 @@ class MaterializedViewBuilder extends MaterializedViewBuilderCore {
|
|
|
2227
2352
|
}
|
|
2228
2353
|
}
|
|
2229
2354
|
class ManualMaterializedViewBuilder extends MaterializedViewBuilderCore {
|
|
2355
|
+
columns;
|
|
2230
2356
|
constructor(name, columns, schema) {
|
|
2231
2357
|
super(name, schema);
|
|
2232
2358
|
this.columns = getTableColumns(pgTable(name, columns));
|
|
@@ -2268,6 +2394,7 @@ class PgViewBase extends View {
|
|
|
2268
2394
|
}
|
|
2269
2395
|
const PgViewConfig = Symbol('PgViewConfig');
|
|
2270
2396
|
class PgView extends PgViewBase {
|
|
2397
|
+
[PgViewConfig];
|
|
2271
2398
|
constructor({ pgConfig, config }) {
|
|
2272
2399
|
super(config);
|
|
2273
2400
|
if (pgConfig) {
|
|
@@ -2279,6 +2406,7 @@ class PgView extends PgViewBase {
|
|
|
2279
2406
|
}
|
|
2280
2407
|
const PgMaterializedViewConfig = Symbol('PgMaterializedViewConfig');
|
|
2281
2408
|
class PgMaterializedView extends PgViewBase {
|
|
2409
|
+
[PgMaterializedViewConfig];
|
|
2282
2410
|
constructor({ pgConfig, config }) {
|
|
2283
2411
|
super(config);
|
|
2284
2412
|
this[PgMaterializedViewConfig] = {
|
|
@@ -2434,10 +2562,7 @@ function makePgArray(array) {
|
|
|
2434
2562
|
}
|
|
2435
2563
|
|
|
2436
2564
|
class PgColumnBuilder extends ColumnBuilder {
|
|
2437
|
-
|
|
2438
|
-
super(...arguments);
|
|
2439
|
-
this.foreignKeyConfigs = [];
|
|
2440
|
-
}
|
|
2565
|
+
foreignKeyConfigs = [];
|
|
2441
2566
|
array(size) {
|
|
2442
2567
|
return new PgArrayBuilder(this.config.name, this, size);
|
|
2443
2568
|
}
|
|
@@ -2481,6 +2606,9 @@ class PgArrayBuilder extends PgColumnBuilder {
|
|
|
2481
2606
|
}
|
|
2482
2607
|
}
|
|
2483
2608
|
class PgArray extends PgColumn {
|
|
2609
|
+
baseColumn;
|
|
2610
|
+
range;
|
|
2611
|
+
size;
|
|
2484
2612
|
constructor(table, config, baseColumn, range) {
|
|
2485
2613
|
super(table, config);
|
|
2486
2614
|
this.baseColumn = baseColumn;
|
|
@@ -2626,6 +2754,8 @@ class PgNumericBuilder extends PgColumnBuilder {
|
|
|
2626
2754
|
}
|
|
2627
2755
|
}
|
|
2628
2756
|
class PgNumeric extends PgColumn {
|
|
2757
|
+
precision;
|
|
2758
|
+
scale;
|
|
2629
2759
|
constructor(table, config) {
|
|
2630
2760
|
super(table, config);
|
|
2631
2761
|
this.precision = config.precision;
|
|
@@ -2649,6 +2779,8 @@ function numeric(name, config) {
|
|
|
2649
2779
|
const decimal = numeric;
|
|
2650
2780
|
|
|
2651
2781
|
class PgTimeBuilder extends PgDateColumnBaseBuilder {
|
|
2782
|
+
withTimezone;
|
|
2783
|
+
precision;
|
|
2652
2784
|
constructor(name, withTimezone, precision) {
|
|
2653
2785
|
super(name);
|
|
2654
2786
|
this.withTimezone = withTimezone;
|
|
@@ -2662,6 +2794,8 @@ class PgTimeBuilder extends PgDateColumnBaseBuilder {
|
|
|
2662
2794
|
}
|
|
2663
2795
|
}
|
|
2664
2796
|
class PgTime extends PgColumn {
|
|
2797
|
+
withTimezone;
|
|
2798
|
+
precision;
|
|
2665
2799
|
constructor(table, config) {
|
|
2666
2800
|
super(table, config);
|
|
2667
2801
|
this.withTimezone = config.withTimezone;
|
|
@@ -2688,14 +2822,10 @@ class PgTimestampBuilder extends PgDateColumnBaseBuilder {
|
|
|
2688
2822
|
}
|
|
2689
2823
|
}
|
|
2690
2824
|
class PgTimestamp extends PgColumn {
|
|
2825
|
+
withTimezone;
|
|
2826
|
+
precision;
|
|
2691
2827
|
constructor(table, config) {
|
|
2692
2828
|
super(table, config);
|
|
2693
|
-
this.mapFromDriverValue = (value) => {
|
|
2694
|
-
return new Date(this.withTimezone ? value : value + '+0000');
|
|
2695
|
-
};
|
|
2696
|
-
this.mapToDriverValue = (value) => {
|
|
2697
|
-
return this.withTimezone ? value.toUTCString() : value.toISOString();
|
|
2698
|
-
};
|
|
2699
2829
|
this.withTimezone = config.withTimezone;
|
|
2700
2830
|
this.precision = config.precision;
|
|
2701
2831
|
}
|
|
@@ -2703,6 +2833,12 @@ class PgTimestamp extends PgColumn {
|
|
|
2703
2833
|
const precision = this.precision === undefined ? '' : ` (${this.precision})`;
|
|
2704
2834
|
return `timestamp${precision}${this.withTimezone ? ' with time zone' : ''}`;
|
|
2705
2835
|
}
|
|
2836
|
+
mapFromDriverValue = (value) => {
|
|
2837
|
+
return new Date(this.withTimezone ? value : value + '+0000');
|
|
2838
|
+
};
|
|
2839
|
+
mapToDriverValue = (value) => {
|
|
2840
|
+
return this.withTimezone ? value.toUTCString() : value.toISOString();
|
|
2841
|
+
};
|
|
2706
2842
|
}
|
|
2707
2843
|
class PgTimestampStringBuilder extends PgDateColumnBaseBuilder {
|
|
2708
2844
|
constructor(name, withTimezone, precision) {
|
|
@@ -2716,6 +2852,8 @@ class PgTimestampStringBuilder extends PgDateColumnBaseBuilder {
|
|
|
2716
2852
|
}
|
|
2717
2853
|
}
|
|
2718
2854
|
class PgTimestampString extends PgColumn {
|
|
2855
|
+
withTimezone;
|
|
2856
|
+
precision;
|
|
2719
2857
|
constructor(table, config) {
|
|
2720
2858
|
super(table, config);
|
|
2721
2859
|
this.withTimezone = config.withTimezone;
|
|
@@ -2755,6 +2893,11 @@ function uuid(name) {
|
|
|
2755
2893
|
}
|
|
2756
2894
|
|
|
2757
2895
|
class Relation {
|
|
2896
|
+
sourceTable;
|
|
2897
|
+
referencedTable;
|
|
2898
|
+
relationName;
|
|
2899
|
+
referencedTableName;
|
|
2900
|
+
fieldName;
|
|
2758
2901
|
constructor(sourceTable, referencedTable, relationName) {
|
|
2759
2902
|
this.sourceTable = sourceTable;
|
|
2760
2903
|
this.referencedTable = referencedTable;
|
|
@@ -2763,12 +2906,16 @@ class Relation {
|
|
|
2763
2906
|
}
|
|
2764
2907
|
}
|
|
2765
2908
|
class Relations {
|
|
2909
|
+
table;
|
|
2910
|
+
config;
|
|
2766
2911
|
constructor(table, config) {
|
|
2767
2912
|
this.table = table;
|
|
2768
2913
|
this.config = config;
|
|
2769
2914
|
}
|
|
2770
2915
|
}
|
|
2771
2916
|
class One extends Relation {
|
|
2917
|
+
config;
|
|
2918
|
+
isNullable;
|
|
2772
2919
|
constructor(sourceTable, referencedTable, config, isNullable) {
|
|
2773
2920
|
super(sourceTable, referencedTable, config?.relationName);
|
|
2774
2921
|
this.config = config;
|
|
@@ -2781,6 +2928,7 @@ class One extends Relation {
|
|
|
2781
2928
|
}
|
|
2782
2929
|
}
|
|
2783
2930
|
class Many extends Relation {
|
|
2931
|
+
config;
|
|
2784
2932
|
constructor(sourceTable, referencedTable, config) {
|
|
2785
2933
|
super(sourceTable, referencedTable, config?.relationName);
|
|
2786
2934
|
this.config = config;
|
|
@@ -2959,5 +3107,5 @@ function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelect
|
|
|
2959
3107
|
return result;
|
|
2960
3108
|
}
|
|
2961
3109
|
|
|
2962
|
-
export {
|
|
2963
|
-
//# sourceMappingURL=relations-
|
|
3110
|
+
export { PgArray as $, normalizeRelation as A, and as B, Column as C, or as D, aliasedTable as E, eq as F, TypedQueryBuilder as G, getTableLikeName as H, applyMixins as I, ColumnBuilder as J, TableAliasProxyHandler as K, PgColumnBuilder as L, PgColumn as M, pgTableWithSchema as N, pgViewWithSchema as O, PgDialect as P, QueryPromise as Q, Relation as R, SQL as S, Table as T, pgMaterializedViewWithSchema as U, View as V, WithSubquery as W, CheckBuilder as X, Check as Y, check as Z, PgArrayBuilder as _, Param as a, RelationTableAliasProxyHandler as a$, PgDateBuilder as a0, PgDate as a1, PgDateStringBuilder as a2, PgDateString as a3, date as a4, PgJsonBuilder as a5, PgJson as a6, json as a7, PgJsonbBuilder as a8, PgJsonb as a9, PrimaryKey as aA, PgSelectQueryBuilder as aB, PgSelect as aC, InlineForeignKeys as aD, PgTable as aE, pgTable as aF, pgTableCreator as aG, getTableConfig as aH, getViewConfig as aI, getMaterializedViewConfig as aJ, parsePgNestedArray as aK, parsePgArray as aL, makePgArray as aM, DefaultViewBuilderCore as aN, ViewBuilder as aO, ManualViewBuilder as aP, MaterializedViewBuilderCore as aQ, MaterializedViewBuilder as aR, ManualMaterializedViewBuilder as aS, PgViewBase as aT, PgViewConfig as aU, PgView as aV, PgMaterializedViewConfig as aW, PgMaterializedView as aX, pgView as aY, pgMaterializedView as aZ, ColumnAliasProxyHandler as a_, jsonb as aa, PgNumericBuilder as ab, PgNumeric as ac, numeric as ad, decimal as ae, PgTimeBuilder as af, PgTime as ag, time as ah, PgTimestampBuilder as ai, PgTimestamp as aj, PgTimestampStringBuilder as ak, PgTimestampString as al, timestamp as am, PgUUIDBuilder as an, PgUUID as ao, uuid as ap, ForeignKeyBuilder as aq, ForeignKey as ar, foreignKey as as, IndexBuilderOn as at, IndexBuilder as au, Index as av, index as aw, uniqueIndex as ax, primaryKey as ay, PrimaryKeyBuilder as az, mapUpdateSet as b, bindIfParam as b0, ne as b1, not as b2, gt as b3, gte as b4, lt as b5, lte as b6, inArray as b7, notInArray as b8, isNull as b9, placeholder as bA, TableName as bB, Schema as bC, Columns as bD, OriginalName as bE, BaseName as bF, IsAlias as bG, ExtraConfigBuilder as bH, isTable as bI, iife as bJ, isNotNull as ba, exists as bb, notExists as bc, between as bd, notBetween as be, like as bf, notLike as bg, ilike as bh, notIlike as bi, asc as bj, desc as bk, Relations as bl, One as bm, Many as bn, relations as bo, createOne as bp, createMany as bq, FakePrimitiveParam as br, isSQLWrapper as bs, StringChunk as bt, Name as bu, isDriverValueEncoder as bv, noopDecoder as bw, noopEncoder as bx, noopMapper as by, Placeholder as bz, createTableRelationsHelpers as c, mapRelationalRow as d, extractTablesRelationalConfig as e, fillPlaceholders as f, QueryBuilder as g, SelectionProxyHandler as h, PgSelectBuilder as i, getTableColumns as j, getTableName as k, Subquery as l, mapResultRow as m, name as n, orderSelectedFields as o, SubqueryConfig as p, ViewBaseConfig as q, param as r, sql as s, tracer as t, aliasedTableColumn as u, aliasedRelation as v, mapColumnsInAliasedSQLToAlias as w, operators as x, mapColumnsInSQLToAlias as y, orderByOperators as z };
|
|
3111
|
+
//# sourceMappingURL=relations-d3070559.mjs.map
|