pqb 0.12.4 → 0.12.5

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/LICENSE CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as orchid_core from 'orchid-core';
2
- import { QueryResultRow, AdapterBase, QueryInput, Sql, ColumnTypesBase, ColumnShapeOutput, DefaultSelectColumns, DbBase, QueryThen, QueryCatch, QueryBaseCommon, ColumnsShapeBase, QueryInternal, QueryMetaBase, EmptyObject, RawExpression, ColumnTypeBase, MaybeArray, ColumnsParsers, getValueKey, StringKey, ColumnOutput, NullableColumn, EmptyTuple, SetOptional, MergeObjects, CoalesceString, QueryCommon, Spread, BaseNumberData, Code, ColumnWithDefault, numberTypeMethods, BaseStringData, PrimaryKeyColumn, DateTypeMethods, DateColumnData, EncodeColumn, ParseColumn, JSONTypeAny, record, ArrayMethodsData, arrayMethods, ForeignKeyTable, name, ColumnNameOfTable, ColumnDataBase, BaseOperators, ValidationContext, MessageParam } from 'orchid-core';
2
+ import { QueryResultRow, AdapterBase, QueryInput, Sql, ColumnTypesBase, ColumnShapeOutput, DefaultSelectColumns, DbBase, QueryThen, QueryCatch, QueryBaseCommon, ColumnsShapeBase, QueryInternal, QueryMetaBase, EmptyObject, RawExpression, ColumnTypeBase, MaybeArray, ColumnsParsers, getValueKey, StringKey, ColumnOutput, NullableColumn, TemplateLiteralArgs, EmptyTuple, SetOptional, MergeObjects, CoalesceString, QueryCommon, Spread, BaseNumberData, Code, ColumnWithDefault, numberTypeMethods, BaseStringData, PrimaryKeyColumn, DateTypeMethods, DateColumnData, EncodeColumn, ParseColumn, JSONTypeAny, record, ArrayMethodsData, arrayMethods, ForeignKeyTable, name, ColumnNameOfTable, ColumnDataBase, BaseOperators, ValidationContext, MessageParam } from 'orchid-core';
3
3
  import { PoolConfig, Pool, PoolClient } from 'pg';
4
4
  import { inspect } from 'util';
