pqb 0.11.17 → 0.11.19
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 +3 -2
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -837,6 +837,7 @@ type DbOptions<CT extends ColumnTypesBase> = ({
|
|
|
837
837
|
autoPreparedStatements?: boolean;
|
|
838
838
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
839
839
|
snakeCase?: boolean;
|
|
840
|
+
nowSQL?: string;
|
|
840
841
|
};
|
|
841
842
|
type DbTableOptions = {
|
|
842
843
|
schema?: string;
|
|
@@ -884,7 +885,7 @@ type DbResult<CT extends ColumnTypesBase> = Db<string, Record<string, never>, Qu
|
|
|
884
885
|
adapter: Adapter;
|
|
885
886
|
close: Adapter['close'];
|
|
886
887
|
};
|
|
887
|
-
declare const createDb: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>>({ log, logger, columnTypes: ctOrFn, snakeCase, ...options }: DbOptions<CT>) => DbResult<CT>;
|
|
888
|
+
declare const createDb: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>>({ log, logger, columnTypes: ctOrFn, snakeCase, nowSQL, ...options }: DbOptions<CT>) => DbResult<CT>;
|
|
888
889
|
|
|
889
890
|
type WithArgsOptions = Omit<WithOptions, 'columns'> & {
|
|
890
891
|
columns?: boolean | string[];
|
|
@@ -3408,7 +3409,7 @@ declare const getConstraintKind: (it: TableData.Constraint) => 'constraint' | 'f
|
|
|
3408
3409
|
declare const newTableData: () => TableData;
|
|
3409
3410
|
declare const getTableData: () => TableData;
|
|
3410
3411
|
declare const resetTableData: (data?: TableData) => void;
|
|
3411
|
-
declare const getColumnTypes: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>, Shape extends ColumnsShape>(types: CT, fn: (t: CT) => Shape, data?: TableData) => Shape;
|
|
3412
|
+
declare const getColumnTypes: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>, Shape extends ColumnsShape>(types: CT, fn: (t: CT) => Shape, nowSQL: string | undefined, data?: TableData) => Shape;
|
|
3412
3413
|
declare function text(min: number, max: number): TextColumn;
|
|
3413
3414
|
type DefaultColumnTypes = typeof columnTypes;
|
|
3414
3415
|
declare const columnTypes: {
|
package/dist/index.js
CHANGED
|
@@ -377,7 +377,7 @@ const isDefaultTimeStamp = (item) => {
|
|
|
377
377
|
if (item.dataType !== "timestamptz")
|
|
378
378
|
return false;
|
|
379
379
|
const def = item.data.default;
|
|
380
|
-
return def && orchidCore.isRaw(def) && def.__raw
|
|
380
|
+
return def && orchidCore.isRaw(def) && def.__raw.startsWith("now()");
|
|
381
381
|
};
|
|
382
382
|
const combineCodeElements = (input) => {
|
|
383
383
|
if (typeof input === "string")
|
|
@@ -3249,7 +3249,9 @@ const getTableData = () => tableData;
|
|
|
3249
3249
|
const resetTableData = (data = newTableData()) => {
|
|
3250
3250
|
tableData = data;
|
|
3251
3251
|
};
|
|
3252
|
-
const getColumnTypes = (types, fn, data = newTableData()) => {
|
|
3252
|
+
const getColumnTypes = (types, fn, nowSQL, data = newTableData()) => {
|
|
3253
|
+
if (nowSQL)
|
|
3254
|
+
orchidCore.setDefaultNowFn(nowSQL);
|
|
3253
3255
|
resetTableData(data);
|
|
3254
3256
|
return fn(types);
|
|
3255
3257
|
};
|
|
@@ -3465,9 +3467,9 @@ const columnTypes = __spreadValues$9({
|
|
|
3465
3467
|
}
|
|
3466
3468
|
}, orchidCore.makeTimestampsHelpers(
|
|
3467
3469
|
makeRegexToFindInSql('\\bupdatedAt\\b"?\\s*='),
|
|
3468
|
-
|
|
3470
|
+
'"updatedAt"',
|
|
3469
3471
|
makeRegexToFindInSql('\\bupdated_at\\b"?\\s*='),
|
|
3470
|
-
|
|
3472
|
+
'"updated_at"'
|
|
3471
3473
|
));
|
|
3472
3474
|
|
|
3473
3475
|
class ColumnsObject extends ColumnType {
|
|
@@ -3982,6 +3984,13 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
3982
3984
|
query = value.wrap(value.baseQuery.clone())._jsonAgg(value.query.select[0]);
|
|
3983
3985
|
value.query.coalesceValue = orchidCore.raw("'[]'");
|
|
3984
3986
|
} else {
|
|
3987
|
+
if ((returnType === "value" || returnType === "valueOrThrow") && value.query.select) {
|
|
3988
|
+
if (typeof value.query.select[0] === "string") {
|
|
3989
|
+
value.query.select[0] = {
|
|
3990
|
+
selectAs: { r: value.query.select[0] }
|
|
3991
|
+
};
|
|
3992
|
+
}
|
|
3993
|
+
}
|
|
3985
3994
|
query = value;
|
|
3986
3995
|
}
|
|
3987
3996
|
_joinLateral(q, "LEFT JOIN", query, (q2) => q2, key);
|
|
@@ -6545,12 +6554,14 @@ const createDb = (_a) => {
|
|
|
6545
6554
|
log,
|
|
6546
6555
|
logger,
|
|
6547
6556
|
columnTypes: ctOrFn = columnTypes,
|
|
6548
|
-
snakeCase
|
|
6557
|
+
snakeCase,
|
|
6558
|
+
nowSQL
|
|
6549
6559
|
} = _b, options = __objRest(_b, [
|
|
6550
6560
|
"log",
|
|
6551
6561
|
"logger",
|
|
6552
6562
|
"columnTypes",
|
|
6553
|
-
"snakeCase"
|
|
6563
|
+
"snakeCase",
|
|
6564
|
+
"nowSQL"
|
|
6554
6565
|
]);
|
|
6555
6566
|
var _a2, _b2;
|
|
6556
6567
|
const adapter = "adapter" in options ? options.adapter : new Adapter(options);
|
|
@@ -6582,7 +6593,7 @@ const createDb = (_a) => {
|
|
|
6582
6593
|
adapter,
|
|
6583
6594
|
qb,
|
|
6584
6595
|
table,
|
|
6585
|
-
typeof shape === "function" ? getColumnTypes(ct, shape) : shape,
|
|
6596
|
+
typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL) : shape,
|
|
6586
6597
|
ct,
|
|
6587
6598
|
transactionStorage,
|
|
6588
6599
|
__spreadValues(__spreadValues({}, commonOptions), options2)
|