pqb 0.17.3 → 0.17.4

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 CHANGED
@@ -1826,13 +1826,9 @@ type ForQueryBuilder<Q extends Query> = Q & {
1826
1826
  };
1827
1827
  declare class For {
1828
1828
  forUpdate<T extends Query>(this: T, tableNames?: string[] | Expression): ForQueryBuilder<T>;
1829
- _forUpdate<T extends Query>(this: T, tableNames?: string[] | Expression): ForQueryBuilder<T>;
1830
1829
  forNoKeyUpdate<T extends Query>(this: T, tableNames?: string[] | Expression): ForQueryBuilder<T>;
1831
- _forNoKeyUpdate<T extends Query>(this: T, tableNames?: string[] | Expression): ForQueryBuilder<T>;
1832
1830
  forShare<T extends Query>(this: T, tableNames?: string[] | Expression): ForQueryBuilder<T>;
1833
- _forShare<T extends Query>(this: T, tableNames?: string[] | Expression): ForQueryBuilder<T>;
1834
1831
  forKeyShare<T extends Query>(this: T, tableNames?: string[] | Expression): ForQueryBuilder<T>;
1835
- _forKeyShare<T extends Query>(this: T, tableNames?: string[] | Expression): ForQueryBuilder<T>;
1836
1832
  }
1837
1833
 
1838
1834
  type FromArgs<T extends Query> = [
@@ -3591,10 +3587,46 @@ declare class OnQueryBuilder<S extends QueryBase = QueryBase, J extends QueryBas
3591
3587
  withData: {};
3592
3588
  internal: QueryInternal;
3593
3589
  constructor(q: QueryBase, { shape, joinedShapes }: Pick<QueryData, 'shape' | 'joinedShapes'>, joinTo: QueryBase);
3590
+ /**
3591
+ * Use `on` to specify columns to join records.
3592
+ *
3593
+ * ```ts
3594
+ * q
3595
+ * // left column is the db.message column, right column is the db.user column
3596
+ * .on('userId', 'id')
3597
+ * // table names can be provided:
3598
+ * .on('message.userId', 'user.id')
3599
+ * // operator can be specified:
3600
+ * .on('userId', '!=', 'id')
3601
+ * // operator can be specified with table names as well:
3602
+ * .on('message.userId', '!=', 'user.id')
3603
+ * // `.orOn` takes the same arguments as `.on` and acts like `.or`:
3604
+ * .on('userId', 'id') // where message.userId = user.id
3605
+ * ```
3606
+ *
3607
+ * @param args - columns to join with
3608
+ */
3594
3609
  on<T extends OnQueryBuilder>(this: T, ...args: OnArgs<T>): T;
3595
3610
  _on<T extends OnQueryBuilder>(this: T, ...args: OnArgs<T>): T;
3611
+ /**
3612
+ * Works as {@link on}, but the added conditions will be separated from previous with `OR`.
3613
+ *
3614
+ * @param args - columns to join with
3615
+ */
3596
3616
  orOn<T extends OnQueryBuilder>(this: T, ...args: OnArgs<T>): T;
3597
3617
  _orOn<T extends OnQueryBuilder>(this: T, ...args: OnArgs<T>): T;
3618
+ /**
3619
+ * Use `onJsonPathEquals` to join record based on a field of their JSON column:
3620
+ *
3621
+ * ```ts
3622
+ * db.table.join(db.otherTable, (q) =>
3623
+ * // '$.key' is a JSON path
3624
+ * q.onJsonPathEquals('otherTable.data', '$.key', 'table.data', '$.key'),
3625
+ * );
3626
+ * ```
3627
+ *
3628
+ * @param args - columns and JSON paths to join with.
3629
+ */
3598
3630
  onJsonPathEquals<T extends OnQueryBuilder>(this: T, ...args: OnJsonPathEqualsArgs<T>): T;
3599
3631
  _onJsonPathEquals<T extends OnQueryBuilder>(this: T, ...args: OnJsonPathEqualsArgs<T>): T;
3600
3632
  }