5
5
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -434,7 +434,7 @@ type JoinOverrides = Record<string, string>;
434
434
  type CommonQueryData = {
435
435
  adapter: Adapter;
436
436
  shape: ColumnsShapeBase;
437
- patchResult?(queryResult: QueryResult): Promise<void>;
437
+ patchResult?(q: Query, queryResult: QueryResult): Promise<void>;
438
438
  handleResult(q: Query, result: QueryResult, isSubQuery?: true): unknown;
439
439
  returnType: QueryReturnType;
440
440
  [relationQueryKey]?: RelationQueryData;
@@ -742,7 +742,7 @@ type FromArgs<T extends Query> = [
742
742
  second?: {
743
743
  only?: boolean;
744
744
  }
745
- ] | [TemplateStringsArray, ...unknown[]];
745
+ ] | TemplateLiteralArgs;
746
746
  type FromResult<T extends Query, Args extends FromArgs<T>> = Args extends TemplateStringsArray ? T : Args[0] extends string ? T['withData'] extends Record<string, WithDataItem> ? Args[0] extends keyof T['withData'] ? Omit<T, 'meta' | 'selectable'> & {
747
747
  meta: Omit<T['meta'], 'as'> & {
748
748
  as?: string;
@@ -802,7 +802,7 @@ type WhereArg<T extends QueryBase> = (Omit<{
802
802
  values: unknown[][] | Query | RawExpression;
803
803
  }>;
804
804
  }) | QueryBase | RawExpression | ((q: WhereQueryBuilder<T>) => WhereQueryBuilder);
805
- type WhereArgs<T extends QueryBase> = WhereArg<T>[] | [TemplateStringsArray, ...unknown[]];
805
+ type WhereArgs<T extends QueryBase> = WhereArg<T>[] | TemplateLiteralArgs;
806
806
  type WhereInColumn<T extends QueryBase> = keyof T['selectable'] | [keyof T['selectable'], ...(keyof T['selectable'])[]];
807
807
  type WhereInValues<T extends QueryBase, Column extends WhereInColumn<T>> = Column extends keyof T['selectable'] ? T['selectable'][Column]['column']['type'][] | Query | RawExpression : ({
808
808
  [I in keyof Column]: Column[I] extends keyof T['selectable'] ? T['selectable'][Column[I]]['column']['type'] : never;
@@ -1873,7 +1873,7 @@ type UpdateHasAndBelongsToManyData<Rel extends HasAndBelongsToManyRelation> = {
1873
1873
  create?: CreateData<Rel['nestedCreateQuery']>[];
1874
1874
  };
1875
1875
  type UpdateArg<T extends Query> = T['meta']['hasWhere'] extends true ? UpdateData<T> : never;
1876
- type UpdateRawArgs<T extends Query> = T['meta']['hasWhere'] extends true ? [sql: RawExpression] | [TemplateStringsArray, ...unknown[]] : never;
1876
+ type UpdateRawArgs<T extends Query> = T['meta']['hasWhere'] extends true ? [sql: RawExpression] | TemplateLiteralArgs : never;
1877
1877
  type UpdateResult<T extends Query> = T['meta']['hasSelect'] extends true ? T : SetQueryReturnsRowCount<T>;
1878
1878
  type ChangeCountArg<T extends Query> = keyof T['shape'] | Partial<Record<keyof T['shape'], number>>;
1879
1879
  type UpdateCtx = {
@@ -2192,7 +2192,7 @@ type HavingArg<T extends Query = Query> = ({
2192
2192
  } & {
2193
2193
  count?: number | HavingArgObject<T, 'count'>;
2194
2194
  }) | Query | RawExpression;
2195
- type HavingArgs<T extends Query> = [...args: HavingArg<T>[]] | [TemplateStringsArray, ...unknown[]];
2195
+ type HavingArgs<T extends Query> = [...args: HavingArg<T>[]] | TemplateLiteralArgs;
2196
2196
  declare class Having {
2197
2197
  having<T extends Query>(this: T, ...args: HavingArgs<T>): T;
2198
2198
  _having<T extends Query>(this: T, ...args: HavingArgs<T>): T;
@@ -2503,10 +2503,6 @@ type SqlNoColumnArgs = [params: {
2503
2503
  }] | TemplateLiteralArgs;
2504
2504
  type Values = Record<string, unknown>;
2505
2505
  type ColumnFn<T extends Query> = (types: T['columnTypes']) => ColumnType;
2506
- type TemplateLiteralArgs = [
2507
- strings: TemplateStringsArray,
2508
- ...values: unknown[]
2509
- ];
2510
2506
  type SqlFn<C extends ColumnType> = (...args: TemplateLiteralArgs) => RawExpression<C>;
2511
2507
  type SqlResult<T extends Query, Args extends SqlArgs<T>> = Args extends SqlColumnArgs<T> ? Args extends SqlColumnArgsWithSQL<T> ? RawExpression<ReturnType<Args[0]>> : SqlFn<ReturnType<Args[0]>> : Args extends [{
2512
2508
  raw: string;
@@ -2766,8 +2762,8 @@ type OrderArg<T extends Query, Key extends PropertyKey = keyof T['selectable'] |
2766
2762
  }[keyof T['result']]> = Key | {
2767
2763
  [K in Key]?: SortDir;
2768
2764
  } | RawExpression;
2769
- type OrderArgs<T extends Query> = OrderArg<T>[] | [TemplateStringsArray, ...unknown[]];
2770
- type FindArgs<T extends Query> = [T['shape'][T['singlePrimaryKey']]['type'] | RawExpression] | [TemplateStringsArray, ...unknown[]];
2765
+ type OrderArgs<T extends Query> = OrderArg<T>[] | TemplateLiteralArgs;
2766
+ type FindArgs<T extends Query> = [T['shape'][T['singlePrimaryKey']]['type'] | RawExpression] | TemplateLiteralArgs;
2771
2767
  type QueryHelper<T extends Query, Args extends unknown[], Result> = <Q extends {
2772
2768
  [K in keyof T]: K extends 'then' ? QueryThen<unknown> : K extends 'result' ? ColumnsShapeBase : T[K];
2773
2769
  }>(q: Q, ...args: Args) => Result extends Query ? MergeQuery<Q, Result> : Result;
@@ -5054,7 +5050,7 @@ declare function text(min: number, max: number): TextColumn;
5054
5050
  declare function sql(sql: TemplateStringsArray, ...values: unknown[]): RawExpression;
5055
5051
  declare function sql(sql: string): RawExpression;
5056
5052
  declare function sql(values: Record<string, unknown>, sql: string): RawExpression;
5057
- declare function sql(values: Record<string, unknown>): (...sql: [TemplateStringsArray, ...unknown[]]) => RawExpression;
5053
+ declare function sql(values: Record<string, unknown>): (...sql: TemplateLiteralArgs) => RawExpression;
5058
5054
  type DefaultColumnTypes = typeof columnTypes;
5059
5055
  declare const columnTypes: {
5060
5056
  timestamps<T extends orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>(this: {
package/dist/index.js CHANGED
@@ -4408,7 +4408,7 @@ const then = async (q, adapter, resolve, reject) => {
4408
4408
  }
4409
4409
  const queryResult = await adapter[queryMethodByReturnType[query.returnType || "all"]](sql);
4410
4410
  if (query.patchResult) {
4411
- await query.patchResult(queryResult);
4411
+ await query.patchResult(q, queryResult);
4412
4412
  }
4413
4413
  if (query.log) {
4414
4414
  query.log.afterQuery(sql, logData);
@@ -5741,9 +5741,7 @@ class From {
5741
5741
  _from(...args) {
5742
5742
  var _a, _b, _c;
5743
5743
  if (Array.isArray(args[0])) {
5744
- return this._from(
5745
- orchidCore.raw(args)
5746
- );
5744
+ return this._from(orchidCore.raw(args));
5747
5745
  }
5748
5746
  if (typeof args[0] === "string") {
5749
5747
  (_a = this.query).as || (_a.as = args[0]);
@@ -7030,7 +7028,7 @@ class Update {
7030
7028
  }
7031
7029
  });
7032
7030
  }
7033
- query.patchResult = async (queryResult) => {
7031
+ query.patchResult = async (_, queryResult) => {
7034
7032
  await Promise.all(queries.map((fn) => fn(queryResult)));
7035
7033
  if (ctx.updateData) {
7036
7034
  const t = this.baseQuery.clone();
@@ -7489,16 +7487,16 @@ class QueryUpsertOrCreate {
7489
7487
  this.query.handleResult = (q, r, s) => {
7490
7488
  return created ? result : handleResult(q, r, s);
7491
7489
  };
7492
- this.query.patchResult = async (queryResult) => {
7490
+ this.query.patchResult = async (q, queryResult) => {
7493
7491
  if (queryResult.rowCount === 0) {
7494
7492
  if (typeof data === "function") {
7495
7493
  data = data();
7496
7494
  }
7497
- const inner = this.create(data);
7495
+ const inner = q.create(data);
7498
7496
  const { handleResult: handleResult2 } = inner.query;
7499
- inner.query.handleResult = (q, r, s) => {
7497
+ inner.query.handleResult = (q2, r, s) => {
7500
7498
  queryResult = r;
7501
- const res = handleResult2(q, r, s);
7499
+ const res = handleResult2(q2, r, s);
7502
7500
  result = res;
7503
7501
  return res;
7504
7502
  };
@@ -7620,39 +7618,23 @@ class RawSqlMethods {
7620
7618
  const arg = args[0];
7621
7619
  if (typeof arg === "object") {
7622
7620
  if (Array.isArray(arg)) {
7623
- return {
7624
- __raw: args
7625
- };
7621
+ return orchidCore.raw(args);
7626
7622
  }
7627
7623
  const obj = arg;
7628
7624
  if (obj.raw) {
7629
- return {
7630
- __raw: obj.raw,
7631
- __values: obj.values
7632
- };
7625
+ return orchidCore.raw(obj.raw, obj.values);
7633
7626
  }
7634
7627
  return (...args2) => {
7635
- return {
7636
- __raw: args2,
7637
- __values: obj.values
7638
- };
7628
+ return orchidCore.raw(args2, obj.values);
7639
7629
  };
7640
7630
  }
7641
7631
  const column = arg(this.columnTypes);
7642
7632
  const second = args[1];
7643
7633
  if (second == null ? void 0 : second.raw) {
7644
- return {
7645
- __column: column,
7646
- __raw: second.raw,
7647
- __values: second.values
7648
- };
7634
+ return orchidCore.raw(second.raw, second.values, column);
7649
7635
  }
7650
7636
  return (...args2) => {
7651
- return {
7652
- __column: column,
7653
- __raw: args2,
7654
- __values: second == null ? void 0 : second.values
7655
- };
7637
+ return orchidCore.raw(args2, second == null ? void 0 : second.values, column);
7656
7638
  };
7657
7639
  }
7658
7640
  /**
@@ -7660,16 +7642,9 @@ class RawSqlMethods {
7660
7642
  */
7661
7643
  raw(...args) {
7662
7644
  if (typeof args[0] === "string") {
7663
- return {
7664
- __raw: args[0],
7665
- __values: args[1]
7666
- };
7645
+ return orchidCore.raw(args[0], args[1]);
7667
7646
  } else {
7668
- return {
7669
- __column: args[0](this.columnTypes),
7670
- __raw: args[1],
7671
- __values: args[2]
7672
- };
7647
+ return orchidCore.raw(args[1], args[2], args[0](this.columnTypes));
7673
7648
  }
7674
7649
  }
7675
7650
  }