pqb 0.35.7 → 0.36.0
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 +4 -1
- package/dist/index.js +33 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7362,7 +7362,10 @@ interface ColumnData extends ColumnDataBase {
|
|
|
7362
7362
|
compression?: string;
|
|
7363
7363
|
foreignKeys?: TableData.ColumnReferences[];
|
|
7364
7364
|
identity?: TableData.Identity;
|
|
7365
|
-
generated
|
|
7365
|
+
generated?(ctx: {
|
|
7366
|
+
values: unknown[];
|
|
7367
|
+
snakeCase: boolean | undefined;
|
|
7368
|
+
}, quotedAs?: string): string;
|
|
7366
7369
|
}
|
|
7367
7370
|
interface ColumnFromDbParams {
|
|
7368
7371
|
isNullable?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -380,7 +380,8 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
380
380
|
* @param args - raw SQL
|
|
381
381
|
*/
|
|
382
382
|
generated(...args) {
|
|
383
|
-
|
|
383
|
+
const sql = raw(...args);
|
|
384
|
+
return orchidCore.setColumnData(this, "generated", (...args2) => sql.toSQL(...args2));
|
|
384
385
|
}
|
|
385
386
|
}
|
|
386
387
|
|
|
@@ -461,6 +462,10 @@ const columnsShapeToCode = (shape, t) => {
|
|
|
461
462
|
for (const key in shape) {
|
|
462
463
|
if (hasTimestamps && (key === "createdAt" || key === "updatedAt"))
|
|
463
464
|
continue;
|
|
465
|
+
const column = shape[key];
|
|
466
|
+
const name = column.data.name;
|
|
467
|
+
if (name === key)
|
|
468
|
+
column.data.name = void 0;
|
|
464
469
|
code.push(
|
|
465
470
|
...combineCodeElements([
|
|
466
471
|
`${orchidCore.quoteObjectKey(key)}: `,
|
|
@@ -468,6 +473,8 @@ const columnsShapeToCode = (shape, t) => {
|
|
|
468
473
|
","
|
|
469
474
|
])
|
|
470
475
|
);
|
|
476
|
+
if (name === key)
|
|
477
|
+
column.data.name = name;
|
|
471
478
|
}
|
|
472
479
|
if (hasTimestamps) {
|
|
473
480
|
code.push(`...${t}.timestamps(),`);
|
|
@@ -1517,26 +1524,33 @@ class TsVectorColumn extends ColumnType {
|
|
|
1517
1524
|
* @param args
|
|
1518
1525
|
*/
|
|
1519
1526
|
generated(...args) {
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1527
|
+
return orchidCore.setColumnData(this, "generated", (ctx, quotedAs) => {
|
|
1528
|
+
const first = args[0];
|
|
1529
|
+
if (typeof first === "string" || !("raw" in first)) {
|
|
1530
|
+
const target = typeof first === "string" ? args[1] : first;
|
|
1531
|
+
const language = typeof first === "string" ? first : this.defaultLanguage;
|
|
1532
|
+
const { snakeCase } = ctx;
|
|
1533
|
+
let sql;
|
|
1534
|
+
if (Array.isArray(target)) {
|
|
1535
|
+
const columns = target.length === 1 ? `"${snakeCase ? orchidCore.toSnakeCase(target[0]) : target[0]}"` : target.map(
|
|
1536
|
+
(column) => `coalesce("${snakeCase ? orchidCore.toSnakeCase(column) : column}", '')`
|
|
1537
|
+
).join(` || ' ' || `);
|
|
1538
|
+
sql = `to_tsvector('${language}', ${columns})`;
|
|
1539
|
+
} else {
|
|
1540
|
+
for (const key in target) {
|
|
1541
|
+
sql = (sql ? sql + " || " : "(") + `setweight(to_tsvector('${language}', coalesce("${snakeCase ? orchidCore.toSnakeCase(key) : key}", '')), '${target[key]}')`;
|
|
1542
|
+
}
|
|
1543
|
+
if (sql) {
|
|
1544
|
+
sql += ")";
|
|
1545
|
+
} else {
|
|
1546
|
+
throw new Error("Empty target in the text search generated column");
|
|
1547
|
+
}
|
|
1531
1548
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1549
|
+
return sql;
|
|
1550
|
+
} else {
|
|
1551
|
+
return raw(...args).toSQL(ctx, quotedAs);
|
|
1534
1552
|
}
|
|
1535
|
-
|
|
1536
|
-
arr.raw = arr;
|
|
1537
|
-
args = [arr];
|
|
1538
|
-
}
|
|
1539
|
-
return super.generated(...args);
|
|
1553
|
+
});
|
|
1540
1554
|
}
|
|
1541
1555
|
}
|
|
1542
1556
|
class TsQueryColumn extends ColumnType {
|