pqb 0.67.7 → 0.68.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 +64 -5
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +61 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -604,6 +604,17 @@ interface AfterCommitStandaloneHook {
|
|
|
604
604
|
declare const makeConnectRetryConfig: (config: AdapterConfigConnectRetryParam) => AdapterConfigConnectRetry;
|
|
605
605
|
declare const wrapAdapterFnWithConnectRetry: <Fn extends (...args: any[]) => any>(connectRetryConfig: AdapterConfigConnectRetry, fn: Fn) => Fn;
|
|
606
606
|
declare const getDriverErrorCode: (err: object) => unknown;
|
|
607
|
+
interface SqlJoinExpression<T extends Column.Pick.QueryColumn> extends Expression<T>, ExpressionTypeMethod {}
|
|
608
|
+
declare class SqlJoinExpression<T extends Column.Pick.QueryColumn = Column.Pick.QueryColumn> extends Expression<T> {
|
|
609
|
+
items: readonly unknown[];
|
|
610
|
+
separator?: RawSqlBase | undefined;
|
|
611
|
+
result: {
|
|
612
|
+
value: T;
|
|
613
|
+
};
|
|
614
|
+
q: ExpressionData;
|
|
615
|
+
constructor(items: readonly unknown[], separator?: RawSqlBase | undefined);
|
|
616
|
+
makeSQL(ctx: ToSqlValues, quotedAs?: string): string;
|
|
617
|
+
}
|
|
607
618
|
/**
|
|
608
619
|
* Expression for a SQL identifier reference.
|
|
609
620
|
* Used to safely quote identifiers in raw SQL queries.
|
|
@@ -5242,6 +5253,8 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
5242
5253
|
then: QueryThenShallowSimplifyArr<ColumnsShape.DefaultOutput<Shape>>;
|
|
5243
5254
|
windows: EmptyObject;
|
|
5244
5255
|
relations: EmptyObject;
|
|
5256
|
+
relationsDataForCreate: EmptyObject;
|
|
5257
|
+
relationsDataForCreateOptional: EmptyObject;
|
|
5245
5258
|
relationQueries: EmptyObject;
|
|
5246
5259
|
withData: EmptyObject;
|
|
5247
5260
|
error: new (message: string, length: number, name: QueryErrorName) => QueryError<this>;
|
|
@@ -5322,6 +5335,7 @@ interface DbTableConstructor<ColumnTypes> {
|
|
|
5322
5335
|
interface DbSqlMethod<ColumnTypes> {
|
|
5323
5336
|
<T>(...args: StaticSQLArgs): RawSql<Column.Pick.QueryColumnOfType<T>, ColumnTypes>;
|
|
5324
5337
|
<T>(...args: [DynamicSQLArg<Column.Pick.QueryColumnOfType<T>>]): DynamicRawSQL<Column.Pick.QueryColumnOfType<T>, ColumnTypes>;
|
|
5338
|
+
join<T = unknown>(items: readonly unknown[], separator?: RawSqlBase): SqlJoinExpression<Column.Pick.QueryColumnOfType<T>>;
|
|
5325
5339
|
ref(name: string): SqlRefExpression;
|
|
5326
5340
|
unsafe(sql: string | number | boolean): UnsafeSqlExpression;
|
|
5327
5341
|
}
|
|
@@ -5531,6 +5545,37 @@ declare function raw<T = never>(...args: StaticSQLArgs): RawSql<Column.Pick.Quer
|
|
|
5531
5545
|
declare function raw<T = never>(...args: [DynamicSQLArg<Column.Pick.QueryColumnOfType<T>>]): DynamicRawSQL<Column.Pick.QueryColumnOfType<T>>;
|
|
5532
5546
|
interface SqlFn {
|
|
5533
5547
|
<T, Args extends TemplateLiteralArgs | [sql: string] | [values: RecordUnknown, sql?: string]>(this: T, ...args: Args): Args extends [RecordUnknown] ? (...sql: TemplateLiteralArgs) => RawSql<Column.Pick.QueryColumn, T> : RawSql<Column.Pick.QueryColumn, T>;
|
|
5548
|
+
/**
|
|
5549
|
+
* `sql.join` builds a SQL list from values and expressions.
|
|
5550
|
+
* Plain values are bound as query parameters, while SQL expressions render as SQL.
|
|
5551
|
+
*
|
|
5552
|
+
* Use it for SQL constructs such as `ARRAY[...]`, `IN (...)`, function arguments,
|
|
5553
|
+
* or tuple lists. The default separator is `, `. Provide a SQL expression as the
|
|
5554
|
+
* custom separator when a different separator is needed.
|
|
5555
|
+
*
|
|
5556
|
+
* ```ts
|
|
5557
|
+
* await db.user.whereSql`"id" IN (${sql.join([1, 2, 3])})`;
|
|
5558
|
+
* ```
|
|
5559
|
+
*
|
|
5560
|
+
* ```ts
|
|
5561
|
+
* await db.user.whereSql`
|
|
5562
|
+
* (${sql.join([sql.ref('name'), sql.ref('age')])}) IN (${sql.join(
|
|
5563
|
+
* users.map((user) => sql`(${user.name}, ${user.age})`),
|
|
5564
|
+
* )})
|
|
5565
|
+
* `;
|
|
5566
|
+
* ```
|
|
5567
|
+
*
|
|
5568
|
+
* ```ts
|
|
5569
|
+
* await db.user.select({
|
|
5570
|
+
* displayName: (q) =>
|
|
5571
|
+
* sql<string>`concat(${sql.join(
|
|
5572
|
+
* [q.column('firstName'), q.column('lastName')],
|
|
5573
|
+
* sql` || ' ' || `,
|
|
5574
|
+
* )})`,
|
|
5575
|
+
* });
|
|
5576
|
+
* ```
|
|
5577
|
+
*/
|
|
5578
|
+
join<T = unknown>(items: readonly unknown[], separator?: RawSqlBase): SqlJoinExpression<Column.Pick.QueryColumnOfType<T>>;
|
|
5534
5579
|
/**
|
|
5535
5580
|
* `sql.ref` quotes a SQL identifier such as a table name, column name, or schema name.
|
|
5536
5581
|
* Use it when you need to dynamically reference an identifier in raw SQL.
|
|
@@ -7803,13 +7848,14 @@ declare class QueryCreateFrom {
|
|
|
7803
7848
|
*/
|
|
7804
7849
|
insertForEachFrom<T extends CreateSelf>(this: T, query: IsQuery): InsertManyFromResult<T>;
|
|
7805
7850
|
}
|
|
7806
|
-
interface CreateSelf extends PickQueryHasSelect, PickQueryDefaults, PickQueryResult, PickQueryRelations, PickQueryWithData, PickQueryReturnType, PickQueryShape, PickQueryUniqueProperties, PickQueryInputType, Query.Pick.IsNotReadOnly {}
|
|
7851
|
+
interface CreateSelf extends PickQueryHasSelect, PickQueryDefaults, PickQueryResult, PickQueryRelations, PickQueryRelationsDataForCreate, PickQueryRelationsDataForCreateOptional, PickQueryWithData, PickQueryReturnType, PickQueryShape, PickQueryUniqueProperties, PickQueryInputType, Query.Pick.IsNotReadOnly {}
|
|
7807
7852
|
type CreateData<T extends CreateSelf> = EmptyObject extends T['relations'] ? CreateDataWithDefaults<T, keyof T['__defaults']> : CreateRelationsData<T>;
|
|
7808
7853
|
type CreateDataWithDefaults<T extends CreateSelf, Defaults extends PropertyKey> = { [K in keyof T['__inputType'] as K extends Defaults ? never : K]: K extends Defaults ? never : CreateColumn<T, K> } & { [K in Defaults]?: K extends keyof T['__inputType'] ? CreateColumn<T, K> : never };
|
|
7809
7854
|
type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends keyof T['__inputType'], OmitFKeys extends PropertyKey> = { [K in keyof T['__inputType'] as K extends Defaults | OmitFKeys ? never : K]: K extends Defaults | OmitFKeys ? never : CreateColumn<T, K> } & { [K in Defaults as K extends OmitFKeys ? never : K]?: CreateColumn<T, K> };
|
|
7810
7855
|
type CreateColumn<T extends CreateSelf, K extends keyof T['__inputType']> = T['__inputType'][K] | ((q: T) => QueryOrExpression<T['__inputType'][K]>);
|
|
7811
|
-
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['__defaults'], T['relations'][keyof T['relations']]['omitForeignKeyInCreate']> & CreateRelationsDataOmittingFKeys<T, T['
|
|
7812
|
-
type CreateRelationsDataOmittingFKeys<T extends CreateSelf,
|
|
7856
|
+
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['__defaults'], T['relations'][keyof T['relations']]['omitForeignKeyInCreate']> & CreateRelationsDataOmittingFKeys<T, T['relationsDataForCreate']> & T['relationsDataForCreateOptional'];
|
|
7857
|
+
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Data> = EmptyObject extends Data ? EmptyObject : { [K in keyof Data]: CreateRelationDataOmittingFKeys<T, Data[K]> }[keyof Data] extends ((u: infer Obj) => void) ? Obj : never;
|
|
7858
|
+
type CreateRelationDataOmittingFKeys<T extends CreateSelf, Union> = (u: Union extends RelationConfigDataForCreate ? Union['columns'] extends keyof T['__defaults'] ? Pick<CreateDataWithDefaults<T, keyof T['__defaults']>, Union['columns']> & Partial<Union['nested']> : (Pick<{ [P in keyof T['__inputType']]: CreateColumn<T, P> }, Union['columns'] & keyof T['__inputType']> & { [K in keyof Union['nested']]?: never }) | Union['nested'] : Union) => void;
|
|
7813
7859
|
type CreateResult<T extends CreateSelf, Data> = T extends {
|
|
7814
7860
|
isCount: true;
|
|
7815
7861
|
} ? T : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneResult<T, NarrowCreateResult<T, Data>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnResult<T, NarrowCreateResult<T, Data>> : SetQueryResult<T, NarrowCreateResult<T, Data>>;
|
|
@@ -10612,6 +10658,8 @@ interface Query extends IsQuery, PickQueryTable, PickQueryShape, PickQuerySelect
|
|
|
10612
10658
|
catch: QueryCatch;
|
|
10613
10659
|
windows: EmptyObject;
|
|
10614
10660
|
relations: RelationsBase;
|
|
10661
|
+
relationsDataForCreate: RelationsDataForCreateBase;
|
|
10662
|
+
relationsDataForCreateOptional: RelationsDataForCreateOptionalBase;
|
|
10615
10663
|
relationQueries: IsQueries;
|
|
10616
10664
|
error: new (message: string, length: number, name: QueryErrorName) => QueryError;
|
|
10617
10665
|
__readOnly: true | undefined;
|
|
@@ -10711,7 +10759,6 @@ interface RelationConfigBase extends IsQuery {
|
|
|
10711
10759
|
queryRelated(params: unknown): unknown;
|
|
10712
10760
|
modifyRelatedQuery?(relatedQuery: IsQuery): (query: IsQuery) => void;
|
|
10713
10761
|
omitForeignKeyInCreate: PropertyKey;
|
|
10714
|
-
dataForCreate: unknown;
|
|
10715
10762
|
dataForUpdate: unknown;
|
|
10716
10763
|
dataForUpdateOne: unknown;
|
|
10717
10764
|
primaryKeys: string[];
|
|
@@ -10721,7 +10768,13 @@ interface RelationConfigDataForCreate {
|
|
|
10721
10768
|
nested: RecordUnknown;
|
|
10722
10769
|
}
|
|
10723
10770
|
interface RelationsBase {
|
|
10724
|
-
[
|
|
10771
|
+
[relationName: string]: RelationConfigBase;
|
|
10772
|
+
}
|
|
10773
|
+
interface RelationsDataForCreateBase {
|
|
10774
|
+
[relationName: string]: unknown;
|
|
10775
|
+
}
|
|
10776
|
+
interface RelationsDataForCreateOptionalBase {
|
|
10777
|
+
[relationName: string]: unknown;
|
|
10725
10778
|
}
|
|
10726
10779
|
type RelationQueryMaybeSingle<T extends RelationConfigBase> = T['returnsOne'] extends true ? T['required'] extends true ? QueryManyTake<T['query']> : QueryManyTakeOptional<T['query']> : T['query'];
|
|
10727
10780
|
interface PickQueryTable {
|
|
@@ -10811,6 +10864,12 @@ interface PickQueryWindows {
|
|
|
10811
10864
|
interface PickQueryRelations {
|
|
10812
10865
|
relations: RelationsBase;
|
|
10813
10866
|
}
|
|
10867
|
+
interface PickQueryRelationsDataForCreate {
|
|
10868
|
+
relationsDataForCreate: RelationsDataForCreateBase;
|
|
10869
|
+
}
|
|
10870
|
+
interface PickQueryRelationsDataForCreateOptional {
|
|
10871
|
+
relationsDataForCreateOptional: RelationsDataForCreateOptionalBase;
|
|
10872
|
+
}
|
|
10814
10873
|
interface PickQueryColumTypes {
|
|
10815
10874
|
columnTypes: unknown;
|
|
10816
10875
|
}
|
package/dist/index.js
CHANGED
|
@@ -338,6 +338,29 @@ const templateLiteralSQLToCode = (sql) => {
|
|
|
338
338
|
code += parts[i];
|
|
339
339
|
return code + "`";
|
|
340
340
|
};
|
|
341
|
+
var SqlJoinExpression = class extends Expression {
|
|
342
|
+
constructor(items, separator) {
|
|
343
|
+
super();
|
|
344
|
+
this.items = items;
|
|
345
|
+
this.separator = separator;
|
|
346
|
+
this.result = { value: emptyObject };
|
|
347
|
+
this.q = { expr: this };
|
|
348
|
+
}
|
|
349
|
+
makeSQL(ctx, quotedAs) {
|
|
350
|
+
let sql = "";
|
|
351
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
352
|
+
if (i > 0) sql += this.separator ? this.separator.toSQL(ctx, quotedAs) : ", ";
|
|
353
|
+
const item = this.items[i];
|
|
354
|
+
if (item instanceof Expression) sql += item.toSQL(ctx, quotedAs);
|
|
355
|
+
else {
|
|
356
|
+
ctx.values.push(item);
|
|
357
|
+
sql += `$${ctx.values.length}`;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return sql;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
SqlJoinExpression.prototype.type = ExpressionTypeMethod.prototype.type;
|
|
341
364
|
/**
|
|
342
365
|
* Expression for a SQL identifier reference.
|
|
343
366
|
* Used to safely quote identifiers in raw SQL queries.
|
|
@@ -458,6 +481,7 @@ const sqlFn = ((...args) => {
|
|
|
458
481
|
return (...args) => new RawSql(args, arg);
|
|
459
482
|
});
|
|
460
483
|
sqlFn.ref = (name) => new SqlRefExpression(name);
|
|
484
|
+
sqlFn.join = (items, separator) => new SqlJoinExpression(items, separator);
|
|
461
485
|
sqlFn.unsafe = (sql) => new UnsafeSqlExpression(sql);
|
|
462
486
|
var UnsafeSqlExpression = class extends Expression {
|
|
463
487
|
constructor(sql) {
|
|
@@ -1872,9 +1896,11 @@ const ordinalText = {
|
|
|
1872
1896
|
};
|
|
1873
1897
|
const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
|
|
1874
1898
|
const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${addValue(ctx.values, path)}${options?.vars ? `, ${addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : options?.silent ? ", NULL, true" : ""})`;
|
|
1899
|
+
const shouldEncodeJson = (ctx) => ctx.q.adapter.driverAdapter.schemaConfig?.jsonEncodedByDriver === false;
|
|
1875
1900
|
const quoteJsonValue = (arg, ctx, quotedAs, IN) => {
|
|
1876
1901
|
if (arg && typeof arg === "object") {
|
|
1877
|
-
if (IN && Array.isArray(arg)) return `(${arg.map((value) => addValue(ctx.values, JSON.stringify(value))
|
|
1902
|
+
if (IN && Array.isArray(arg)) return `(${arg.map((value) => shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(value)) : addValue(ctx.values, value)).join(", ")})`;
|
|
1903
|
+
if (Array.isArray(arg)) return shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(arg)) : addValue(ctx.values, arg);
|
|
1878
1904
|
if (isExpression(arg)) return "to_jsonb(" + arg.toSQL(ctx, quotedAs) + ")";
|
|
1879
1905
|
if ("toSQL" in arg) return `to_jsonb((${moveMutativeQueryToCte$1(ctx, arg)}))`;
|
|
1880
1906
|
}
|
|
@@ -14260,6 +14286,7 @@ function _createDbSqlMethod(columnTypes) {
|
|
|
14260
14286
|
return sql;
|
|
14261
14287
|
});
|
|
14262
14288
|
fn.ref = sqlFn.ref;
|
|
14289
|
+
fn.join = sqlFn.join;
|
|
14263
14290
|
fn.unsafe = sqlFn.unsafe;
|
|
14264
14291
|
return fn;
|
|
14265
14292
|
}
|