@@ -3821,6 +3853,7 @@ type Resolve = (result: any) => any;
3821
3853
  type Reject = (error: any) => any;
3822
3854
  declare class Then {
3823
3855
  get then(): typeof maybeWrappedThen;
3856
+ set then(value: typeof maybeWrappedThen);
3824
3857
  catch(this: Query, fn: (reason: any) => unknown): Promise<unknown>;
3825
3858
  }
3826
3859
  declare const handleResult: CommonQueryData['handleResult'];
@@ -5501,6 +5534,26 @@ declare class QueryMethods<CT extends ColumnTypesBase> {
5501
5534
  restartIdentity?: boolean;
5502
5535
  cascade?: boolean;
5503
5536
  }): TruncateResult<T>;
5537
+ /**
5538
+ * `none` will resolve the query into an empty result, without executing a database query.
5539
+ *
5540
+ * ```ts
5541
+ * await db.table.none(); // -> empty array
5542
+ * await db.table.findOptional(123).none(); // -> undefined
5543
+ * await db.table.find(123).none(); // throws NotFoundError
5544
+ * ```
5545
+ *
5546
+ * [create](/guide/create-update-delete.html#create) chained with `count`, [update](/guide/create-update-delete.html#update), and [delete](/guide/create-update-delete.html#del-delete) are returning a count of affected records.
5547
+ *
5548
+ * When they are called with `none`, query does not execute and 0 is returned.
5549
+ *
5550
+ * ```ts
5551
+ * await db.table.count().create(data); // -> 0
5552
+ * await db.table.all().update(data); // -> 0
5553
+ * await db.table.all().delete(); // -> 0
5554
+ * ```
5555
+ */
5556
+ none<T extends Query>(this: T): T;
5504
5557
  /**
5505
5558
  * `modify` allows modifying the query with your function:
5506
5559
  *
@@ -7069,6 +7122,14 @@ declare const setQueryObjectValue: <T extends {
7069
7122
  */
7070
7123
  declare const throwIfNoWhere: (q: Query, method: string) => void;
7071
7124
  declare const saveSearchAlias: (q: QueryBase, as: string, key: 'joinedShapes' | 'withShapes') => string;
7125
+ /**
7126
+ * Extend query prototype with new methods.
7127
+ * The query and its data are cloned (with Object.create).
7128
+ *
7129
+ * @param q - query object to extend from
7130
+ * @param methods - methods to add
7131
+ */
7132
+ declare const extendQuery: <T extends Query, Methods extends Record<string, unknown>>(q: T, methods: Methods) => T & Methods;
7072
7133
 
