pqb 0.27.5 → 0.27.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +177 -88
- package/dist/index.js +380 -203
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +378 -205
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -141,9 +141,12 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
141
141
|
* // primary key can be used by `find` later:
|
|
142
142
|
* db.table.find('97ba9e78-7510-415a-9c03-23d440aec443');
|
|
143
143
|
* ```
|
|
144
|
+
*
|
|
145
|
+
* @param options - to specify a constraint name
|
|
144
146
|
*/
|
|
145
|
-
primaryKey() {
|
|
146
|
-
|
|
147
|
+
primaryKey(options) {
|
|
148
|
+
var _a;
|
|
149
|
+
return orchidCore.setColumnData(this, "primaryKey", (_a = options == null ? void 0 : options.name) != null ? _a : true);
|
|
147
150
|
}
|
|
148
151
|
foreignKey(fnOrTable, column, options = orchidCore.emptyObject) {
|
|
149
152
|
const item = typeof fnOrTable === "string" ? __spreadValues$h({ table: fnOrTable, columns: [column] }, options) : __spreadValues$h({ fn: fnOrTable, columns: [column] }, options);
|
|
@@ -156,9 +159,9 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
156
159
|
return orchidCore.pushColumnData(this, "indexes", options);
|
|
157
160
|
}
|
|
158
161
|
/**
|
|
159
|
-
* `searchIndex` is designed for full text search.
|
|
162
|
+
* `searchIndex` is designed for [full text search](/guide/text-search).
|
|
160
163
|
*
|
|
161
|
-
* It can accept the same options as a regular `index`, but it is `USING GIN` by default, and it is concatenating columns into a `tsvector
|
|
164
|
+
* It can accept the same options as a regular `index`, but it is `USING GIN` by default, and it is concatenating columns into a `tsvector` database type.
|
|
162
165
|
*
|
|
163
166
|
* ```ts
|
|
164
167
|
* import { change } from '../dbScript';
|
|
@@ -166,8 +169,8 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
166
169
|
* change(async (db) => {
|
|
167
170
|
* await db.createTable('table', (t) => ({
|
|
168
171
|
* id: t.identity().primaryKey(),
|
|
169
|
-
* title: t.
|
|
170
|
-
* body: t.
|
|
172
|
+
* title: t.text(),
|
|
173
|
+
* body: t.text(),
|
|
171
174
|
* ...t.searchIndex(['title', 'body']),
|
|
172
175
|
* }));
|
|
173
176
|
* });
|
|
@@ -176,10 +179,29 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
176
179
|
* Produces the following index ('english' is a default language, see [full text search](/guide/text-search.html#language) for changing it):
|
|
177
180
|
*
|
|
178
181
|
* ```sql
|
|
179
|
-
* CREATE INDEX "table_title_body_idx" ON "table" USING GIN (to_tsvector('english',
|
|
182
|
+
* CREATE INDEX "table_title_body_idx" ON "table" USING GIN (to_tsvector('english', "title" || ' ' || "body"))
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* You can set different search weights (`A` to `D`) on different columns inside the index:
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* import { change } from '../dbScript';
|
|
189
|
+
*
|
|
190
|
+
* change(async (db) => {
|
|
191
|
+
* await db.createTable('table', (t) => ({
|
|
192
|
+
* id: t.identity().primaryKey(),
|
|
193
|
+
* title: t.text(),
|
|
194
|
+
* body: t.text(),
|
|
195
|
+
* ...t.searchIndex([
|
|
196
|
+
* { column: 'title', weight: 'A' },
|
|
197
|
+
* { column: 'body', weight: 'B' },
|
|
198
|
+
* ]),
|
|
199
|
+
* }));
|
|
200
|
+
* });
|
|
180
201
|
* ```
|
|
181
202
|
*
|
|
182
|
-
*
|
|
203
|
+
* When the table has localized columns,
|
|
204
|
+
* you can define different indexes for different languages by setting the `language` parameter:
|
|
183
205
|
*
|
|
184
206
|
* ```ts
|
|
185
207
|
* import { change } from '../dbScript';
|
|
@@ -187,8 +209,44 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
187
209
|
* change(async (db) => {
|
|
188
210
|
* await db.createTable('table', (t) => ({
|
|
189
211
|
* id: t.identity().primaryKey(),
|
|
190
|
-
*
|
|
191
|
-
*
|
|
212
|
+
* titleEn: t.text(),
|
|
213
|
+
* bodyEn: t.text(),
|
|
214
|
+
* titleFr: t.text(),
|
|
215
|
+
* bodyFr: t.text(),
|
|
216
|
+
* ...t.searchIndex(['titleEn', 'bodyEn'], { language: 'english' }),
|
|
217
|
+
* ...t.searchIndex(['titleFr', 'bodyFr'], { language: 'french' }),
|
|
218
|
+
* }));
|
|
219
|
+
* });
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* Alternatively, different table records may correspond to a single language,
|
|
223
|
+
* then you can define a search index that relies on a language column by using `languageColumn` parameter:
|
|
224
|
+
*
|
|
225
|
+
* ```ts
|
|
226
|
+
* import { change } from '../dbScript';
|
|
227
|
+
*
|
|
228
|
+
* change(async (db) => {
|
|
229
|
+
* await db.createTable('table', (t) => ({
|
|
230
|
+
* id: t.identity().primaryKey(),
|
|
231
|
+
* lang: t.type('regconfig'),
|
|
232
|
+
* title: t.text(),
|
|
233
|
+
* body: t.text(),
|
|
234
|
+
* ...t.searchIndex(['title', 'body'], { languageColumn: 'lang' }),
|
|
235
|
+
* }));
|
|
236
|
+
* });
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* It can be more efficient to use a [generated](/guide/migration-column-methods.html#generated-column) column instead of indexing text column in the way described above,
|
|
240
|
+
* and to set a `searchIndex` on it:
|
|
241
|
+
*
|
|
242
|
+
* ```ts
|
|
243
|
+
* import { change } from '../dbScript';
|
|
244
|
+
*
|
|
245
|
+
* change(async (db) => {
|
|
246
|
+
* await db.createTable('table', (t) => ({
|
|
247
|
+
* id: t.identity().primaryKey(),
|
|
248
|
+
* title: t.text(),
|
|
249
|
+
* body: t.text(),
|
|
192
250
|
* generatedTsVector: t.tsvector().generated(['title', 'body']).searchIndex(),
|
|
193
251
|
* }));
|
|
194
252
|
* });
|
|
@@ -269,14 +327,21 @@ const knownDefaults = {
|
|
|
269
327
|
};
|
|
270
328
|
const simplifyColumnDefault = (value) => {
|
|
271
329
|
if (typeof value === "string") {
|
|
272
|
-
|
|
273
|
-
|
|
330
|
+
return new RawSQL([
|
|
331
|
+
[knownDefaults[value.toLowerCase()] || value]
|
|
332
|
+
]);
|
|
274
333
|
}
|
|
275
334
|
return;
|
|
276
335
|
};
|
|
277
336
|
const instantiateColumn = (typeFn, params) => {
|
|
278
337
|
const column = typeFn();
|
|
338
|
+
const { dateTimePrecision } = params;
|
|
279
339
|
Object.assign(column.data, __spreadProps$a(__spreadValues$g({}, params), {
|
|
340
|
+
dateTimePrecision: (
|
|
341
|
+
// 0 is default for date, 6 is default for timestamp
|
|
342
|
+
dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
|
|
343
|
+
),
|
|
344
|
+
collate: params.collate,
|
|
280
345
|
default: simplifyColumnDefault(params.default)
|
|
281
346
|
}));
|
|
282
347
|
return column;
|
|
@@ -317,7 +382,7 @@ const combineCodeElements = (input) => {
|
|
|
317
382
|
}
|
|
318
383
|
return output;
|
|
319
384
|
};
|
|
320
|
-
const columnsShapeToCode = (shape, tableData, t) => {
|
|
385
|
+
const columnsShapeToCode = (shape, tableData, t, m) => {
|
|
321
386
|
const hasTimestamps = "createdAt" in shape && isDefaultTimeStamp(shape.createdAt) && "updatedAt" in shape && isDefaultTimeStamp(shape.updatedAt);
|
|
322
387
|
const code = [];
|
|
323
388
|
for (const key in shape) {
|
|
@@ -345,19 +410,33 @@ const columnsShapeToCode = (shape, tableData, t) => {
|
|
|
345
410
|
}
|
|
346
411
|
if (constraints) {
|
|
347
412
|
for (const item of constraints) {
|
|
348
|
-
code.push(...constraintToCode(item, t));
|
|
413
|
+
code.push(...constraintToCode(item, t, m));
|
|
349
414
|
}
|
|
350
415
|
}
|
|
351
416
|
return code;
|
|
352
417
|
};
|
|
353
418
|
const primaryKeyToCode = (primaryKey, t) => {
|
|
419
|
+
return `...${primaryKeyInnerToCode(primaryKey, t)},`;
|
|
420
|
+
};
|
|
421
|
+
const primaryKeyInnerToCode = (primaryKey, t) => {
|
|
354
422
|
var _a;
|
|
355
423
|
const name = (_a = primaryKey.options) == null ? void 0 : _a.name;
|
|
356
|
-
return
|
|
424
|
+
return `${t}.primaryKey([${primaryKey.columns.map(orchidCore.singleQuote).join(", ")}]${name ? `, { name: ${orchidCore.singleQuote(name)} }` : ""})`;
|
|
357
425
|
};
|
|
358
426
|
const indexToCode = (index, t) => {
|
|
427
|
+
const code = indexInnerToCode(index, t);
|
|
428
|
+
code[0] = `...${code[0]}`;
|
|
429
|
+
const last = code[code.length - 1];
|
|
430
|
+
if (typeof last === "string" && !last.endsWith(","))
|
|
431
|
+
orchidCore.addCode(code, ",");
|
|
432
|
+
return code;
|
|
433
|
+
};
|
|
434
|
+
const indexInnerToCode = (index, t) => {
|
|
359
435
|
const code = [];
|
|
360
|
-
code.push(
|
|
436
|
+
code.push(
|
|
437
|
+
`${t}.${index.options.tsVector ? "searchIndex" : index.options.unique ? "unique" : "index"}(`
|
|
438
|
+
);
|
|
439
|
+
const columnOptions = ["collate", "opclass", "order", "weight"];
|
|
361
440
|
const columnsMultiline = index.columns.some((column) => {
|
|
362
441
|
for (const key in column) {
|
|
363
442
|
if (key !== "column" && column[key] !== void 0)
|
|
@@ -369,13 +448,13 @@ const indexToCode = (index, t) => {
|
|
|
369
448
|
const objects = [];
|
|
370
449
|
for (const column of index.columns) {
|
|
371
450
|
const expr = "column" in column ? column.column : column.expression;
|
|
372
|
-
let
|
|
451
|
+
let hasOptions = false;
|
|
373
452
|
for (const key in column) {
|
|
374
|
-
if (key !== "column"
|
|
375
|
-
|
|
453
|
+
if (key !== "column") {
|
|
454
|
+
hasOptions = true;
|
|
376
455
|
}
|
|
377
456
|
}
|
|
378
|
-
if (!
|
|
457
|
+
if (!hasOptions) {
|
|
379
458
|
objects.push(`${orchidCore.singleQuote(expr)},`);
|
|
380
459
|
} else {
|
|
381
460
|
const props = [
|
|
@@ -383,14 +462,11 @@ const indexToCode = (index, t) => {
|
|
|
383
462
|
expr
|
|
384
463
|
)},`
|
|
385
464
|
];
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
if (column.order !== void 0) {
|
|
393
|
-
props.push(`order: ${orchidCore.singleQuote(column.order)},`);
|
|
465
|
+
for (const key of columnOptions) {
|
|
466
|
+
const value = column[key];
|
|
467
|
+
if (value !== void 0) {
|
|
468
|
+
props.push(`${key}: ${orchidCore.singleQuote(value)},`);
|
|
469
|
+
}
|
|
394
470
|
}
|
|
395
471
|
objects.push("{", props, "},");
|
|
396
472
|
}
|
|
@@ -402,8 +478,22 @@ const indexToCode = (index, t) => {
|
|
|
402
478
|
`[${index.columns.map((it) => orchidCore.singleQuote(it.column)).join(", ")}]`
|
|
403
479
|
);
|
|
404
480
|
}
|
|
405
|
-
const
|
|
406
|
-
|
|
481
|
+
const indexOptionsKeys = [
|
|
482
|
+
"name",
|
|
483
|
+
"using",
|
|
484
|
+
"nullsNotDistinct",
|
|
485
|
+
"include",
|
|
486
|
+
"with",
|
|
487
|
+
"tablespace",
|
|
488
|
+
"where",
|
|
489
|
+
"language",
|
|
490
|
+
"languageColumn",
|
|
491
|
+
"dropMode"
|
|
492
|
+
];
|
|
493
|
+
if (index.options.tsVector && index.options.unique) {
|
|
494
|
+
indexOptionsKeys.unshift("unique");
|
|
495
|
+
}
|
|
496
|
+
if (indexOptionsKeys.some((key) => index.options[key])) {
|
|
407
497
|
if (columnsMultiline) {
|
|
408
498
|
const columns = code[code.length - 1];
|
|
409
499
|
columns[columns.length - 1] += ",";
|
|
@@ -412,7 +502,7 @@ const indexToCode = (index, t) => {
|
|
|
412
502
|
orchidCore.addCode(code, ", {");
|
|
413
503
|
}
|
|
414
504
|
const options = [];
|
|
415
|
-
for (const key
|
|
505
|
+
for (const key of indexOptionsKeys) {
|
|
416
506
|
const value = index.options[key];
|
|
417
507
|
if (value === null || value === void 0)
|
|
418
508
|
continue;
|
|
@@ -430,25 +520,35 @@ const indexToCode = (index, t) => {
|
|
|
430
520
|
if (columnsMultiline) {
|
|
431
521
|
code.push("),");
|
|
432
522
|
} else {
|
|
433
|
-
orchidCore.addCode(code, ")
|
|
523
|
+
orchidCore.addCode(code, ")");
|
|
434
524
|
}
|
|
435
525
|
return code;
|
|
436
526
|
};
|
|
437
|
-
const constraintToCode = (item, t) => {
|
|
527
|
+
const constraintToCode = (item, t, m) => {
|
|
528
|
+
const code = constraintInnerToCode(item, t, m);
|
|
529
|
+
code[0] = `...${code[0]}`;
|
|
530
|
+
const last = code[code.length - 1];
|
|
531
|
+
if (typeof last === "string" && !last.endsWith(","))
|
|
532
|
+
code[code.length - 1] += ",";
|
|
533
|
+
return code;
|
|
534
|
+
};
|
|
535
|
+
const constraintInnerToCode = (item, t, m) => {
|
|
438
536
|
const kind = getConstraintKind(item);
|
|
439
537
|
if (kind === "foreignKey" && item.references) {
|
|
440
538
|
return [
|
|
441
|
-
|
|
442
|
-
referencesArgsToCode(item.references, item.name),
|
|
539
|
+
`${t}.foreignKey(`,
|
|
540
|
+
referencesArgsToCode(item.references, item.name, m),
|
|
443
541
|
"),"
|
|
444
542
|
];
|
|
445
543
|
} else if (kind === "check" && item.check) {
|
|
446
|
-
return [
|
|
544
|
+
return [
|
|
545
|
+
`${t}.check(${item.check.toCode(t)}${item.name ? `, { name: '${item.name}' }` : ""})`
|
|
546
|
+
];
|
|
447
547
|
} else {
|
|
448
|
-
return [
|
|
548
|
+
return [`${t}.constraint({`, constraintPropsToCode(t, item, m), "}),"];
|
|
449
549
|
}
|
|
450
550
|
};
|
|
451
|
-
const constraintPropsToCode = (t, item) => {
|
|
551
|
+
const constraintPropsToCode = (t, item, m) => {
|
|
452
552
|
const props = [];
|
|
453
553
|
if (item.name) {
|
|
454
554
|
props.push(`name: ${orchidCore.singleQuote(item.name)},`);
|
|
@@ -456,7 +556,7 @@ const constraintPropsToCode = (t, item) => {
|
|
|
456
556
|
if (item.references) {
|
|
457
557
|
props.push(
|
|
458
558
|
`references: [`,
|
|
459
|
-
referencesArgsToCode(item.references, false),
|
|
559
|
+
referencesArgsToCode(item.references, false, m),
|
|
460
560
|
"],"
|
|
461
561
|
);
|
|
462
562
|
}
|
|
@@ -470,9 +570,13 @@ const referencesArgsToCode = ({
|
|
|
470
570
|
fnOrTable,
|
|
471
571
|
foreignColumns,
|
|
472
572
|
options
|
|
473
|
-
}, name = (options == null ? void 0 : options.name) || false) => {
|
|
573
|
+
}, name = (options == null ? void 0 : options.name) || false, m) => {
|
|
474
574
|
const args = [];
|
|
475
575
|
args.push(`${orchidCore.singleQuoteArray(columns)},`);
|
|
576
|
+
if (m && typeof fnOrTable !== "string") {
|
|
577
|
+
const { schema, table } = new (fnOrTable())();
|
|
578
|
+
fnOrTable = schema ? `${schema}.${table}` : table;
|
|
579
|
+
}
|
|
476
580
|
args.push(
|
|
477
581
|
`${typeof fnOrTable === "string" ? orchidCore.singleQuote(fnOrTable) : fnOrTable.toString()},`
|
|
478
582
|
);
|
|
@@ -492,24 +596,27 @@ const referencesArgsToCode = ({
|
|
|
492
596
|
}
|
|
493
597
|
return args;
|
|
494
598
|
};
|
|
495
|
-
const columnForeignKeysToCode = (foreignKeys) => {
|
|
599
|
+
const columnForeignKeysToCode = (foreignKeys, migration) => {
|
|
496
600
|
const code = [];
|
|
497
601
|
for (const foreignKey of foreignKeys) {
|
|
498
602
|
orchidCore.addCode(code, `.foreignKey(`);
|
|
499
|
-
for (const part of foreignKeyArgumentToCode(foreignKey)) {
|
|
603
|
+
for (const part of foreignKeyArgumentToCode(foreignKey, migration)) {
|
|
500
604
|
orchidCore.addCode(code, part);
|
|
501
605
|
}
|
|
502
606
|
orchidCore.addCode(code, ")");
|
|
503
607
|
}
|
|
504
608
|
return code;
|
|
505
609
|
};
|
|
506
|
-
const foreignKeyArgumentToCode = (foreignKey) => {
|
|
610
|
+
const foreignKeyArgumentToCode = (foreignKey, migration) => {
|
|
507
611
|
const code = [];
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
612
|
+
let fnOrTable = "fn" in foreignKey ? foreignKey.fn : foreignKey.table;
|
|
613
|
+
if (migration && typeof fnOrTable !== "string") {
|
|
614
|
+
const { schema, table } = new (fnOrTable())();
|
|
615
|
+
fnOrTable = schema ? `${schema}.${table}` : table;
|
|
512
616
|
}
|
|
617
|
+
code.push(
|
|
618
|
+
typeof fnOrTable === "string" ? orchidCore.singleQuote(fnOrTable) : fnOrTable.toString()
|
|
619
|
+
);
|
|
513
620
|
orchidCore.addCode(code, `, ${orchidCore.singleQuote(foreignKey.columns[0])}`);
|
|
514
621
|
const hasOptions = foreignKey.name || foreignKey.match || foreignKey.onUpdate || foreignKey.onDelete;
|
|
515
622
|
if (hasOptions) {
|
|
@@ -564,8 +671,8 @@ const columnIndexesToCode = (indexes) => {
|
|
|
564
671
|
}
|
|
565
672
|
return code;
|
|
566
673
|
};
|
|
567
|
-
const columnCheckToCode = (t,
|
|
568
|
-
return `.check(${
|
|
674
|
+
const columnCheckToCode = (t, { sql, options }) => {
|
|
675
|
+
return `.check(${sql.toCode(t)}${(options == null ? void 0 : options.name) ? `, { name: '${options.name}' }` : ""})`;
|
|
569
676
|
};
|
|
570
677
|
const identityToCode = (identity, dataType) => {
|
|
571
678
|
const code = [];
|
|
@@ -577,16 +684,18 @@ const identityToCode = (identity, dataType) => {
|
|
|
577
684
|
const props = [];
|
|
578
685
|
if (identity.always)
|
|
579
686
|
props.push(`always: true,`);
|
|
580
|
-
if (identity.
|
|
581
|
-
props.push(`
|
|
582
|
-
if (identity.
|
|
583
|
-
props.push(`
|
|
687
|
+
if (identity.increment && identity.increment !== 1)
|
|
688
|
+
props.push(`increment: ${identity.increment},`);
|
|
689
|
+
if (identity.start && identity.start !== 1)
|
|
690
|
+
props.push(`start: ${identity.start},`);
|
|
584
691
|
if (identity.min)
|
|
585
692
|
props.push(`min: ${identity.min},`);
|
|
586
693
|
if (identity.max)
|
|
587
694
|
props.push(`max: ${identity.max},`);
|
|
588
|
-
if (identity.cache)
|
|
695
|
+
if (identity.cache && identity.cache !== 1)
|
|
589
696
|
props.push(`cache: ${identity.cache},`);
|
|
697
|
+
if (identity.cycle)
|
|
698
|
+
props.push(`cycle: true,`);
|
|
590
699
|
if (props.length) {
|
|
591
700
|
orchidCore.addCode(code, "{");
|
|
592
701
|
code.push(props, "}");
|
|
@@ -594,7 +703,7 @@ const identityToCode = (identity, dataType) => {
|
|
|
594
703
|
orchidCore.addCode(code, ")");
|
|
595
704
|
return code;
|
|
596
705
|
};
|
|
597
|
-
const columnCode = (type, t, code, data = type.data, skip) => {
|
|
706
|
+
const columnCode = (type, t, code, migration, data = type.data, skip) => {
|
|
598
707
|
code = orchidCore.toArray(code);
|
|
599
708
|
let prepend = `${t}.`;
|
|
600
709
|
if (data.name) {
|
|
@@ -605,10 +714,14 @@ const columnCode = (type, t, code, data = type.data, skip) => {
|
|
|
605
714
|
} else {
|
|
606
715
|
code[0].unshift(prepend);
|
|
607
716
|
}
|
|
608
|
-
if (data.
|
|
609
|
-
orchidCore.addCode(
|
|
717
|
+
if (data.primaryKey) {
|
|
718
|
+
orchidCore.addCode(
|
|
719
|
+
code,
|
|
720
|
+
`.primaryKey(${data.primaryKey === true ? "" : `{ name: '${data.primaryKey}' }`})`
|
|
721
|
+
);
|
|
722
|
+
}
|
|
610
723
|
if (data.foreignKeys) {
|
|
611
|
-
for (const part of columnForeignKeysToCode(data.foreignKeys)) {
|
|
724
|
+
for (const part of columnForeignKeysToCode(data.foreignKeys, migration)) {
|
|
612
725
|
orchidCore.addCode(code, part);
|
|
613
726
|
}
|
|
614
727
|
}
|
|
@@ -622,7 +735,7 @@ const columnCode = (type, t, code, data = type.data, skip) => {
|
|
|
622
735
|
orchidCore.addCode(code, `.parse(${type.parseFn.toString()})`);
|
|
623
736
|
if (data.as)
|
|
624
737
|
orchidCore.addCode(code, `.as(${data.as.toCode(t)})`);
|
|
625
|
-
if (data.default !== void 0) {
|
|
738
|
+
if (data.default !== void 0 && (!migration || typeof data.default !== "function")) {
|
|
626
739
|
orchidCore.addCode(code, `.default(${orchidCore.columnDefaultArgumentToCode(t, data.default)})`);
|
|
627
740
|
}
|
|
628
741
|
if (data.indexes) {
|
|
@@ -824,8 +937,8 @@ class JSONColumn extends ColumnType {
|
|
|
824
937
|
this.dataType = "jsonb";
|
|
825
938
|
this.operators = Operators.json;
|
|
826
939
|
}
|
|
827
|
-
toCode(t) {
|
|
828
|
-
return columnCode(this, t, `json()`, this.data, toCodeSkip);
|
|
940
|
+
toCode(t, m) {
|
|
941
|
+
return columnCode(this, t, `json()`, m, this.data, toCodeSkip);
|
|
829
942
|
}
|
|
830
943
|
}
|
|
831
944
|
JSONColumn.prototype.encodeFn = JSON.stringify;
|
|
@@ -835,8 +948,8 @@ class JSONTextColumn extends ColumnType {
|
|
|
835
948
|
this.dataType = "json";
|
|
836
949
|
this.operators = Operators.text;
|
|
837
950
|
}
|
|
838
|
-
toCode(t) {
|
|
839
|
-
return columnCode(this, t, `jsonText()`, this.data, toCodeSkip);
|
|
951
|
+
toCode(t, m) {
|
|
952
|
+
return columnCode(this, t, `jsonText()`, m, this.data, toCodeSkip);
|
|
840
953
|
}
|
|
841
954
|
}
|
|
842
955
|
|
|
@@ -1426,8 +1539,9 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
|
|
|
1426
1539
|
};
|
|
1427
1540
|
const makeJoinQueryBuilder = (joinedQuery, joinedShapes, joinTo) => {
|
|
1428
1541
|
const q = joinedQuery.baseQuery.clone();
|
|
1429
|
-
q.q.joinedShapes = joinedShapes;
|
|
1430
1542
|
q.baseQuery = q;
|
|
1543
|
+
q.q.as = joinedQuery.q.as;
|
|
1544
|
+
q.q.joinedShapes = joinedShapes;
|
|
1431
1545
|
q.q.joinTo = joinTo;
|
|
1432
1546
|
return q;
|
|
1433
1547
|
};
|
|
@@ -1605,11 +1719,12 @@ class DateColumn extends DateBaseColumn {
|
|
|
1605
1719
|
super(...arguments);
|
|
1606
1720
|
this.dataType = "date";
|
|
1607
1721
|
}
|
|
1608
|
-
toCode(t) {
|
|
1722
|
+
toCode(t, m) {
|
|
1609
1723
|
return columnCode(
|
|
1610
1724
|
this,
|
|
1611
1725
|
t,
|
|
1612
|
-
`date()${orchidCore.dateDataToCode(this.data)}`,
|
|
1726
|
+
`date()${orchidCore.dateDataToCode(this.data, m)}`,
|
|
1727
|
+
m,
|
|
1613
1728
|
this.data,
|
|
1614
1729
|
skipDateMethodsFromToCode
|
|
1615
1730
|
);
|
|
@@ -1636,7 +1751,7 @@ class DateTimeTzBaseClass extends DateTimeBaseClass {
|
|
|
1636
1751
|
);
|
|
1637
1752
|
}
|
|
1638
1753
|
}
|
|
1639
|
-
const timestampToCode = (self, t) => {
|
|
1754
|
+
const timestampToCode = (self, t, m) => {
|
|
1640
1755
|
const { dateTimePrecision: p } = self.data;
|
|
1641
1756
|
const { defaultTimestamp } = self.data;
|
|
1642
1757
|
if (defaultTimestamp) {
|
|
@@ -1648,7 +1763,8 @@ const timestampToCode = (self, t) => {
|
|
|
1648
1763
|
const code = columnCode(
|
|
1649
1764
|
self,
|
|
1650
1765
|
t,
|
|
1651
|
-
`timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data)}`,
|
|
1766
|
+
`timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data, m)}`,
|
|
1767
|
+
m,
|
|
1652
1768
|
self.data,
|
|
1653
1769
|
skipDateMethodsFromToCode
|
|
1654
1770
|
);
|
|
@@ -1659,7 +1775,8 @@ const timestampToCode = (self, t) => {
|
|
|
1659
1775
|
return columnCode(
|
|
1660
1776
|
self,
|
|
1661
1777
|
t,
|
|
1662
|
-
`${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data)}`,
|
|
1778
|
+
`${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data, m)}`,
|
|
1779
|
+
m,
|
|
1663
1780
|
self.data,
|
|
1664
1781
|
skipDateMethodsFromToCode
|
|
1665
1782
|
);
|
|
@@ -1670,8 +1787,8 @@ class TimestampColumn extends DateTimeBaseClass {
|
|
|
1670
1787
|
super(...arguments);
|
|
1671
1788
|
this.dataType = "timestamp";
|
|
1672
1789
|
}
|
|
1673
|
-
toCode(t) {
|
|
1674
|
-
return timestampToCode(this, t);
|
|
1790
|
+
toCode(t, m) {
|
|
1791
|
+
return timestampToCode(this, t, m);
|
|
1675
1792
|
}
|
|
1676
1793
|
}
|
|
1677
1794
|
class TimestampTZColumn extends DateTimeTzBaseClass {
|
|
@@ -1680,8 +1797,8 @@ class TimestampTZColumn extends DateTimeTzBaseClass {
|
|
|
1680
1797
|
this.dataType = "timestamptz";
|
|
1681
1798
|
this.baseDataType = "timestamp";
|
|
1682
1799
|
}
|
|
1683
|
-
toCode(t) {
|
|
1684
|
-
return timestampToCode(this, t);
|
|
1800
|
+
toCode(t, m) {
|
|
1801
|
+
return timestampToCode(this, t, m);
|
|
1685
1802
|
}
|
|
1686
1803
|
}
|
|
1687
1804
|
class TimeColumn extends ColumnType {
|
|
@@ -1691,12 +1808,13 @@ class TimeColumn extends ColumnType {
|
|
|
1691
1808
|
this.operators = Operators.time;
|
|
1692
1809
|
this.data.dateTimePrecision = dateTimePrecision;
|
|
1693
1810
|
}
|
|
1694
|
-
toCode(t) {
|
|
1811
|
+
toCode(t, m) {
|
|
1695
1812
|
const { dateTimePrecision } = this.data;
|
|
1696
1813
|
return columnCode(
|
|
1697
1814
|
this,
|
|
1698
1815
|
t,
|
|
1699
|
-
`time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(this.data)}`,
|
|
1816
|
+
`time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(this.data, m)}`,
|
|
1817
|
+
m,
|
|
1700
1818
|
this.data,
|
|
1701
1819
|
skipDateMethodsFromToCode
|
|
1702
1820
|
);
|
|
@@ -1710,12 +1828,13 @@ class IntervalColumn extends ColumnType {
|
|
|
1710
1828
|
this.data.fields = fields;
|
|
1711
1829
|
this.data.precision = precision;
|
|
1712
1830
|
}
|
|
1713
|
-
toCode(t) {
|
|
1831
|
+
toCode(t, m) {
|
|
1714
1832
|
const { fields, precision } = this.data;
|
|
1715
1833
|
return columnCode(
|
|
1716
1834
|
this,
|
|
1717
1835
|
t,
|
|
1718
1836
|
`interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})`,
|
|
1837
|
+
m,
|
|
1719
1838
|
this.data,
|
|
1720
1839
|
skipDateMethodsFromToCode
|
|
1721
1840
|
);
|
|
@@ -1738,9 +1857,9 @@ class EnumColumn extends ColumnType {
|
|
|
1738
1857
|
this.dataType = "enum";
|
|
1739
1858
|
this.inputSchema = this.outputSchema = this.querySchema = schemaType;
|
|
1740
1859
|
}
|
|
1741
|
-
toCode(t,
|
|
1742
|
-
const options =
|
|
1743
|
-
return columnCode(this, t, `enum('${this.enumName}'${options})
|
|
1860
|
+
toCode(t, m) {
|
|
1861
|
+
const options = m ? "" : `, [${this.options.map((option) => `'${option}'`).join(", ")}]`;
|
|
1862
|
+
return columnCode(this, t, `enum('${this.enumName}'${options})`, m);
|
|
1744
1863
|
}
|
|
1745
1864
|
toSQL() {
|
|
1746
1865
|
const name = this.enumName;
|
|
@@ -1772,15 +1891,16 @@ class ArrayColumn extends ColumnType {
|
|
|
1772
1891
|
}
|
|
1773
1892
|
);
|
|
1774
1893
|
this.data.item = item;
|
|
1894
|
+
this.data.name = item.data.name;
|
|
1775
1895
|
}
|
|
1776
1896
|
toSQL() {
|
|
1777
1897
|
return `${this.data.item.toSQL()}[]`;
|
|
1778
1898
|
}
|
|
1779
|
-
toCode(t) {
|
|
1899
|
+
toCode(t, m) {
|
|
1780
1900
|
const code = ["array("];
|
|
1781
1901
|
orchidCore.addCode(code, this.data.item.toCode(t));
|
|
1782
|
-
orchidCore.addCode(code, `)${orchidCore.arrayDataToCode(this.data)}`);
|
|
1783
|
-
return columnCode(this, t, code);
|
|
1902
|
+
orchidCore.addCode(code, `)${orchidCore.arrayDataToCode(this.data, m)}`);
|
|
1903
|
+
return columnCode(this, t, code, m);
|
|
1784
1904
|
}
|
|
1785
1905
|
}
|
|
1786
1906
|
const parseArray = (input, pos, len, entries, nested, item) => {
|
|
@@ -4063,16 +4183,18 @@ class DecimalColumn extends ColumnType {
|
|
|
4063
4183
|
constructor(schema, numericPrecision, numericScale) {
|
|
4064
4184
|
super(schema, schema.stringSchema());
|
|
4065
4185
|
this.operators = Operators.number;
|
|
4066
|
-
this.dataType = "
|
|
4186
|
+
this.dataType = "numeric";
|
|
4067
4187
|
this.data.numericPrecision = numericPrecision;
|
|
4068
4188
|
this.data.numericScale = numericScale;
|
|
4189
|
+
this.data.alias = "decimal";
|
|
4069
4190
|
}
|
|
4070
|
-
toCode(t) {
|
|
4191
|
+
toCode(t, m) {
|
|
4071
4192
|
const { numericPrecision, numericScale } = this.data;
|
|
4072
4193
|
return columnCode(
|
|
4073
4194
|
this,
|
|
4074
4195
|
t,
|
|
4075
|
-
`decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})
|
|
4196
|
+
`decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`,
|
|
4197
|
+
m
|
|
4076
4198
|
);
|
|
4077
4199
|
}
|
|
4078
4200
|
toSQL() {
|
|
@@ -4084,49 +4206,52 @@ class DecimalColumn extends ColumnType {
|
|
|
4084
4206
|
}
|
|
4085
4207
|
}
|
|
4086
4208
|
const skipNumberMethods = { int: true };
|
|
4087
|
-
const intToCode = (column, t) => {
|
|
4209
|
+
const intToCode = (column, t, alias, m) => {
|
|
4088
4210
|
let code;
|
|
4089
4211
|
if (column.data.identity) {
|
|
4090
|
-
code = identityToCode(column.data.identity,
|
|
4212
|
+
code = identityToCode(column.data.identity, alias);
|
|
4091
4213
|
} else {
|
|
4092
|
-
code = [`${
|
|
4214
|
+
code = [`${alias}()`];
|
|
4093
4215
|
}
|
|
4094
|
-
orchidCore.addCode(code, orchidCore.numberDataToCode(column.data, skipNumberMethods));
|
|
4095
|
-
return columnCode(column, t, code);
|
|
4216
|
+
orchidCore.addCode(code, orchidCore.numberDataToCode(column.data, m, skipNumberMethods));
|
|
4217
|
+
return columnCode(column, t, code, m);
|
|
4096
4218
|
};
|
|
4097
4219
|
class SmallIntColumn extends IntegerBaseColumn {
|
|
4098
|
-
constructor() {
|
|
4099
|
-
super(
|
|
4100
|
-
this.dataType = "
|
|
4220
|
+
constructor(schema) {
|
|
4221
|
+
super(schema);
|
|
4222
|
+
this.dataType = "int2";
|
|
4101
4223
|
this.parseItem = parseInt;
|
|
4224
|
+
this.data.alias = "smallint";
|
|
4102
4225
|
}
|
|
4103
|
-
toCode(t) {
|
|
4104
|
-
return intToCode(this, t);
|
|
4226
|
+
toCode(t, m) {
|
|
4227
|
+
return intToCode(this, t, "smallint", m);
|
|
4105
4228
|
}
|
|
4106
4229
|
identity(options = {}) {
|
|
4107
4230
|
return orchidCore.setColumnData(this, "identity", options);
|
|
4108
4231
|
}
|
|
4109
4232
|
}
|
|
4110
4233
|
class IntegerColumn extends IntegerBaseColumn {
|
|
4111
|
-
constructor() {
|
|
4112
|
-
super(
|
|
4113
|
-
this.dataType = "
|
|
4234
|
+
constructor(schema) {
|
|
4235
|
+
super(schema);
|
|
4236
|
+
this.dataType = "int4";
|
|
4114
4237
|
this.parseItem = parseInt;
|
|
4238
|
+
this.data.alias = "integer";
|
|
4115
4239
|
}
|
|
4116
|
-
toCode(t) {
|
|
4117
|
-
return intToCode(this, t);
|
|
4240
|
+
toCode(t, m) {
|
|
4241
|
+
return intToCode(this, t, "integer", m);
|
|
4118
4242
|
}
|
|
4119
4243
|
identity(options = {}) {
|
|
4120
4244
|
return orchidCore.setColumnData(this, "identity", options);
|
|
4121
4245
|
}
|
|
4122
4246
|
}
|
|
4123
4247
|
class BigIntColumn extends NumberAsStringBaseColumn {
|
|
4124
|
-
constructor() {
|
|
4125
|
-
super(
|
|
4126
|
-
this.dataType = "
|
|
4248
|
+
constructor(schema) {
|
|
4249
|
+
super(schema);
|
|
4250
|
+
this.dataType = "int8";
|
|
4251
|
+
this.data.alias = "bigint";
|
|
4127
4252
|
}
|
|
4128
|
-
toCode(t) {
|
|
4129
|
-
return intToCode(this, t);
|
|
4253
|
+
toCode(t, m) {
|
|
4254
|
+
return intToCode(this, t, "bigint", m);
|
|
4130
4255
|
}
|
|
4131
4256
|
identity(options = {}) {
|
|
4132
4257
|
return orchidCore.setColumnData(this, "identity", options);
|
|
@@ -4135,68 +4260,75 @@ class BigIntColumn extends NumberAsStringBaseColumn {
|
|
|
4135
4260
|
class RealColumn extends NumberBaseColumn {
|
|
4136
4261
|
constructor(schema) {
|
|
4137
4262
|
super(schema, schema.number());
|
|
4138
|
-
this.dataType = "
|
|
4263
|
+
this.dataType = "float4";
|
|
4139
4264
|
this.parseItem = parseFloat;
|
|
4265
|
+
this.data.alias = "real";
|
|
4140
4266
|
}
|
|
4141
|
-
toCode(t) {
|
|
4142
|
-
return columnCode(this, t, `real()${orchidCore.numberDataToCode(this.data)}
|
|
4267
|
+
toCode(t, m) {
|
|
4268
|
+
return columnCode(this, t, `real()${orchidCore.numberDataToCode(this.data, m)}`, m);
|
|
4143
4269
|
}
|
|
4144
4270
|
}
|
|
4145
4271
|
class DoublePrecisionColumn extends NumberAsStringBaseColumn {
|
|
4146
|
-
constructor() {
|
|
4147
|
-
super(
|
|
4148
|
-
this.dataType = "
|
|
4272
|
+
constructor(schema) {
|
|
4273
|
+
super(schema);
|
|
4274
|
+
this.dataType = "float8";
|
|
4275
|
+
this.data.alias = "doublePrecision";
|
|
4149
4276
|
}
|
|
4150
|
-
toCode(t) {
|
|
4151
|
-
return columnCode(this, t, `doublePrecision()
|
|
4277
|
+
toCode(t, m) {
|
|
4278
|
+
return columnCode(this, t, `doublePrecision()`, m);
|
|
4152
4279
|
}
|
|
4153
4280
|
}
|
|
4154
4281
|
class SmallSerialColumn extends IntegerBaseColumn {
|
|
4155
4282
|
constructor(schema) {
|
|
4156
4283
|
super(schema);
|
|
4157
|
-
this.dataType = "
|
|
4284
|
+
this.dataType = "int2";
|
|
4158
4285
|
this.parseItem = parseInt;
|
|
4159
4286
|
this.data.int = true;
|
|
4287
|
+
this.data.alias = "smallSerial";
|
|
4160
4288
|
}
|
|
4161
4289
|
toSQL() {
|
|
4162
4290
|
return "smallserial";
|
|
4163
4291
|
}
|
|
4164
|
-
toCode(t) {
|
|
4292
|
+
toCode(t, m) {
|
|
4165
4293
|
return columnCode(
|
|
4166
4294
|
this,
|
|
4167
4295
|
t,
|
|
4168
|
-
`smallSerial()${orchidCore.numberDataToCode(this.data, skipNumberMethods)}
|
|
4296
|
+
`smallSerial()${orchidCore.numberDataToCode(this.data, m, skipNumberMethods)}`,
|
|
4297
|
+
m
|
|
4169
4298
|
);
|
|
4170
4299
|
}
|
|
4171
4300
|
}
|
|
4172
4301
|
class SerialColumn extends IntegerBaseColumn {
|
|
4173
4302
|
constructor(schema) {
|
|
4174
4303
|
super(schema);
|
|
4175
|
-
this.dataType = "
|
|
4304
|
+
this.dataType = "int4";
|
|
4176
4305
|
this.parseItem = parseInt;
|
|
4177
4306
|
this.data.int = true;
|
|
4307
|
+
this.data.alias = "serial";
|
|
4178
4308
|
}
|
|
4179
4309
|
toSQL() {
|
|
4180
4310
|
return "serial";
|
|
4181
4311
|
}
|
|
4182
|
-
toCode(t) {
|
|
4312
|
+
toCode(t, m) {
|
|
4183
4313
|
return columnCode(
|
|
4184
4314
|
this,
|
|
4185
4315
|
t,
|
|
4186
|
-
`serial()${orchidCore.numberDataToCode(this.data, skipNumberMethods)}
|
|
4316
|
+
`serial()${orchidCore.numberDataToCode(this.data, m, skipNumberMethods)}`,
|
|
4317
|
+
m
|
|
4187
4318
|
);
|
|
4188
4319
|
}
|
|
4189
4320
|
}
|
|
4190
4321
|
class BigSerialColumn extends NumberAsStringBaseColumn {
|
|
4191
|
-
constructor() {
|
|
4192
|
-
super(
|
|
4193
|
-
this.dataType = "
|
|
4322
|
+
constructor(schema) {
|
|
4323
|
+
super(schema);
|
|
4324
|
+
this.dataType = "int8";
|
|
4325
|
+
this.data.alias = "bigint";
|
|
4194
4326
|
}
|
|
4195
4327
|
toSQL() {
|
|
4196
4328
|
return "bigserial";
|
|
4197
4329
|
}
|
|
4198
|
-
toCode(t) {
|
|
4199
|
-
return columnCode(this, t, `bigSerial()
|
|
4330
|
+
toCode(t, m) {
|
|
4331
|
+
return columnCode(this, t, `bigSerial()`, m);
|
|
4200
4332
|
}
|
|
4201
4333
|
}
|
|
4202
4334
|
|
|
@@ -4245,12 +4377,13 @@ class VarCharColumn extends LimitedTextBaseColumn {
|
|
|
4245
4377
|
super(...arguments);
|
|
4246
4378
|
this.dataType = "varchar";
|
|
4247
4379
|
}
|
|
4248
|
-
toCode(t) {
|
|
4380
|
+
toCode(t, m) {
|
|
4249
4381
|
const { maxChars } = this.data;
|
|
4250
4382
|
return columnCode(
|
|
4251
4383
|
this,
|
|
4252
4384
|
t,
|
|
4253
|
-
`varchar(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data)}
|
|
4385
|
+
`varchar(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data, m)}`,
|
|
4386
|
+
m
|
|
4254
4387
|
);
|
|
4255
4388
|
}
|
|
4256
4389
|
}
|
|
@@ -4258,14 +4391,15 @@ class StringColumn extends VarCharColumn {
|
|
|
4258
4391
|
constructor(schema, limit = 255) {
|
|
4259
4392
|
super(schema, limit);
|
|
4260
4393
|
}
|
|
4261
|
-
toCode(t) {
|
|
4394
|
+
toCode(t, m) {
|
|
4262
4395
|
let max = this.data.maxChars;
|
|
4263
4396
|
if (max === 255)
|
|
4264
4397
|
max = void 0;
|
|
4265
4398
|
return columnCode(
|
|
4266
4399
|
this,
|
|
4267
4400
|
t,
|
|
4268
|
-
`string(${max != null ? max : ""})${orchidCore.stringDataToCode(this.data)}
|
|
4401
|
+
`string(${max != null ? max : ""})${orchidCore.stringDataToCode(this.data, m)}`,
|
|
4402
|
+
m
|
|
4269
4403
|
);
|
|
4270
4404
|
}
|
|
4271
4405
|
}
|
|
@@ -4274,12 +4408,13 @@ class CharColumn extends LimitedTextBaseColumn {
|
|
|
4274
4408
|
super(...arguments);
|
|
4275
4409
|
this.dataType = "char";
|
|
4276
4410
|
}
|
|
4277
|
-
toCode(t) {
|
|
4411
|
+
toCode(t, m) {
|
|
4278
4412
|
const { maxChars } = this.data;
|
|
4279
4413
|
return columnCode(
|
|
4280
4414
|
this,
|
|
4281
4415
|
t,
|
|
4282
|
-
`char(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data)}
|
|
4416
|
+
`char(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data, m)}`,
|
|
4417
|
+
m
|
|
4283
4418
|
);
|
|
4284
4419
|
}
|
|
4285
4420
|
}
|
|
@@ -4291,7 +4426,7 @@ const setTextColumnData = (column, minArg, maxArg) => {
|
|
|
4291
4426
|
}
|
|
4292
4427
|
}
|
|
4293
4428
|
};
|
|
4294
|
-
const textColumnToCode = (column, t) => {
|
|
4429
|
+
const textColumnToCode = (column, t, m) => {
|
|
4295
4430
|
const data = __spreadValues$9({}, column.data);
|
|
4296
4431
|
let args = "";
|
|
4297
4432
|
const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
|
|
@@ -4310,7 +4445,8 @@ const textColumnToCode = (column, t) => {
|
|
|
4310
4445
|
return columnCode(
|
|
4311
4446
|
column,
|
|
4312
4447
|
t,
|
|
4313
|
-
`${column.dataType}(${args})${orchidCore.stringDataToCode(data)}
|
|
4448
|
+
`${column.dataType}(${args})${orchidCore.stringDataToCode(data, m)}`,
|
|
4449
|
+
m
|
|
4314
4450
|
);
|
|
4315
4451
|
};
|
|
4316
4452
|
const minMaxToSchema = (schema, min, max) => min ? max ? schema.stringMinMax(min, max) : schema.stringMin(min) : schema.stringSchema();
|
|
@@ -4320,8 +4456,8 @@ class TextColumn extends TextBaseColumn {
|
|
|
4320
4456
|
this.dataType = "text";
|
|
4321
4457
|
setTextColumnData(this, min, max);
|
|
4322
4458
|
}
|
|
4323
|
-
toCode(t) {
|
|
4324
|
-
return textColumnToCode(this, t);
|
|
4459
|
+
toCode(t, m) {
|
|
4460
|
+
return textColumnToCode(this, t, m);
|
|
4325
4461
|
}
|
|
4326
4462
|
}
|
|
4327
4463
|
class ByteaColumn extends ColumnType {
|
|
@@ -4330,8 +4466,8 @@ class ByteaColumn extends ColumnType {
|
|
|
4330
4466
|
this.dataType = "bytea";
|
|
4331
4467
|
this.operators = Operators.text;
|
|
4332
4468
|
}
|
|
4333
|
-
toCode(t) {
|
|
4334
|
-
return columnCode(this, t, `bytea()
|
|
4469
|
+
toCode(t, m) {
|
|
4470
|
+
return columnCode(this, t, `bytea()`, m);
|
|
4335
4471
|
}
|
|
4336
4472
|
}
|
|
4337
4473
|
class PointColumn extends ColumnType {
|
|
@@ -4340,8 +4476,8 @@ class PointColumn extends ColumnType {
|
|
|
4340
4476
|
this.dataType = "point";
|
|
4341
4477
|
this.operators = Operators.text;
|
|
4342
4478
|
}
|
|
4343
|
-
toCode(t) {
|
|
4344
|
-
return columnCode(this, t, `point()
|
|
4479
|
+
toCode(t, m) {
|
|
4480
|
+
return columnCode(this, t, `point()`, m);
|
|
4345
4481
|
}
|
|
4346
4482
|
}
|
|
4347
4483
|
class LineColumn extends ColumnType {
|
|
@@ -4350,8 +4486,8 @@ class LineColumn extends ColumnType {
|
|
|
4350
4486
|
this.dataType = "line";
|
|
4351
4487
|
this.operators = Operators.text;
|
|
4352
4488
|
}
|
|
4353
|
-
toCode(t) {
|
|
4354
|
-
return columnCode(this, t, `line()
|
|
4489
|
+
toCode(t, m) {
|
|
4490
|
+
return columnCode(this, t, `line()`, m);
|
|
4355
4491
|
}
|
|
4356
4492
|
}
|
|
4357
4493
|
class LsegColumn extends ColumnType {
|
|
@@ -4360,8 +4496,8 @@ class LsegColumn extends ColumnType {
|
|
|
4360
4496
|
this.dataType = "lseg";
|
|
4361
4497
|
this.operators = Operators.text;
|
|
4362
4498
|
}
|
|
4363
|
-
toCode(t) {
|
|
4364
|
-
return columnCode(this, t, `lseg()
|
|
4499
|
+
toCode(t, m) {
|
|
4500
|
+
return columnCode(this, t, `lseg()`, m);
|
|
4365
4501
|
}
|
|
4366
4502
|
}
|
|
4367
4503
|
class BoxColumn extends ColumnType {
|
|
@@ -4370,8 +4506,8 @@ class BoxColumn extends ColumnType {
|
|
|
4370
4506
|
this.dataType = "box";
|
|
4371
4507
|
this.operators = Operators.text;
|
|
4372
4508
|
}
|
|
4373
|
-
toCode(t) {
|
|
4374
|
-
return columnCode(this, t, `box()
|
|
4509
|
+
toCode(t, m) {
|
|
4510
|
+
return columnCode(this, t, `box()`, m);
|
|
4375
4511
|
}
|
|
4376
4512
|
}
|
|
4377
4513
|
class PathColumn extends ColumnType {
|
|
@@ -4380,8 +4516,8 @@ class PathColumn extends ColumnType {
|
|
|
4380
4516
|
this.dataType = "path";
|
|
4381
4517
|
this.operators = Operators.text;
|
|
4382
4518
|
}
|
|
4383
|
-
toCode(t) {
|
|
4384
|
-
return columnCode(this, t, `path()
|
|
4519
|
+
toCode(t, m) {
|
|
4520
|
+
return columnCode(this, t, `path()`, m);
|
|
4385
4521
|
}
|
|
4386
4522
|
}
|
|
4387
4523
|
class PolygonColumn extends ColumnType {
|
|
@@ -4390,8 +4526,8 @@ class PolygonColumn extends ColumnType {
|
|
|
4390
4526
|
this.dataType = "polygon";
|
|
4391
4527
|
this.operators = Operators.text;
|
|
4392
4528
|
}
|
|
4393
|
-
toCode(t) {
|
|
4394
|
-
return columnCode(this, t, `polygon()
|
|
4529
|
+
toCode(t, m) {
|
|
4530
|
+
return columnCode(this, t, `polygon()`, m);
|
|
4395
4531
|
}
|
|
4396
4532
|
}
|
|
4397
4533
|
class CircleColumn extends ColumnType {
|
|
@@ -4400,8 +4536,8 @@ class CircleColumn extends ColumnType {
|
|
|
4400
4536
|
this.dataType = "circle";
|
|
4401
4537
|
this.operators = Operators.text;
|
|
4402
4538
|
}
|
|
4403
|
-
toCode(t) {
|
|
4404
|
-
return columnCode(this, t, `circle()
|
|
4539
|
+
toCode(t, m) {
|
|
4540
|
+
return columnCode(this, t, `circle()`, m);
|
|
4405
4541
|
}
|
|
4406
4542
|
}
|
|
4407
4543
|
class MoneyColumn extends NumberBaseColumn {
|
|
@@ -4417,8 +4553,8 @@ class MoneyColumn extends NumberBaseColumn {
|
|
|
4417
4553
|
}
|
|
4418
4554
|
);
|
|
4419
4555
|
}
|
|
4420
|
-
toCode(t) {
|
|
4421
|
-
return columnCode(this, t, `money()
|
|
4556
|
+
toCode(t, m) {
|
|
4557
|
+
return columnCode(this, t, `money()`, m);
|
|
4422
4558
|
}
|
|
4423
4559
|
}
|
|
4424
4560
|
class CidrColumn extends ColumnType {
|
|
@@ -4427,8 +4563,8 @@ class CidrColumn extends ColumnType {
|
|
|
4427
4563
|
this.dataType = "cidr";
|
|
4428
4564
|
this.operators = Operators.text;
|
|
4429
4565
|
}
|
|
4430
|
-
toCode(t) {
|
|
4431
|
-
return columnCode(this, t, `cidr()
|
|
4566
|
+
toCode(t, m) {
|
|
4567
|
+
return columnCode(this, t, `cidr()`, m);
|
|
4432
4568
|
}
|
|
4433
4569
|
}
|
|
4434
4570
|
class InetColumn extends ColumnType {
|
|
@@ -4437,8 +4573,8 @@ class InetColumn extends ColumnType {
|
|
|
4437
4573
|
this.dataType = "inet";
|
|
4438
4574
|
this.operators = Operators.text;
|
|
4439
4575
|
}
|
|
4440
|
-
toCode(t) {
|
|
4441
|
-
return columnCode(this, t, `inet()
|
|
4576
|
+
toCode(t, m) {
|
|
4577
|
+
return columnCode(this, t, `inet()`, m);
|
|
4442
4578
|
}
|
|
4443
4579
|
}
|
|
4444
4580
|
class MacAddrColumn extends ColumnType {
|
|
@@ -4447,8 +4583,8 @@ class MacAddrColumn extends ColumnType {
|
|
|
4447
4583
|
this.dataType = "macaddr";
|
|
4448
4584
|
this.operators = Operators.text;
|
|
4449
4585
|
}
|
|
4450
|
-
toCode(t) {
|
|
4451
|
-
return columnCode(this, t, `macaddr()
|
|
4586
|
+
toCode(t, m) {
|
|
4587
|
+
return columnCode(this, t, `macaddr()`, m);
|
|
4452
4588
|
}
|
|
4453
4589
|
}
|
|
4454
4590
|
class MacAddr8Column extends ColumnType {
|
|
@@ -4457,8 +4593,8 @@ class MacAddr8Column extends ColumnType {
|
|
|
4457
4593
|
this.dataType = "macaddr8";
|
|
4458
4594
|
this.operators = Operators.text;
|
|
4459
4595
|
}
|
|
4460
|
-
toCode(t) {
|
|
4461
|
-
return columnCode(this, t, `macaddr8()
|
|
4596
|
+
toCode(t, m) {
|
|
4597
|
+
return columnCode(this, t, `macaddr8()`, m);
|
|
4462
4598
|
}
|
|
4463
4599
|
}
|
|
4464
4600
|
class BitColumn extends ColumnType {
|
|
@@ -4468,9 +4604,9 @@ class BitColumn extends ColumnType {
|
|
|
4468
4604
|
this.operators = Operators.text;
|
|
4469
4605
|
this.data.length = length;
|
|
4470
4606
|
}
|
|
4471
|
-
toCode(t) {
|
|
4607
|
+
toCode(t, m) {
|
|
4472
4608
|
const { length } = this.data;
|
|
4473
|
-
return columnCode(this, t, `bit(${length})
|
|
4609
|
+
return columnCode(this, t, `bit(${length})`, m);
|
|
4474
4610
|
}
|
|
4475
4611
|
toSQL() {
|
|
4476
4612
|
return orchidCore.joinTruthy(
|
|
@@ -4482,13 +4618,14 @@ class BitColumn extends ColumnType {
|
|
|
4482
4618
|
class BitVaryingColumn extends ColumnType {
|
|
4483
4619
|
constructor(schema, length) {
|
|
4484
4620
|
super(schema, schema.bit(length));
|
|
4485
|
-
this.dataType = "
|
|
4621
|
+
this.dataType = "varbit";
|
|
4486
4622
|
this.operators = Operators.text;
|
|
4487
4623
|
this.data.length = length;
|
|
4624
|
+
this.data.alias = "bitVarying";
|
|
4488
4625
|
}
|
|
4489
|
-
toCode(t) {
|
|
4626
|
+
toCode(t, m) {
|
|
4490
4627
|
const { length } = this.data;
|
|
4491
|
-
return columnCode(this, t, `bitVarying(${length != null ? length : ""})
|
|
4628
|
+
return columnCode(this, t, `bitVarying(${length != null ? length : ""})`, m);
|
|
4492
4629
|
}
|
|
4493
4630
|
toSQL() {
|
|
4494
4631
|
return orchidCore.joinTruthy(
|
|
@@ -4504,8 +4641,8 @@ class TsVectorColumn extends ColumnType {
|
|
|
4504
4641
|
this.dataType = "tsvector";
|
|
4505
4642
|
this.operators = Operators.text;
|
|
4506
4643
|
}
|
|
4507
|
-
toCode(t) {
|
|
4508
|
-
return columnCode(this, t, `tsvector()
|
|
4644
|
+
toCode(t, m) {
|
|
4645
|
+
return columnCode(this, t, `tsvector()`, m);
|
|
4509
4646
|
}
|
|
4510
4647
|
/**
|
|
4511
4648
|
* For `tsvector` column type, it can also accept language (optional) and columns:
|
|
@@ -4535,14 +4672,17 @@ class TsVectorColumn extends ColumnType {
|
|
|
4535
4672
|
const first = args[0];
|
|
4536
4673
|
if (typeof first === "string" || !("raw" in first)) {
|
|
4537
4674
|
const target = typeof first === "string" ? args[1] : first;
|
|
4675
|
+
const language = typeof first === "string" ? first : this.defaultLanguage;
|
|
4538
4676
|
let sql;
|
|
4539
4677
|
if (Array.isArray(target)) {
|
|
4540
4678
|
const columns = target.length === 1 ? `"${target[0]}"` : target.map((column) => `coalesce("${column}", '')`).join(` || ' ' || `);
|
|
4541
|
-
sql = `to_tsvector('${
|
|
4679
|
+
sql = `to_tsvector('${language}', ${columns})`;
|
|
4542
4680
|
} else {
|
|
4543
4681
|
for (const key in target) {
|
|
4544
|
-
sql = (sql ? sql + " || " : "") + `setweight(to_tsvector(coalesce("${key}", '')), '${target[key]}')`;
|
|
4682
|
+
sql = (sql ? sql + " || " : "(") + `setweight(to_tsvector('${language}', coalesce("${key}", '')), '${target[key]}')`;
|
|
4545
4683
|
}
|
|
4684
|
+
if (sql)
|
|
4685
|
+
sql += ")";
|
|
4546
4686
|
}
|
|
4547
4687
|
const arr = [sql];
|
|
4548
4688
|
arr.raw = arr;
|
|
@@ -4557,8 +4697,8 @@ class TsQueryColumn extends ColumnType {
|
|
|
4557
4697
|
this.dataType = "tsquery";
|
|
4558
4698
|
this.operators = Operators.text;
|
|
4559
4699
|
}
|
|
4560
|
-
toCode(t) {
|
|
4561
|
-
return columnCode(this, t, `tsquery()
|
|
4700
|
+
toCode(t, m) {
|
|
4701
|
+
return columnCode(this, t, `tsquery()`, m);
|
|
4562
4702
|
}
|
|
4563
4703
|
}
|
|
4564
4704
|
const uuidDefaultSQL = "gen_random_uuid()";
|
|
@@ -4575,12 +4715,13 @@ class UUIDColumn extends ColumnType {
|
|
|
4575
4715
|
column.data.default = uuidDefault;
|
|
4576
4716
|
return column;
|
|
4577
4717
|
}
|
|
4578
|
-
toCode(t) {
|
|
4718
|
+
toCode(t, m) {
|
|
4579
4719
|
const { data } = this;
|
|
4580
4720
|
return columnCode(
|
|
4581
4721
|
this,
|
|
4582
4722
|
t,
|
|
4583
4723
|
`uuid()`,
|
|
4724
|
+
m,
|
|
4584
4725
|
// don't output the default default
|
|
4585
4726
|
data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$5(__spreadValues$9({}, data), { default: void 0 }) : data
|
|
4586
4727
|
);
|
|
@@ -4592,8 +4733,8 @@ class XMLColumn extends ColumnType {
|
|
|
4592
4733
|
this.dataType = "xml";
|
|
4593
4734
|
this.operators = Operators.text;
|
|
4594
4735
|
}
|
|
4595
|
-
toCode(t) {
|
|
4596
|
-
return columnCode(this, t, `xml()
|
|
4736
|
+
toCode(t, m) {
|
|
4737
|
+
return columnCode(this, t, `xml()`, m);
|
|
4597
4738
|
}
|
|
4598
4739
|
}
|
|
4599
4740
|
class CitextColumn extends TextBaseColumn {
|
|
@@ -4602,20 +4743,21 @@ class CitextColumn extends TextBaseColumn {
|
|
|
4602
4743
|
this.dataType = "citext";
|
|
4603
4744
|
setTextColumnData(this, min, max);
|
|
4604
4745
|
}
|
|
4605
|
-
toCode(t) {
|
|
4606
|
-
return textColumnToCode(this, t);
|
|
4746
|
+
toCode(t, m) {
|
|
4747
|
+
return textColumnToCode(this, t, m);
|
|
4607
4748
|
}
|
|
4608
4749
|
}
|
|
4609
4750
|
|
|
4610
4751
|
class BooleanColumn extends ColumnType {
|
|
4611
4752
|
constructor(schema) {
|
|
4612
4753
|
super(schema, schema.boolean());
|
|
4613
|
-
this.dataType = "
|
|
4754
|
+
this.dataType = "bool";
|
|
4614
4755
|
this.operators = Operators.boolean;
|
|
4615
4756
|
this.parseItem = (input) => input[0] === "t";
|
|
4757
|
+
this.data.alias = "boolean";
|
|
4616
4758
|
}
|
|
4617
|
-
toCode(t) {
|
|
4618
|
-
return columnCode(this, t, "boolean()");
|
|
4759
|
+
toCode(t, m) {
|
|
4760
|
+
return columnCode(this, t, "boolean()", m);
|
|
4619
4761
|
}
|
|
4620
4762
|
}
|
|
4621
4763
|
|
|
@@ -4631,8 +4773,8 @@ class CustomTypeColumn extends ColumnType {
|
|
|
4631
4773
|
this.operators = Operators.any;
|
|
4632
4774
|
this.data.isOfCustomType = true;
|
|
4633
4775
|
}
|
|
4634
|
-
toCode(t) {
|
|
4635
|
-
return columnCode(this, t, `type(${orchidCore.singleQuote(this.dataType)})
|
|
4776
|
+
toCode(t, m) {
|
|
4777
|
+
return columnCode(this, t, `type(${orchidCore.singleQuote(this.dataType)})`, m);
|
|
4636
4778
|
}
|
|
4637
4779
|
as(column) {
|
|
4638
4780
|
const c = orchidCore.setColumnData(
|
|
@@ -4647,8 +4789,8 @@ class CustomTypeColumn extends ColumnType {
|
|
|
4647
4789
|
}
|
|
4648
4790
|
}
|
|
4649
4791
|
class DomainColumn extends CustomTypeColumn {
|
|
4650
|
-
toCode(t) {
|
|
4651
|
-
return columnCode(this, t, `domain(${orchidCore.singleQuote(this.dataType)})
|
|
4792
|
+
toCode(t, m) {
|
|
4793
|
+
return columnCode(this, t, `domain(${orchidCore.singleQuote(this.dataType)})`, m);
|
|
4652
4794
|
}
|
|
4653
4795
|
}
|
|
4654
4796
|
|
|
@@ -4827,7 +4969,7 @@ const makeColumnTypes = (schema) => {
|
|
|
4827
4969
|
* See {@link ColumnType.searchIndex}
|
|
4828
4970
|
*/
|
|
4829
4971
|
searchIndex(columns, options) {
|
|
4830
|
-
return this.index(columns, __spreadProps$4(__spreadValues$8({}, options), { tsVector: true }));
|
|
4972
|
+
return this.index(columns, __spreadProps$4(__spreadValues$8({ using: "gin" }, options), { tsVector: true }));
|
|
4831
4973
|
},
|
|
4832
4974
|
constraint({ name, references, check, dropMode }) {
|
|
4833
4975
|
var _a;
|
|
@@ -4858,11 +5000,11 @@ const makeColumnTypes = (schema) => {
|
|
|
4858
5000
|
});
|
|
4859
5001
|
return orchidCore.emptyObject;
|
|
4860
5002
|
},
|
|
4861
|
-
check(check) {
|
|
5003
|
+
check(check, options) {
|
|
4862
5004
|
var _a;
|
|
4863
|
-
((_a = tableData.constraints) != null ? _a : tableData.constraints = []).push({
|
|
5005
|
+
((_a = tableData.constraints) != null ? _a : tableData.constraints = []).push(__spreadProps$4(__spreadValues$8({}, options), {
|
|
4864
5006
|
check
|
|
4865
|
-
});
|
|
5007
|
+
}));
|
|
4866
5008
|
return orchidCore.emptyObject;
|
|
4867
5009
|
}
|
|
4868
5010
|
}, orchidCore.makeTimestampsHelpers(makeRegexToFindInSql));
|
|
@@ -4981,6 +5123,8 @@ for (const key in types.builtins) {
|
|
|
4981
5123
|
delete defaultTypeParsers[id];
|
|
4982
5124
|
});
|
|
4983
5125
|
const returnArg = (arg) => arg;
|
|
5126
|
+
const rollbackSql$1 = { text: "ROLLBACK" };
|
|
5127
|
+
const commitSql$1 = { text: "COMMIT" };
|
|
4984
5128
|
class Adapter {
|
|
4985
5129
|
constructor(_a) {
|
|
4986
5130
|
var _b = _a, { types: types2 = defaultTypeParsers } = _b, config = __objRest$1(_b, ["types"]);
|
|
@@ -5022,7 +5166,7 @@ class Adapter {
|
|
|
5022
5166
|
arrays(query, types2) {
|
|
5023
5167
|
return performQuery$1(this, query, types2, "array");
|
|
5024
5168
|
}
|
|
5025
|
-
async transaction(begin, cb) {
|
|
5169
|
+
async transaction(begin, cb, end = commitSql$1) {
|
|
5026
5170
|
const client = await this.connect();
|
|
5027
5171
|
try {
|
|
5028
5172
|
await setSearchPath(client, this.schema);
|
|
@@ -5031,10 +5175,10 @@ class Adapter {
|
|
|
5031
5175
|
try {
|
|
5032
5176
|
result = await cb(new TransactionAdapter(this, client, this.types));
|
|
5033
5177
|
} catch (err) {
|
|
5034
|
-
await performQueryOnClient(client,
|
|
5178
|
+
await performQueryOnClient(client, rollbackSql$1, this.types);
|
|
5035
5179
|
throw err;
|
|
5036
5180
|
}
|
|
5037
|
-
await performQueryOnClient(client,
|
|
5181
|
+
await performQueryOnClient(client, end, this.types);
|
|
5038
5182
|
return result;
|
|
5039
5183
|
} finally {
|
|
5040
5184
|
client.release();
|
|
@@ -6046,12 +6190,15 @@ const _queryCreateMany = (q, data) => {
|
|
|
6046
6190
|
};
|
|
6047
6191
|
const _queryInsertMany = (q, data) => {
|
|
6048
6192
|
const ctx = createCtx();
|
|
6049
|
-
|
|
6193
|
+
let result = insert(
|
|
6050
6194
|
q,
|
|
6051
6195
|
handleManyData(q, data, ctx),
|
|
6052
6196
|
"object",
|
|
6053
6197
|
true
|
|
6054
6198
|
);
|
|
6199
|
+
if (!data.length)
|
|
6200
|
+
result = result.none();
|
|
6201
|
+
return result;
|
|
6055
6202
|
};
|
|
6056
6203
|
const _queryCreateRaw = (q, args) => {
|
|
6057
6204
|
createSelect(q);
|
|
@@ -7949,7 +8096,7 @@ const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values
|
|
|
7949
8096
|
const elapsed = process.hrtime(time);
|
|
7950
8097
|
const formattedTime = `(${elapsed[0] ? `${elapsed[0]}s ` : ""}${(elapsed[1] / 1e6).toFixed(1)}ms)`;
|
|
7951
8098
|
const result = `${colors ? timeColor(formattedTime) : formattedTime} ${colors ? sqlColor(sql) : sql}`;
|
|
7952
|
-
if (!values.length) {
|
|
8099
|
+
if (!(values == null ? void 0 : values.length)) {
|
|
7953
8100
|
return result;
|
|
7954
8101
|
}
|
|
7955
8102
|
const formattedValues = `[${values.map(quote).join(", ")}]`;
|
|
@@ -10720,7 +10867,7 @@ class QueryMethods {
|
|
|
10720
10867
|
* ```
|
|
10721
10868
|
*/
|
|
10722
10869
|
none() {
|
|
10723
|
-
return extendQuery(this, noneMethods);
|
|
10870
|
+
return this.then === noneMethods.then ? this : extendQuery(this, noneMethods);
|
|
10724
10871
|
}
|
|
10725
10872
|
/**
|
|
10726
10873
|
* `modify` allows modifying the query with your function:
|
|
@@ -10907,21 +11054,23 @@ var __objRest = (source, exclude) => {
|
|
|
10907
11054
|
};
|
|
10908
11055
|
const anyShape = {};
|
|
10909
11056
|
class Db {
|
|
10910
|
-
constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options) {
|
|
11057
|
+
constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = getTableData()) {
|
|
10911
11058
|
this.adapter = adapter;
|
|
10912
11059
|
this.queryBuilder = queryBuilder;
|
|
10913
11060
|
this.table = table;
|
|
10914
11061
|
this.shape = shape;
|
|
10915
11062
|
this.columnTypes = columnTypes;
|
|
11063
|
+
this.tableData = tableData;
|
|
10916
11064
|
var _a, _b;
|
|
10917
11065
|
const self = this;
|
|
10918
11066
|
const { softDelete } = options;
|
|
10919
11067
|
const scopes = options.scopes || softDelete ? {} : orchidCore.emptyObject;
|
|
10920
|
-
const tableData = getTableData();
|
|
10921
11068
|
this.internal = __spreadProps(__spreadValues({}, tableData), {
|
|
10922
11069
|
transactionStorage,
|
|
10923
11070
|
scopes,
|
|
10924
|
-
snakeCase: options.snakeCase
|
|
11071
|
+
snakeCase: options.snakeCase,
|
|
11072
|
+
noPrimaryKey: options.noPrimaryKey === "ignore",
|
|
11073
|
+
comment: options.comment
|
|
10925
11074
|
});
|
|
10926
11075
|
this.baseQuery = this;
|
|
10927
11076
|
const logger = options.logger || console;
|
|
@@ -10989,7 +11138,7 @@ class Db {
|
|
|
10989
11138
|
this.q.schema = options.schema;
|
|
10990
11139
|
}
|
|
10991
11140
|
this.primaryKeys = Object.keys(shape).filter(
|
|
10992
|
-
(key) => shape[key].data.
|
|
11141
|
+
(key) => shape[key].data.primaryKey
|
|
10993
11142
|
);
|
|
10994
11143
|
const primaryKeysFromData = (_b = getTableData().primaryKey) == null ? void 0 : _b.columns;
|
|
10995
11144
|
if (primaryKeysFromData)
|
|
@@ -11185,16 +11334,13 @@ const createDb = (_a) => {
|
|
|
11185
11334
|
ct[orchidCore.snakeCaseKey] = true;
|
|
11186
11335
|
}
|
|
11187
11336
|
const transactionStorage = new node_async_hooks.AsyncLocalStorage();
|
|
11188
|
-
const qb =
|
|
11337
|
+
const qb = _initQueryBuilder(
|
|
11189
11338
|
adapter,
|
|
11190
|
-
void 0,
|
|
11191
|
-
void 0,
|
|
11192
|
-
anyShape,
|
|
11193
11339
|
ct,
|
|
11194
11340
|
transactionStorage,
|
|
11195
|
-
commonOptions
|
|
11341
|
+
commonOptions,
|
|
11342
|
+
options
|
|
11196
11343
|
);
|
|
11197
|
-
qb.queryBuilder = qb;
|
|
11198
11344
|
const tableConstructor = (table, shape, options2) => new Db(
|
|
11199
11345
|
adapter,
|
|
11200
11346
|
qb,
|
|
@@ -11213,6 +11359,33 @@ const createDb = (_a) => {
|
|
|
11213
11359
|
}
|
|
11214
11360
|
return db;
|
|
11215
11361
|
};
|
|
11362
|
+
const _initQueryBuilder = (adapter, columnTypes, transactionStorage, commonOptions, options) => {
|
|
11363
|
+
const qb = new Db(
|
|
11364
|
+
adapter,
|
|
11365
|
+
void 0,
|
|
11366
|
+
void 0,
|
|
11367
|
+
anyShape,
|
|
11368
|
+
columnTypes,
|
|
11369
|
+
transactionStorage,
|
|
11370
|
+
commonOptions,
|
|
11371
|
+
orchidCore.emptyObject
|
|
11372
|
+
);
|
|
11373
|
+
if (options.extensions) {
|
|
11374
|
+
const arr = [];
|
|
11375
|
+
for (const x of options.extensions) {
|
|
11376
|
+
if (typeof x === "string") {
|
|
11377
|
+
arr.push({ name: x });
|
|
11378
|
+
} else {
|
|
11379
|
+
for (const key in x) {
|
|
11380
|
+
arr.push({ name: key, version: x[key] });
|
|
11381
|
+
}
|
|
11382
|
+
}
|
|
11383
|
+
}
|
|
11384
|
+
qb.internal.extensions = arr;
|
|
11385
|
+
}
|
|
11386
|
+
qb.internal.domains = options.domains;
|
|
11387
|
+
return qb.queryBuilder = qb;
|
|
11388
|
+
};
|
|
11216
11389
|
|
|
11217
11390
|
class Rollback extends Error {
|
|
11218
11391
|
}
|
|
@@ -11445,6 +11618,7 @@ exports.VirtualColumn = VirtualColumn;
|
|
|
11445
11618
|
exports.Where = Where;
|
|
11446
11619
|
exports.With = With;
|
|
11447
11620
|
exports.XMLColumn = XMLColumn;
|
|
11621
|
+
exports._initQueryBuilder = _initQueryBuilder;
|
|
11448
11622
|
exports._queryAfterSaveCommit = _queryAfterSaveCommit;
|
|
11449
11623
|
exports._queryAll = _queryAll;
|
|
11450
11624
|
exports._queryAs = _queryAs;
|
|
@@ -11512,6 +11686,7 @@ exports.columnCode = columnCode;
|
|
|
11512
11686
|
exports.columnForeignKeysToCode = columnForeignKeysToCode;
|
|
11513
11687
|
exports.columnIndexesToCode = columnIndexesToCode;
|
|
11514
11688
|
exports.columnsShapeToCode = columnsShapeToCode;
|
|
11689
|
+
exports.constraintInnerToCode = constraintInnerToCode;
|
|
11515
11690
|
exports.constraintPropsToCode = constraintPropsToCode;
|
|
11516
11691
|
exports.constraintToCode = constraintToCode;
|
|
11517
11692
|
exports.copyTableData = copyTableData;
|
|
@@ -11529,6 +11704,7 @@ exports.getShapeFromSelect = getShapeFromSelect;
|
|
|
11529
11704
|
exports.getTableData = getTableData;
|
|
11530
11705
|
exports.handleResult = handleResult;
|
|
11531
11706
|
exports.identityToCode = identityToCode;
|
|
11707
|
+
exports.indexInnerToCode = indexInnerToCode;
|
|
11532
11708
|
exports.indexToCode = indexToCode;
|
|
11533
11709
|
exports.instantiateColumn = instantiateColumn;
|
|
11534
11710
|
exports.isDefaultTimeStamp = isDefaultTimeStamp;
|
|
@@ -11546,6 +11722,7 @@ exports.makeSQL = makeSQL;
|
|
|
11546
11722
|
exports.newTableData = newTableData;
|
|
11547
11723
|
exports.parseRecord = parseRecord;
|
|
11548
11724
|
exports.parseResult = parseResult;
|
|
11725
|
+
exports.primaryKeyInnerToCode = primaryKeyInnerToCode;
|
|
11549
11726
|
exports.primaryKeyToCode = primaryKeyToCode;
|
|
11550
11727
|
exports.processSelectArg = processSelectArg;
|
|
11551
11728
|
exports.pushLimitSQL = pushLimitSQL;
|