pqb 0.36.12 → 0.36.14
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 +30 -20
- package/dist/index.js +29 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2209,22 +2209,16 @@ declare class Where {
|
|
|
2209
2209
|
*
|
|
2210
2210
|
* ### JSONB column operators
|
|
2211
2211
|
*
|
|
2212
|
-
*
|
|
2212
|
+
* JSON functions are available only for the `jsonb` column, note that the `json` type has text operators instead.
|
|
2213
2213
|
*
|
|
2214
|
-
*
|
|
2214
|
+
* You can use [jsonPathQueryFirst](/guide/json.html#jsonpathqueryfirst) to filter by a JSON value, follow the link for details.
|
|
2215
2215
|
*
|
|
2216
|
-
*
|
|
2216
|
+
* The value can be of any type, it can also be returned from a sub-query, raw SQL expression.
|
|
2217
2217
|
*
|
|
2218
2218
|
* ```ts
|
|
2219
|
-
* db.table.where(
|
|
2220
|
-
* jsonbColumn
|
|
2221
|
-
*
|
|
2222
|
-
* '$.name', // first element is JSON path
|
|
2223
|
-
* '=', // second argument is comparison operator
|
|
2224
|
-
* 'value', // third argument is a value to compare with
|
|
2225
|
-
* ],
|
|
2226
|
-
* },
|
|
2227
|
-
* });
|
|
2219
|
+
* db.table.where((q) =>
|
|
2220
|
+
* q.get('jsonbColumn').jsonPathQueryFirst('$.name').equals(value),
|
|
2221
|
+
* );
|
|
2228
2222
|
* ```
|
|
2229
2223
|
*
|
|
2230
2224
|
* `jsonSupersetOf`: check if the column value is a superset of provided value.
|
|
@@ -2250,7 +2244,7 @@ declare class Where {
|
|
|
2250
2244
|
* ```ts
|
|
2251
2245
|
* db.table.where({
|
|
2252
2246
|
* jsonbColumn: {
|
|
2253
|
-
*
|
|
2247
|
+
* jsonSubsetOf: { a: 1 },
|
|
2254
2248
|
* },
|
|
2255
2249
|
* });
|
|
2256
2250
|
* ```
|
|
@@ -3285,9 +3279,16 @@ type DbOptions<SchemaConfig extends ColumnSchemaConfig, ColumnTypes> = ({
|
|
|
3285
3279
|
};
|
|
3286
3280
|
interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape extends QueryColumns> extends QueryLogOptions {
|
|
3287
3281
|
schema?: string;
|
|
3282
|
+
/**
|
|
3283
|
+
* Prepare all SQL queries before executing,
|
|
3284
|
+
* true by default
|
|
3285
|
+
*/
|
|
3288
3286
|
autoPreparedStatements?: boolean;
|
|
3289
3287
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
3290
3288
|
snakeCase?: boolean;
|
|
3289
|
+
/**
|
|
3290
|
+
* Default language for the full text search
|
|
3291
|
+
*/
|
|
3291
3292
|
language?: string;
|
|
3292
3293
|
/**
|
|
3293
3294
|
* See {@link ScopeMethods}
|
|
@@ -3297,8 +3298,18 @@ interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape ex
|
|
|
3297
3298
|
* See {@link SoftDeleteMethods}
|
|
3298
3299
|
*/
|
|
3299
3300
|
softDelete?: SoftDeleteOption<Shape>;
|
|
3301
|
+
/**
|
|
3302
|
+
* Table comment, for migrations generator
|
|
3303
|
+
*/
|
|
3300
3304
|
comment?: string;
|
|
3305
|
+
/**
|
|
3306
|
+
* Computed SQL or JS columns definitions
|
|
3307
|
+
*/
|
|
3301
3308
|
computed?: ComputedOptionsFactory<ColumnTypes, Shape>;
|
|
3309
|
+
/**
|
|
3310
|
+
* For customizing `now()` sql, used in soft delete
|
|
3311
|
+
*/
|
|
3312
|
+
nowSQL?: string;
|
|
3302
3313
|
}
|
|
3303
3314
|
/**
|
|
3304
3315
|
* See {@link ScopeMethods}
|
|
@@ -3497,7 +3508,7 @@ interface DbResult<ColumnTypes> extends Db<string, never, never, never, never, n
|
|
|
3497
3508
|
* })
|
|
3498
3509
|
* ```
|
|
3499
3510
|
*/
|
|
3500
|
-
declare const createDb: <SchemaConfig extends ColumnSchemaConfig<ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>> = DefaultSchemaConfig, ColumnTypes = DefaultColumnTypes<SchemaConfig>>({ log, logger, snakeCase,
|
|
3511
|
+
declare const createDb: <SchemaConfig extends ColumnSchemaConfig<ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>> = DefaultSchemaConfig, ColumnTypes = DefaultColumnTypes<SchemaConfig>>({ log, logger, snakeCase, schemaConfig, columnTypes: ctOrFn, ...options }: DbOptions<SchemaConfig, ColumnTypes>) => DbResult<ColumnTypes>;
|
|
3501
3512
|
declare const _initQueryBuilder: (adapter: Adapter, columnTypes: unknown, transactionStorage: AsyncLocalStorage<TransactionState>, commonOptions: DbTableOptions<unknown, undefined, QueryColumns>, options: DbSharedOptions) => Db;
|
|
3502
3513
|
|
|
3503
3514
|
interface ToSQLCtx {
|
|
@@ -4628,8 +4639,6 @@ type DeleteResult<T extends PickQueryMetaResult> = T['meta']['hasSelect'] extend
|
|
|
4628
4639
|
declare const _queryDelete: <T extends PickQueryMetaResult>(query: T) => DeleteResult<T>;
|
|
4629
4640
|
declare class Delete {
|
|
4630
4641
|
/**
|
|
4631
|
-
* It is aliased to `del` because `delete` is a reserved word in JavaScript.
|
|
4632
|
-
*
|
|
4633
4642
|
* This method deletes one or more rows, based on other conditions specified in the query.
|
|
4634
4643
|
*
|
|
4635
4644
|
* By default, `delete` will return a count of deleted records.
|
|
@@ -6519,7 +6528,7 @@ type OrderArgKey<T extends OrderArgSelf> = {
|
|
|
6519
6528
|
type GroupArgs<T extends PickQueryResult> = ({
|
|
6520
6529
|
[K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K;
|
|
6521
6530
|
}[keyof T['result']] | Expression)[];
|
|
6522
|
-
interface QueryHelper<T extends PickQueryMetaShape, Args extends
|
|
6531
|
+
interface QueryHelper<T extends PickQueryMetaShape, Args extends any[], Result> {
|
|
6523
6532
|
<Q extends {
|
|
6524
6533
|
returnType: QueryReturnType;
|
|
6525
6534
|
meta: QueryMetaBase & {
|
|
@@ -6531,7 +6540,7 @@ interface QueryHelper<T extends PickQueryMetaShape, Args extends unknown[], Resu
|
|
|
6531
6540
|
}>(q: Q, ...args: Args): Result extends Query ? MergeQuery<Q, Result> : Result;
|
|
6532
6541
|
result: Result;
|
|
6533
6542
|
}
|
|
6534
|
-
type QueryHelperResult<T extends QueryHelper<Query,
|
|
6543
|
+
type QueryHelperResult<T extends QueryHelper<Query, any[], unknown>> = T['result'];
|
|
6535
6544
|
type NarrowTypeResult<T extends PickQueryMetaResultReturnType, Narrow> = {
|
|
6536
6545
|
[K in keyof T['result']]: K extends keyof Narrow ? {
|
|
6537
6546
|
[P in keyof T['result'][K]]: P extends 'outputType' ? Narrow[K] extends T['result'][K]['outputType'] ? Narrow[K] : `narrowType() error: passed type does not exist in '${K & string}'s type union` : T['result'][K][P];
|
|
@@ -6673,7 +6682,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
6673
6682
|
* Finds a single record with a given SQL, throws {@link NotFoundError} if not found:
|
|
6674
6683
|
*
|
|
6675
6684
|
* ```ts
|
|
6676
|
-
* await db.user.
|
|
6685
|
+
* await db.user.findBySql`
|
|
6677
6686
|
* age = ${age} AND
|
|
6678
6687
|
* name = ${name}
|
|
6679
6688
|
* `;
|
|
@@ -6698,7 +6707,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
6698
6707
|
* Returns `undefined` when not found.
|
|
6699
6708
|
*
|
|
6700
6709
|
* ```ts
|
|
6701
|
-
* await db.user.
|
|
6710
|
+
* await db.user.findBySqlOptional`
|
|
6702
6711
|
* age = ${age} AND
|
|
6703
6712
|
* name = ${name}
|
|
6704
6713
|
* `;
|
|
@@ -7135,6 +7144,7 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
|
|
|
7135
7144
|
extensions?: DbExtension[];
|
|
7136
7145
|
domains?: DbDomainArgRecord;
|
|
7137
7146
|
tableData: TableData;
|
|
7147
|
+
nowSQL?: string;
|
|
7138
7148
|
primaryKeys?: string[];
|
|
7139
7149
|
}
|
|
7140
7150
|
type SelectableFromShape<Shape extends QueryColumns, Table extends string | undefined> = {
|
package/dist/index.js
CHANGED
|
@@ -1908,18 +1908,6 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
1908
1908
|
}
|
|
1909
1909
|
return `"${tableName}"."${key}"`;
|
|
1910
1910
|
};
|
|
1911
|
-
const columnToSqlWithAs = (ctx, data, column, quotedAs, select) => {
|
|
1912
|
-
const index = column.indexOf(".");
|
|
1913
|
-
return index !== -1 ? tableColumnToSqlWithAs(
|
|
1914
|
-
ctx,
|
|
1915
|
-
data,
|
|
1916
|
-
column,
|
|
1917
|
-
column.slice(0, index),
|
|
1918
|
-
column.slice(index + 1),
|
|
1919
|
-
quotedAs,
|
|
1920
|
-
select
|
|
1921
|
-
) : ownColumnToSqlWithAs(ctx, data, column, quotedAs, select);
|
|
1922
|
-
};
|
|
1923
1911
|
const tableColumnToSqlWithAs = (ctx, data, column, table, key, quotedAs, select) => {
|
|
1924
1912
|
var _a, _b, _c;
|
|
1925
1913
|
if (key === "*") {
|
|
@@ -4543,11 +4531,9 @@ class SelectItemExpression extends orchidCore.Expression {
|
|
|
4543
4531
|
if (value)
|
|
4544
4532
|
Object.assign(this, value.operators);
|
|
4545
4533
|
}
|
|
4546
|
-
// `makeSQL` acts similarly to how select args are handled
|
|
4547
|
-
// except that it will use non-aliasing `columnToSql` when `ctx.aliasValue` is true,
|
|
4548
|
-
// it is needed for relation sub-queries that returns a single column.
|
|
4534
|
+
// `makeSQL` acts similarly to how select args are handled
|
|
4549
4535
|
makeSQL(ctx, quotedAs) {
|
|
4550
|
-
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(this.query, this.q, quotedAs) :
|
|
4536
|
+
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(this.query, this.q, quotedAs) : columnToSql(ctx, this.q, this.q.shape, this.item, quotedAs, true) : this.item.toSQL(ctx, quotedAs);
|
|
4551
4537
|
}
|
|
4552
4538
|
}
|
|
4553
4539
|
|
|
@@ -7889,8 +7875,6 @@ const _queryDelete = (query) => {
|
|
|
7889
7875
|
};
|
|
7890
7876
|
class Delete {
|
|
7891
7877
|
/**
|
|
7892
|
-
* It is aliased to `del` because `delete` is a reserved word in JavaScript.
|
|
7893
|
-
*
|
|
7894
7878
|
* This method deletes one or more rows, based on other conditions specified in the query.
|
|
7895
7879
|
*
|
|
7896
7880
|
* By default, `delete` will return a count of deleted records.
|
|
@@ -9833,22 +9817,16 @@ class Where {
|
|
|
9833
9817
|
*
|
|
9834
9818
|
* ### JSONB column operators
|
|
9835
9819
|
*
|
|
9836
|
-
*
|
|
9820
|
+
* JSON functions are available only for the `jsonb` column, note that the `json` type has text operators instead.
|
|
9837
9821
|
*
|
|
9838
|
-
*
|
|
9822
|
+
* You can use [jsonPathQueryFirst](/guide/json.html#jsonpathqueryfirst) to filter by a JSON value, follow the link for details.
|
|
9839
9823
|
*
|
|
9840
|
-
*
|
|
9824
|
+
* The value can be of any type, it can also be returned from a sub-query, raw SQL expression.
|
|
9841
9825
|
*
|
|
9842
9826
|
* ```ts
|
|
9843
|
-
* db.table.where(
|
|
9844
|
-
* jsonbColumn
|
|
9845
|
-
*
|
|
9846
|
-
* '$.name', // first element is JSON path
|
|
9847
|
-
* '=', // second argument is comparison operator
|
|
9848
|
-
* 'value', // third argument is a value to compare with
|
|
9849
|
-
* ],
|
|
9850
|
-
* },
|
|
9851
|
-
* });
|
|
9827
|
+
* db.table.where((q) =>
|
|
9828
|
+
* q.get('jsonbColumn').jsonPathQueryFirst('$.name').equals(value),
|
|
9829
|
+
* );
|
|
9852
9830
|
* ```
|
|
9853
9831
|
*
|
|
9854
9832
|
* `jsonSupersetOf`: check if the column value is a superset of provided value.
|
|
@@ -9874,7 +9852,7 @@ class Where {
|
|
|
9874
9852
|
* ```ts
|
|
9875
9853
|
* db.table.where({
|
|
9876
9854
|
* jsonbColumn: {
|
|
9877
|
-
*
|
|
9855
|
+
* jsonSubsetOf: { a: 1 },
|
|
9878
9856
|
* },
|
|
9879
9857
|
* });
|
|
9880
9858
|
* ```
|
|
@@ -11290,14 +11268,14 @@ function enableSoftDelete(q, table, shape, softDelete, scopes) {
|
|
|
11290
11268
|
};
|
|
11291
11269
|
scopes.deleted = scope;
|
|
11292
11270
|
((_b = (_a = q.q).scopes) != null ? _b : _a.scopes = {}).nonDeleted = scope;
|
|
11293
|
-
const _del = _softDelete(column);
|
|
11271
|
+
const _del = _softDelete(column, q.internal.nowSQL);
|
|
11294
11272
|
q.baseQuery.delete = function() {
|
|
11295
11273
|
return _del.call(this.clone());
|
|
11296
11274
|
};
|
|
11297
11275
|
}
|
|
11298
11276
|
const nowSql = new RawSQL("now()");
|
|
11299
|
-
const _softDelete = (column) => {
|
|
11300
|
-
const set = { [column]: nowSql };
|
|
11277
|
+
const _softDelete = (column, customNowSQL) => {
|
|
11278
|
+
const set = { [column]: customNowSQL ? new RawSQL(customNowSQL) : nowSql };
|
|
11301
11279
|
return function() {
|
|
11302
11280
|
return _queryUpdate(this, set);
|
|
11303
11281
|
};
|
|
@@ -11692,7 +11670,7 @@ class QueryMethods {
|
|
|
11692
11670
|
* Finds a single record with a given SQL, throws {@link NotFoundError} if not found:
|
|
11693
11671
|
*
|
|
11694
11672
|
* ```ts
|
|
11695
|
-
* await db.user.
|
|
11673
|
+
* await db.user.findBySql`
|
|
11696
11674
|
* age = ${age} AND
|
|
11697
11675
|
* name = ${name}
|
|
11698
11676
|
* `;
|
|
@@ -11722,7 +11700,7 @@ class QueryMethods {
|
|
|
11722
11700
|
* Returns `undefined` when not found.
|
|
11723
11701
|
*
|
|
11724
11702
|
* ```ts
|
|
11725
|
-
* await db.user.
|
|
11703
|
+
* await db.user.findBySqlOptional`
|
|
11726
11704
|
* age = ${age} AND
|
|
11727
11705
|
* name = ${name}
|
|
11728
11706
|
* `;
|
|
@@ -12345,6 +12323,7 @@ class Db {
|
|
|
12345
12323
|
snakeCase: options.snakeCase,
|
|
12346
12324
|
noPrimaryKey: options.noPrimaryKey === "ignore",
|
|
12347
12325
|
comment: options.comment,
|
|
12326
|
+
nowSQL: options.nowSQL,
|
|
12348
12327
|
tableData
|
|
12349
12328
|
};
|
|
12350
12329
|
this.baseQuery = this;
|
|
@@ -12586,14 +12565,12 @@ const createDb = (_a) => {
|
|
|
12586
12565
|
log,
|
|
12587
12566
|
logger,
|
|
12588
12567
|
snakeCase,
|
|
12589
|
-
nowSQL,
|
|
12590
12568
|
schemaConfig = defaultSchemaConfig,
|
|
12591
12569
|
columnTypes: ctOrFn = makeColumnTypes(schemaConfig)
|
|
12592
12570
|
} = _b, options = __objRest(_b, [
|
|
12593
12571
|
"log",
|
|
12594
12572
|
"logger",
|
|
12595
12573
|
"snakeCase",
|
|
12596
|
-
"nowSQL",
|
|
12597
12574
|
"schemaConfig",
|
|
12598
12575
|
"columnTypes"
|
|
12599
12576
|
]);
|
|
@@ -12604,6 +12581,7 @@ const createDb = (_a) => {
|
|
|
12604
12581
|
logger,
|
|
12605
12582
|
autoPreparedStatements: (_a2 = options.autoPreparedStatements) != null ? _a2 : false,
|
|
12606
12583
|
noPrimaryKey: (_b2 = options.noPrimaryKey) != null ? _b2 : "error",
|
|
12584
|
+
nowSQL: options.nowSQL,
|
|
12607
12585
|
snakeCase
|
|
12608
12586
|
};
|
|
12609
12587
|
const ct = typeof ctOrFn === "function" ? ctOrFn(makeColumnTypes(schemaConfig)) : ctOrFn;
|
|
@@ -12618,16 +12596,19 @@ const createDb = (_a) => {
|
|
|
12618
12596
|
commonOptions,
|
|
12619
12597
|
options
|
|
12620
12598
|
);
|
|
12621
|
-
const
|
|
12622
|
-
|
|
12623
|
-
|
|
12624
|
-
|
|
12625
|
-
|
|
12626
|
-
|
|
12627
|
-
|
|
12628
|
-
|
|
12629
|
-
|
|
12630
|
-
|
|
12599
|
+
const { nowSQL } = options;
|
|
12600
|
+
const tableConstructor = (table, shape, dataFn, options2) => {
|
|
12601
|
+
return new Db(
|
|
12602
|
+
adapter,
|
|
12603
|
+
qb,
|
|
12604
|
+
table,
|
|
12605
|
+
typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options2 == null ? void 0 : options2.language) : shape,
|
|
12606
|
+
ct,
|
|
12607
|
+
transactionStorage,
|
|
12608
|
+
__spreadValues(__spreadValues({}, commonOptions), options2),
|
|
12609
|
+
parseTableData(dataFn)
|
|
12610
|
+
);
|
|
12611
|
+
};
|
|
12631
12612
|
const db = Object.assign(tableConstructor, qb, {
|
|
12632
12613
|
adapter,
|
|
12633
12614
|
close: () => adapter.close()
|