7073
7134
  type Arg = {
7074
7135
  $queryBuilder: Query;
@@ -7079,4 +7140,4 @@ declare const testTransaction: {
7079
7140
  close(arg: Arg): Promise<void>;
7080
7141
  };
7081
7142
 
7082
- export { Adapter, AdapterConfig, AdapterOptions, AddQuerySelect, AddQueryWith, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AsMethods, BaseOperators, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanNullable, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, ColumnData, ColumnExpression, ColumnFromDbParams, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnOperators, ColumnType, ColumnTypes, ColumnsObject, ColumnsShape, CommonQueryData, CopyMethods, CopyOptions, CopyQueryData, Create, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DbOptions, DbResult, DbTableOptions, DecimalBaseColumn, DecimalColumn, DefaultColumnTypes, Delete, DeleteMethodsNames, DeleteQueryData, DomainColumn, DoublePrecisionColumn, DropMode, EnumColumn, ExpressionOutput, FnExpression, FnExpressionArg, For, ForeignKey, ForeignKeyAction, ForeignKeyMatch, ForeignKeyOptions, From, FromArgs, FromResult, GetArg, GetQueryResult, GetStringArg, Having, HavingItem, HookAction, HookSelect, IdentityColumn, IndexColumnOptions, IndexOptions, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinLateralCallback, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinResult, JoinedParsers, JoinedShapes, JsonItem, JsonMethods, JsonModifiers, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgs, OrderItem, OrderTsQueryConfig, Over, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBeforeHook, QueryData, QueryError, QueryErrorName, QueryGet, QueryHookSelect, QueryHooks, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryReturnType, QueryReturnsAll, QuerySourceItem, QueryTransform, QueryTransformFn, QueryUpsertOrCreate, QueryWithTable, RawSQL, RawSqlMethods, RealColumn, RelationConfigBase, RelationQuery, RelationQueryBase, RelationSubQueries, RelationsBase, SearchArg, SearchMethods, SearchWeight, Select, SelectAggMethods, SelectArg, SelectItem, SelectQueryBuilder, SelectQueryData, Selectable, SelectableBase, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, SerialColumn, SerialColumnData, SetQueryKind, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumn, SetQueryReturnsColumnInfo, SetQueryReturnsColumnOptional, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWith, SimpleJoinItem, SingleColumnIndexOptions, SmallIntColumn, SmallSerialColumn, SortDir, StringColumn, SubQueryBuilder, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, TimeColumn, TimeInterval, TimestampColumn, TimestampTZColumn, ToSQLCtx, ToSQLOptions, Transaction, TransactionAdapter, TransactionOptions, TransformMethods, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnionKind, UnknownColumn, Update, UpdateCtx, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, UpsertCreateArg, UpsertData, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereOnItem, WhereOnJoinItem, WhereQueryBase, WhereQueryBuilder, WhereResult, WhereSearchItem, WhereSearchResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowItem, With, WithDataBase, WithDataItem, WithItem, WithOptions, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addQueryOn, addWhere, addWhereIn, addWhereNot, anyShape, checkIfASimpleQuery, cloneQueryArrays, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnTypes, columnsByType, columnsShapeToCode, constraintPropsToCode, constraintToCode, createDb, createOperator, foreignKeyArgumentToCode, getClonedQueryData, getColumnTypes, getConstraintKind, getQueryAs, getShapeFromSelect, getSubQueryBuilder, getTableData, handleResult, identityToCode, indexToCode, instantiateColumn, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnFn, makeColumnFnClass, makeRegexToFindInSql, makeSQL, newTableData, parseRecord, parseResult, primaryKeyToCode, processSelectArg, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, quoteString, raw, referencesArgsToCode, resetTableData, resolveSubQueryCallback, saveSearchAlias, setQueryObjectValue, simplifyColumnDefault, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
7143
+ export { Adapter, AdapterConfig, AdapterOptions, AddQuerySelect, AddQueryWith, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AsMethods, BaseOperators, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanNullable, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, ColumnData, ColumnExpression, ColumnFromDbParams, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnOperators, ColumnType, ColumnTypes, ColumnsObject, ColumnsShape, CommonQueryData, CopyMethods, CopyOptions, CopyQueryData, Create, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DbOptions, DbResult, DbTableOptions, DecimalBaseColumn, DecimalColumn, DefaultColumnTypes, Delete, DeleteMethodsNames, DeleteQueryData, DomainColumn, DoublePrecisionColumn, DropMode, EnumColumn, ExpressionOutput, FnExpression, FnExpressionArg, For, ForeignKey, ForeignKeyAction, ForeignKeyMatch, ForeignKeyOptions, From, FromArgs, FromResult, GetArg, GetQueryResult, GetStringArg, Having, HavingItem, HookAction, HookSelect, IdentityColumn, IndexColumnOptions, IndexOptions, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinLateralCallback, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinResult, JoinedParsers, JoinedShapes, JsonItem, JsonMethods, JsonModifiers, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgs, OrderItem, OrderTsQueryConfig, Over, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBeforeHook, QueryData, QueryError, QueryErrorName, QueryGet, QueryHookSelect, QueryHooks, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryReturnType, QueryReturnsAll, QuerySourceItem, QueryTransform, QueryTransformFn, QueryUpsertOrCreate, QueryWithTable, RawSQL, RawSqlMethods, RealColumn, RelationConfigBase, RelationQuery, RelationQueryBase, RelationSubQueries, RelationsBase, SearchArg, SearchMethods, SearchWeight, Select, SelectAggMethods, SelectArg, SelectItem, SelectQueryBuilder, SelectQueryData, Selectable, SelectableBase, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, SerialColumn, SerialColumnData, SetQueryKind, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumn, SetQueryReturnsColumnInfo, SetQueryReturnsColumnOptional, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWith, SimpleJoinItem, SingleColumnIndexOptions, SmallIntColumn, SmallSerialColumn, SortDir, StringColumn, SubQueryBuilder, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, TimeColumn, TimeInterval, TimestampColumn, TimestampTZColumn, ToSQLCtx, ToSQLOptions, Transaction, TransactionAdapter, TransactionOptions, TransformMethods, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnionKind, UnknownColumn, Update, UpdateCtx, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, UpsertCreateArg, UpsertData, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereOnItem, WhereOnJoinItem, WhereQueryBase, WhereQueryBuilder, WhereResult, WhereSearchItem, WhereSearchResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowItem, With, WithDataBase, WithDataItem, WithItem, WithOptions, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addQueryOn, addWhere, addWhereIn, addWhereNot, anyShape, checkIfASimpleQuery, cloneQueryArrays, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnTypes, columnsByType, columnsShapeToCode, constraintPropsToCode, constraintToCode, createDb, createOperator, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnTypes, getConstraintKind, getQueryAs, getShapeFromSelect, getSubQueryBuilder, getTableData, handleResult, identityToCode, indexToCode, instantiateColumn, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnFn, makeColumnFnClass, makeRegexToFindInSql, makeSQL, newTableData, parseRecord, parseResult, primaryKeyToCode, processSelectArg, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, quoteString, raw, referencesArgsToCode, resetTableData, resolveSubQueryCallback, saveSearchAlias, setQueryObjectValue, simplifyColumnDefault, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
package/dist/index.js CHANGED
@@ -2204,6 +2204,14 @@ const saveSearchAlias = (q, as, key) => {
2204
2204
  setQueryObjectValue(q, key, as, orchidCore.emptyObject);
2205
2205
  return as;
2206
2206
  };
2207
+ const extendQuery = (q, methods) => {
2208
+ const base = Object.create(q.baseQuery);
2209
+ base.baseQuery = base;
2210
+ Object.assign(base, methods);
2211
+ const cloned = Object.create(base);
2212
+ cloned.q = getClonedQueryData(q.q);
2213
+ return cloned;
2214
+ };
2207
2215
 
2208
2216
  var __defProp$b = Object.defineProperty;
2209
2217
  var __defProps$6 = Object.defineProperties;
@@ -5531,55 +5539,45 @@ class Delete {
5531
5539
  }
5532
5540
  }
5533
5541
 
5542
+ const forMethods = {
5543
+ noWait() {
5544
+ return this.clone()._noWait();
5545
+ },
5546
+ _noWait() {
5547
+ const q = this.q;
5548
+ if (q == null ? void 0 : q.for)
5549
+ q.for.mode = "NO WAIT";
5550
+ return this;
5551
+ },
5552
+ skipLocked() {
5553
+ return this.clone()._skipLocked();
5554
+ },
5555
+ _skipLocked() {
5556
+ const q = this.q;
5557
+ if (q == null ? void 0 : q.for)
5558
+ q.for.mode = "SKIP LOCKED";
5559
+ return this;
5560
+ }
5561
+ };
5534
5562
  const forQueryBuilder = (q, type, tableNames) => {
5535
- q.q.for = { type, tableNames };
5536
- q.baseQuery = Object.create(q.baseQuery);
5537
- q.baseQuery.baseQuery = q.baseQuery;
5538
- Object.assign(q.baseQuery, {
5539
- noWait() {
5540
- return this.clone()._noWait();
5541
- },
5542
- _noWait() {
5543
- const q2 = this.q;
5544
- if (q2 == null ? void 0 : q2.for)
5545
- q2.for.mode = "NO WAIT";
5546
- return this;
5547
- },
5548
- skipLocked() {
5549
- return this.clone()._skipLocked();
5550
- },
5551
- _skipLocked() {
5552
- const q2 = this.q;
5553
- if (q2 == null ? void 0 : q2.for)
5554
- q2.for.mode = "SKIP LOCKED";
5555
- return this;
5556
- }
5557
- });
5558
- return q.clone();
5563
+ q = extendQuery(q, forMethods);
5564
+ q.q.for = {
5565
+ type,
5566
+ tableNames
5567
+ };
5568
+ return q;
5559
5569
  };
5560
5570
  class For {
5561
5571
  forUpdate(tableNames) {
5562
- return this.clone()._forUpdate(tableNames);
5563
- }
5564
- _forUpdate(tableNames) {
5565
5572
  return forQueryBuilder(this, "UPDATE", tableNames);
5566
5573
  }
5567
5574
  forNoKeyUpdate(tableNames) {
5568
- return this.clone()._forNoKeyUpdate(tableNames);
5569
- }
5570
- _forNoKeyUpdate(tableNames) {
5571
5575
  return forQueryBuilder(this, "NO KEY UPDATE", tableNames);
5572
5576
  }
5573
5577
  forShare(tableNames) {
5574
- return this.clone()._forShare(tableNames);
5575
- }
5576
- _forShare(tableNames) {
5577
5578
  return forQueryBuilder(this, "SHARE", tableNames);
5578
5579
  }
5579
5580
  forKeyShare(tableNames) {
5580
- return this.clone()._forKeyShare(tableNames);
5581
- }
5582
- _forKeyShare(tableNames) {
5583
5581
  return forQueryBuilder(this, "KEY SHARE", tableNames);
5584
5582
  }
5585
5583
  }
@@ -7211,18 +7209,54 @@ class OnQueryBuilder extends WhereQueryBase {
7211
7209
  }
7212
7210
  this.q.joinTo = joinTo;
7213
7211
  }
7212
+ /**
7213
+ * Use `on` to specify columns to join records.
7214
+ *
7215
+ * ```ts
7216
+ * q
7217
+ * // left column is the db.message column, right column is the db.user column
7218
+ * .on('userId', 'id')
7219
+ * // table names can be provided:
7220
+ * .on('message.userId', 'user.id')
7221
+ * // operator can be specified:
7222
+ * .on('userId', '!=', 'id')
7223
+ * // operator can be specified with table names as well:
7224
+ * .on('message.userId', '!=', 'user.id')
7225
+ * // `.orOn` takes the same arguments as `.on` and acts like `.or`:
7226
+ * .on('userId', 'id') // where message.userId = user.id
7227
+ * ```
7228
+ *
7229
+ * @param args - columns to join with
7230
+ */
7214
7231
  on(...args) {
7215
7232
  return this.clone()._on(...args);
7216
7233
  }
7217
7234
  _on(...args) {
7218
7235
  return pushQueryOn(this, this.q.joinTo, this, ...args);
7219
7236
  }
7237
+ /**
7238
+ * Works as {@link on}, but the added conditions will be separated from previous with `OR`.
7239
+ *
7240
+ * @param args - columns to join with
7241
+ */
7220
7242
  orOn(...args) {
7221
7243
  return this.clone()._orOn(...args);
7222
7244
  }
7223
7245
  _orOn(...args) {
7224
7246
  return pushQueryOrOn(this, this.q.joinTo, this, ...args);
7225
7247
  }
7248
+ /**
7249
+ * Use `onJsonPathEquals` to join record based on a field of their JSON column:
7250
+ *
7251
+ * ```ts
7252
+ * db.table.join(db.otherTable, (q) =>
7253
+ * // '$.key' is a JSON path
7254
+ * q.onJsonPathEquals('otherTable.data', '$.key', 'table.data', '$.key'),
7255
+ * );
7256
+ * ```
7257
+ *
7258
+ * @param args - columns and JSON paths to join with.
7259
+ */
7226
7260
  onJsonPathEquals(...args) {
7227
7261
  return this.clone()._onJsonPathEquals(...args);
7228
7262
  }
@@ -7603,6 +7637,11 @@ class Then {
7603
7637
  queryError = new Error();
7604
7638
  return maybeWrappedThen;
7605
7639
  }
7640
+ set then(value) {
7641
+ Object.defineProperty(this, "then", {
7642
+ value
7643
+ });
7644
+ }
7606
7645
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
7607
7646
  catch(fn) {
7608
7647
  return this.then(void 0, fn);
@@ -9211,6 +9250,24 @@ class TransformMethods {
9211
9250
  }
9212
9251
  }
9213
9252
 
9253
+ const noneMethods = {
9254
+ // `then` resolves or rejects based on return type of the query.
9255
+ // It is `async` so it returns a chainable Promise.
9256
+ async then(resolve, reject) {
9257
+ const type = this.q.returnType;
9258
+ if (!type || type === "all" || type === "rows" || type === "pluck")
9259
+ resolve == null ? void 0 : resolve([]);
9260
+ else if (type === "one" || type === "value" || type === "void")
9261
+ resolve == null ? void 0 : resolve();
9262
+ else if (type === "rowCount")
9263
+ resolve == null ? void 0 : resolve(0);
9264
+ else
9265
+ reject == null ? void 0 : reject(new NotFoundError(this));
9266
+ },
9267
+ // `catch` returns a Promise, so it is chainable with then/catch.
9268
+ catch: () => new Promise(orchidCore.noop)
9269
+ };
9270
+
9214
9271
  class QueryMethods {
9215
9272
  /**
9216
9273
  * `.all` is a default behavior, that returns an array of objects:
@@ -9672,6 +9729,28 @@ class QueryMethods {
9672
9729
  }
9673
9730
  return this._exec();
9674
9731
  }
9732
+ /**
9733
+ * `none` will resolve the query into an empty result, without executing a database query.
9734
+ *
9735
+ * ```ts
9736
+ * await db.table.none(); // -> empty array
9737
+ * await db.table.findOptional(123).none(); // -> undefined
9738
+ * await db.table.find(123).none(); // throws NotFoundError
9739
+ * ```
9740
+ *
9741
+ * [create](/guide/create-update-delete.html#create) chained with `count`, [update](/guide/create-update-delete.html#update), and [delete](/guide/create-update-delete.html#del-delete) are returning a count of affected records.
9742
+ *
9743
+ * When they are called with `none`, query does not execute and 0 is returned.
9744
+ *
9745
+ * ```ts
9746
+ * await db.table.count().create(data); // -> 0
9747
+ * await db.table.all().update(data); // -> 0
9748
+ * await db.table.all().delete(); // -> 0
9749
+ * ```
9750
+ */
9751
+ none() {
9752
+ return extendQuery(this, noneMethods);
9753
+ }
9675
9754
  /**
9676
9755
  * `modify` allows modifying the query with your function:
9677
9756
  *
@@ -10301,6 +10380,7 @@ exports.constraintPropsToCode = constraintPropsToCode;
10301
10380
  exports.constraintToCode = constraintToCode;
10302
10381
  exports.createDb = createDb;
10303
10382
  exports.createOperator = createOperator;
10383
+ exports.extendQuery = extendQuery;
10304
10384
  exports.foreignKeyArgumentToCode = foreignKeyArgumentToCode;
10305
10385
  exports.getClonedQueryData = getClonedQueryData;
10306
10386
  exports.getColumnTypes = getColumnTypes;