pqb 0.36.15 → 0.37.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 CHANGED
@@ -220,6 +220,7 @@ type WhereJsonPathEqualsItem = [
220
220
  interface WhereOnItem {
221
221
  joinFrom: WhereOnJoinItem;
222
222
  joinTo: WhereOnJoinItem;
223
+ useOuterJoinOverrides?: true;
223
224
  on: [leftFullColumn: string, rightFullColumn: string] | [leftFullColumn: string, op: string, rightFullColumn: string];
224
225
  }
225
226
  type WhereOnJoinItem = {
@@ -380,6 +381,7 @@ interface CommonQueryData {
380
381
  joinedForSelect?: string;
381
382
  innerJoinLateral?: true;
382
383
  joinOverrides?: JoinOverrides;
384
+ outerJoinOverrides?: JoinOverrides;
383
385
  schema?: string;
384
386
  select?: SelectItem[];
385
387
  expr?: Expression;
@@ -817,7 +819,7 @@ declare class Join {
817
819
  *
818
820
  * All the `join` methods accept the same arguments, but returning type is different because with `join` it's guaranteed to load joined table, and with `leftJoin` the joined table columns may be `NULL` when no matching record was found.
819
821
  *
820
- * For the following examples, imagine we have a `User` table with `id` and `name`, and `Message` table with `id`, `text`, messages belongs to user via `userId` column:
822
+ * For the following examples, imagine you have a `User` table with `id` and `name`, and `Message` table with `id`, `text`, messages belongs to user via `userId` column:
821
823
  *
822
824
  * ```ts
823
825
  * export class UserTable extends BaseTable {
@@ -895,7 +897,7 @@ declare class Join {
895
897
  * ```ts
896
898
  * const result = await db.user
897
899
  * .join('messages')
898
- * // after joining a table, we can use it in `where` conditions:
900
+ * // after joining a table, you can use it in `where` conditions:
899
901
  * .where({ 'messages.text': { startsWith: 'Hi' } })
900
902
  * .select(
901
903
  * 'name', // name is User column, table name may be omitted
@@ -906,8 +908,8 @@ declare class Join {
906
908
  * const ok: { name: string; text: string }[] = result;
907
909
  * ```
908
910
  *
909
- * The first argument can also be a callback, where instead of relation name as a string we're picking it as a property of `q`.
910
- * In such a way, we can alias the relation with `as`, add `where` conditions, use other query methods.
911
+ * The first argument can also be a callback, where instead of relation name as a string you're picking it as a property of `q`.
912
+ * In such a way, you can alias the relation with `as`, add `where` conditions, use other query methods.
911
913
  *
912
914
  * ```ts
913
915
  * const result = await db.user.join((q) =>
@@ -924,7 +926,7 @@ declare class Join {
924
926
  * (q) => q.messages.as('m'),
925
927
  * (q) =>
926
928
  * q
927
- * .on('text', 'name') // additionally, match message with user name
929
+ * .on('messages.text', 'user.name') // additionally, match message with user name
928
930
  * .where({ text: 'some text' }), // you can add `where` in a second callback as well.
929
931
  * );
930
932
  * ```
@@ -978,17 +980,16 @@ declare class Join {
978
980
  * Joined table can be references from `where` and `select` by a table name.
979
981
  *
980
982
  * ```ts
981
- * // Join message where userId = id:
982
983
  * db.user
983
- * .join(db.message, 'userId', 'id')
984
+ * .join(db.message, 'userId', 'user.id')
984
985
  * .where({ 'message.text': { startsWith: 'Hi' } })
985
986
  * .select('name', 'message.text');
986
987
  * ```
987
988
  *
988
- * Columns in the join list may be prefixed with table names for clarity:
989
+ * The name of the joining table can be omitted, but not the name of the main table:
989
990
  *
990
991
  * ```ts
991
- * db.user.join(db.message, 'message.userId', 'user.id');
992
+ * db.user.join(db.message, 'userId', 'user.id');
992
993
  * ```
993
994
  *
994
995
  * Joined table can have an alias for referencing it further:
@@ -1019,7 +1020,7 @@ declare class Join {
1019
1020
  * You can provide a custom comparison operator
1020
1021
  *
1021
1022
  * ```ts
1022
- * db.user.join(db.message, 'userId', '!=', 'id');
1023
+ * db.user.join(db.message, 'userId', '!=', 'user.id');
1023
1024
  * ```
1024
1025
  *
1025
1026
  * Join can accept raw SQL for the `ON` part of join:
@@ -1054,11 +1055,11 @@ declare class Join {
1054
1055
  *
1055
1056
  * ```ts
1056
1057
  * db.user.join(db.message, {
1057
- * userId: 'id',
1058
- *
1059
- * // with table names:
1060
1058
  * 'message.userId': 'user.id',
1061
1059
  *
1060
+ * // joined table name may be omitted
1061
+ * userId: 'user.id',
1062
+ *
1062
1063
  * // value can be a raw SQL expression:
1063
1064
  * text: sql`lower("user"."name")`,
1064
1065
  * });
@@ -1077,17 +1078,16 @@ declare class Join {
1077
1078
  * db.message,
1078
1079
  * (q) =>
1079
1080
  * q
1080
- * // left column is the db.message column, right column is the db.user column
1081
- * .on('userId', 'id')
1082
- * // table names can be provided:
1083
1081
  * .on('message.userId', 'user.id')
1082
+ * // joined table name may be omitted
1083
+ * .on('userId', 'user.id')
1084
1084
  * // operator can be specified:
1085
- * .on('userId', '!=', 'id')
1085
+ * .on('userId', '!=', 'user.id')
1086
1086
  * // operator can be specified with table names as well:
1087
1087
  * .on('message.userId', '!=', 'user.id')
1088
1088
  * // `.orOn` takes the same arguments as `.on` and acts like `.or`:
1089
- * .on('userId', 'id') // where message.userId = user.id
1090
- * .orOn('text', 'name'), // or message.text = user.name
1089
+ * .on('userId', 'user.id') // where message.userId = user.id
1090
+ * .orOn('text', 'user.name'), // or message.text = user.name
1091
1091
  * );
1092
1092
  * ```
1093
1093
  *
@@ -1096,7 +1096,7 @@ declare class Join {
1096
1096
  * ```ts
1097
1097
  * db.user.join(db.message, (q) =>
1098
1098
  * q
1099
- * .on('userId', 'id')
1099
+ * .on('userId', 'user.id')
1100
1100
  * .where({
1101
1101
  * // not prefixed column name is for joined table:
1102
1102
  * text: { startsWith: 'hello' },
@@ -1131,7 +1131,7 @@ declare class Join {
1131
1131
  * .where({ text: { startsWith: 'Hi' } })
1132
1132
  * .as('t'),
1133
1133
  * 'userId',
1134
- * 'id',
1134
+ * 'user.id',
1135
1135
  * );
1136
1136
  * ```
1137
1137
  *
@@ -1188,7 +1188,7 @@ declare class Join {
1188
1188
  *
1189
1189
  * // the same query, but joining table explicitly
1190
1190
  * const result2: typeof result = await db.user
1191
- * .leftJoin(db.message, 'userId', 'id')
1191
+ * .leftJoin(db.message, 'userId', 'user.id')
1192
1192
  * .select('name', 'message.text');
1193
1193
  *
1194
1194
  * // result has the following type:
@@ -1260,7 +1260,7 @@ declare class Join {
1260
1260
  * // select message columns
1261
1261
  * .select('text')
1262
1262
  * // join the message to the user, column names can be prefixed with table names
1263
- * .on('authorId', 'id')
1263
+ * .on('authorId', 'user.id')
1264
1264
  * // message columns are available without prefixing,
1265
1265
  * // outer table columns are available with a table name
1266
1266
  * .where({ text: 'some text', 'user.name': 'name' })
@@ -1335,6 +1335,7 @@ declare class Join {
1335
1335
  }): JoinLateralResult<T, Table, Meta, Result, false>;
1336
1336
  }
1337
1337
  type OnArgs<S extends SelectableBase> = [leftColumn: keyof S, rightColumn: keyof S] | [leftColumn: keyof S, op: string, rightColumn: keyof S];
1338
+ declare const pushQueryOnForOuter: <T extends PickQueryMeta>(q: T, joinFrom: PickQueryMeta, joinTo: PickQueryMeta, ...on: OnArgs<SelectableBase>) => T;
1338
1339
  declare const pushQueryOn: <T extends PickQueryMeta>(q: T, joinFrom: PickQueryMeta, joinTo: PickQueryMeta, ...on: OnArgs<SelectableBase>) => T;
1339
1340
  declare const pushQueryOrOn: <T extends PickQueryMeta>(q: T, joinFrom: PickQueryMeta, joinTo: PickQueryMeta, ...on: OnArgs<SelectableBase>) => PickQueryQ;
1340
1341
  declare const addQueryOn: <T extends PickQueryMeta>(q: T, joinFrom: PickQueryMeta, joinTo: PickQueryMeta, ...args: OnArgs<SelectableBase>) => T;
@@ -1372,16 +1373,13 @@ declare class OnMethods {
1372
1373
  *
1373
1374
  * ```ts
1374
1375
  * q
1375
- * // left column is the db.message column, right column is the db.user column
1376
- * .on('userId', 'id')
1377
- * // table names can be provided:
1378
1376
  * .on('message.userId', 'user.id')
1377
+ * // joined table name may be omitted
1378
+ * .on('userId', 'user.id')
1379
1379
  * // operator can be specified:
1380
- * .on('userId', '!=', 'id')
1380
+ * .on('userId', '!=', 'user.id')
1381
1381
  * // operator can be specified with table names as well:
1382
1382
  * .on('message.userId', '!=', 'user.id')
1383
- * // `.orOn` takes the same arguments as `.on` and acts like `.or`:
1384
- * .on('userId', 'id') // where message.userId = user.id
1385
1383
  * ```
1386
1384
  *
1387
1385
  * @param args - columns to join with
@@ -2951,7 +2949,7 @@ declare abstract class LimitedTextBaseColumn<Schema extends ColumnSchemaConfig>
2951
2949
  data: TextColumnData & {
2952
2950
  maxChars?: number;
2953
2951
  };
2954
- constructor(schema: Schema, limit: number);
2952
+ constructor(schema: Schema, limit?: number);
2955
2953
  toSQL(): string;
2956
2954
  }
2957
2955
  declare class VarCharColumn<Schema extends ColumnSchemaConfig> extends LimitedTextBaseColumn<Schema> {
@@ -3181,7 +3179,7 @@ interface DefaultSchemaConfig extends ColumnSchemaConfig<ColumnType> {
3181
3179
  doublePrecision(): DoublePrecisionColumn<DefaultSchemaConfig>;
3182
3180
  bigSerial(): BigSerialColumn<DefaultSchemaConfig>;
3183
3181
  money(): MoneyColumn<DefaultSchemaConfig>;
3184
- varchar(limit: number): VarCharColumn<DefaultSchemaConfig>;
3182
+ varchar(limit?: number): VarCharColumn<DefaultSchemaConfig>;
3185
3183
  text(): TextColumn<DefaultSchemaConfig>;
3186
3184
  string(limit?: number): StringColumn$1<DefaultSchemaConfig>;
3187
3185
  citext(): CitextColumn<DefaultSchemaConfig>;
@@ -5180,7 +5178,7 @@ declare class Select {
5180
5178
  *
5181
5179
  * // table name may refer to the current table or a joined table:
5182
5180
  * db.table
5183
- * .join(Message, 'authorId', 'id')
5181
+ * .join(Message, 'authorId', 'user.id')
5184
5182
  * .select('user.name', 'message.text', { textAlias: 'message.text' });
5185
5183
  *
5186
5184
  * // select value from the sub-query,
@@ -5309,7 +5307,7 @@ declare class SqlMethod<ColumnTypes> {
5309
5307
  *
5310
5308
  * ```ts
5311
5309
  * // ids will be prefixed with proper table names, no ambiguity:
5312
- * db.table.join(db.otherTable, 'id', 'otherId').where`
5310
+ * db.table.join(db.otherTable, 'id', 'other.otherId').where`
5313
5311
  * ${db.table.column('id')} = 1 AND
5314
5312
  * ${db.otherTable.ref('id')} = 2
5315
5313
  * `;
@@ -8033,4 +8031,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
8033
8031
  */
8034
8032
  declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
8035
8033
 
8036
- export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, ColumnData, ColumnFromDbParams, ColumnInfoQueryData, ColumnRefExpression, ColumnType, ColumnsByType, ColumnsShape, ColumnsShapeToNullableObject, ColumnsShapeToObject, ColumnsShapeToObjectArray, ColumnsShapeToPluck, CommonQueryData, ComputedColumn, ComputedColumns, ComputedColumnsFromOptions, ComputedMethods, ComputedOptionsFactory, CopyOptions, CopyQueryData, Create, CreateBelongsToData, CreateColumn, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CreateRelationsData, CreateRelationsDataOmittingFKeys, CreateResult, CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, DbDomainArg, DbDomainArgRecord, DbExtension, DbOptions, DbResult, DbSharedOptions, DbTableConstructor, DbTableOptionScopes, DbTableOptions, DecimalColumn, DecimalColumnData, DefaultColumnTypes, DefaultSchemaConfig, Delete, DeleteArgs, DeleteMethodsNames, DeleteQueryData, DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, ExpressionOutput, FnExpression, FnExpressionArgs, FnExpressionArgsPairs, FnExpressionArgsValue, For, FromArg, FromMethods, FromQuerySelf, FromResult, GetArg, GetColumnInfo, GetQueryResult, GetResult, GetResultOptional, GetStringArg, GroupArgs, HandleResult, Having, HavingItem, HookAction, HookSelectArg, IdentityColumn, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgToQuery, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinItemArgs, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinQueryBuilder, JoinQueryMethod, JoinResult, JoinedParsers, JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MapTableScopesOption, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumnData, OnConflictMerge, OnConflictQueryBuilder, OnConflictSet, OnConflictTarget, OnMethods, Operator, Operators, OperatorsAny, OperatorsArray, OperatorsBoolean, OperatorsDate, OperatorsJson, OperatorsNumber, OperatorsText, OperatorsTime, OrCreateArg, OrExpression, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgSelf, OrderArgs, OrderItem, OrderTsQueryConfig, Over, PathColumn, PickColumnData, PickQueryBaseQuery, PickQueryColumnTypes, PickQueryDataShapeAndJoinedShapes, PickQueryInternal, PickQueryMetaRelations, PickQueryMetaResultRelations, PickQueryMetaResultRelationsWindows, PickQueryMetaResultRelationsWindowsColumnTypes, PickQueryMetaResultRelationsWithDataReturnType, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryMetaResultReturnTypeWithDataWindows, PickQueryMetaResultReturnTypeWithDataWindowsTable, PickQueryMetaShapeRelationsWithData, PickQueryMetaTable, PickQueryMetaTableShape, PickQueryMetaTableShapeReturnTypeWithData, PickQueryMetaWithData, PickQueryMetaWithDataColumnTypes, PickQueryQ, PickQueryQAndBaseQuery, PickQueryQAndInternal, PickQueryRelations, PickQueryRelationsWithData, PickQueryResultColumnTypes, PickQueryShapeResultSinglePrimaryKey, PickQueryShapeSinglePrimaryKey, PickQuerySinglePrimaryKey, PickQueryWindows, PickQueryWithData, PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBaseThen, QueryBatchResult, QueryBeforeHook, QueryComputedArg, QueryData, QueryDataFromItem, QueryDataJoinTo, QueryDefaultReturnData, QueryError, QueryErrorName, QueryGet, QueryGetSelf, QueryHelperResult, QueryHooks, QueryInternal, QueryLog, QueryMetaHasSelect, QueryMetaHasWhere, QueryMethods, QueryOrExpression, QueryOrExpressionBooleanOrNullResult, QueryResult, QueryScopeData, QueryScopes, QuerySourceItem, QueryUpsertOrCreate, QueryWithTable, RawSQL, RealColumn, RecordOfColumnsShapeBase, RefExpression, RelationConfigBase, RelationConfigDataForCreate, RelationJoinQuery, RelationQuery, RelationQueryBase, RelationsBase, RuntimeComputedQueryColumn, SearchArg, SearchMethods, SearchWeight, SearchWeightRecord, Select, SelectArg, SelectArgs, SelectAs, SelectAsValue, SelectItem, SelectQueryData, SelectSubQueryResult, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, SelectableOrExpressions, SerialColumn, SerialColumnData, SetQueryKind, SetQueryKindResult, SetQueryReturnsAll, SetQueryReturnsAllKind, SetQueryReturnsAllKindResult, SetQueryReturnsColumnInfo, SetQueryReturnsColumnKind, SetQueryReturnsColumnKindResult, SetQueryReturnsColumnOptional, SetQueryReturnsColumnOrThrow, SetQueryReturnsOne, SetQueryReturnsOneKind, SetQueryReturnsOneKindResult, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsPluckColumn, SetQueryReturnsPluckColumnKind, SetQueryReturnsPluckColumnKindResult, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValueOptional, SetQueryReturnsValueOrThrow, SetQueryReturnsVoid, SetQueryReturnsVoidKind, SetQueryTableAlias, ShapeColumnPrimaryKeys, ShapeUniqueColumns, SimpleJoinItem, SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, SortDir, SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, TableDataFn, TableDataInput, TableDataItem, TableDataItemsUniqueColumnTuples, TableDataItemsUniqueColumns, TableDataItemsUniqueConstraints, TableDataMethods, TextBaseColumn, TextColumn, TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, ToSQLCtx, ToSQLOptions, ToSQLQuery, Transaction, TransactionAdapter, TransactionOptions, TransformMethods, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArgs, UnionItem, UnionKind, UnionSet, UniqueConstraints, UniqueQueryTypeOrExpression, UniqueTableDataItem, UnknownColumn, Update, UpdateArg, UpdateCtx, UpdateCtxCollect, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdateSelf, UpdatedAtDataInjector, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereNotArgs, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WhereSearchItem, WhereSearchResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowItem, WithArgsOptions, WithConfigs, WithDataItem, WithDataItems, WithItem, WithMethods, WithOptions, WithQueryBuilder, WithRecursiveOptions, WithResult, WithSqlResult, WrapQueryArg, XMLColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
8034
+ export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, ColumnData, ColumnFromDbParams, ColumnInfoQueryData, ColumnRefExpression, ColumnType, ColumnsByType, ColumnsShape, ColumnsShapeToNullableObject, ColumnsShapeToObject, ColumnsShapeToObjectArray, ColumnsShapeToPluck, CommonQueryData, ComputedColumn, ComputedColumns, ComputedColumnsFromOptions, ComputedMethods, ComputedOptionsFactory, CopyOptions, CopyQueryData, Create, CreateBelongsToData, CreateColumn, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CreateRelationsData, CreateRelationsDataOmittingFKeys, CreateResult, CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, DbDomainArg, DbDomainArgRecord, DbExtension, DbOptions, DbResult, DbSharedOptions, DbTableConstructor, DbTableOptionScopes, DbTableOptions, DecimalColumn, DecimalColumnData, DefaultColumnTypes, DefaultSchemaConfig, Delete, DeleteArgs, DeleteMethodsNames, DeleteQueryData, DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, ExpressionOutput, FnExpression, FnExpressionArgs, FnExpressionArgsPairs, FnExpressionArgsValue, For, FromArg, FromMethods, FromQuerySelf, FromResult, GetArg, GetColumnInfo, GetQueryResult, GetResult, GetResultOptional, GetStringArg, GroupArgs, HandleResult, Having, HavingItem, HookAction, HookSelectArg, IdentityColumn, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgToQuery, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinItemArgs, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinQueryBuilder, JoinQueryMethod, JoinResult, JoinedParsers, JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MapTableScopesOption, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumnData, OnConflictMerge, OnConflictQueryBuilder, OnConflictSet, OnConflictTarget, OnMethods, Operator, Operators, OperatorsAny, OperatorsArray, OperatorsBoolean, OperatorsDate, OperatorsJson, OperatorsNumber, OperatorsText, OperatorsTime, OrCreateArg, OrExpression, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgSelf, OrderArgs, OrderItem, OrderTsQueryConfig, Over, PathColumn, PickColumnData, PickQueryBaseQuery, PickQueryColumnTypes, PickQueryDataShapeAndJoinedShapes, PickQueryInternal, PickQueryMetaRelations, PickQueryMetaResultRelations, PickQueryMetaResultRelationsWindows, PickQueryMetaResultRelationsWindowsColumnTypes, PickQueryMetaResultRelationsWithDataReturnType, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryMetaResultReturnTypeWithDataWindows, PickQueryMetaResultReturnTypeWithDataWindowsTable, PickQueryMetaShapeRelationsWithData, PickQueryMetaTable, PickQueryMetaTableShape, PickQueryMetaTableShapeReturnTypeWithData, PickQueryMetaWithData, PickQueryMetaWithDataColumnTypes, PickQueryQ, PickQueryQAndBaseQuery, PickQueryQAndInternal, PickQueryRelations, PickQueryRelationsWithData, PickQueryResultColumnTypes, PickQueryShapeResultSinglePrimaryKey, PickQueryShapeSinglePrimaryKey, PickQuerySinglePrimaryKey, PickQueryWindows, PickQueryWithData, PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBaseThen, QueryBatchResult, QueryBeforeHook, QueryComputedArg, QueryData, QueryDataFromItem, QueryDataJoinTo, QueryDefaultReturnData, QueryError, QueryErrorName, QueryGet, QueryGetSelf, QueryHelperResult, QueryHooks, QueryInternal, QueryLog, QueryMetaHasSelect, QueryMetaHasWhere, QueryMethods, QueryOrExpression, QueryOrExpressionBooleanOrNullResult, QueryResult, QueryScopeData, QueryScopes, QuerySourceItem, QueryUpsertOrCreate, QueryWithTable, RawSQL, RealColumn, RecordOfColumnsShapeBase, RefExpression, RelationConfigBase, RelationConfigDataForCreate, RelationJoinQuery, RelationQuery, RelationQueryBase, RelationsBase, RuntimeComputedQueryColumn, SearchArg, SearchMethods, SearchWeight, SearchWeightRecord, Select, SelectArg, SelectArgs, SelectAs, SelectAsValue, SelectItem, SelectQueryData, SelectSubQueryResult, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, SelectableOrExpressions, SerialColumn, SerialColumnData, SetQueryKind, SetQueryKindResult, SetQueryReturnsAll, SetQueryReturnsAllKind, SetQueryReturnsAllKindResult, SetQueryReturnsColumnInfo, SetQueryReturnsColumnKind, SetQueryReturnsColumnKindResult, SetQueryReturnsColumnOptional, SetQueryReturnsColumnOrThrow, SetQueryReturnsOne, SetQueryReturnsOneKind, SetQueryReturnsOneKindResult, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsPluckColumn, SetQueryReturnsPluckColumnKind, SetQueryReturnsPluckColumnKindResult, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValueOptional, SetQueryReturnsValueOrThrow, SetQueryReturnsVoid, SetQueryReturnsVoidKind, SetQueryTableAlias, ShapeColumnPrimaryKeys, ShapeUniqueColumns, SimpleJoinItem, SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, SortDir, SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, TableDataFn, TableDataInput, TableDataItem, TableDataItemsUniqueColumnTuples, TableDataItemsUniqueColumns, TableDataItemsUniqueConstraints, TableDataMethods, TextBaseColumn, TextColumn, TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, ToSQLCtx, ToSQLOptions, ToSQLQuery, Transaction, TransactionAdapter, TransactionOptions, TransformMethods, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArgs, UnionItem, UnionKind, UnionSet, UniqueConstraints, UniqueQueryTypeOrExpression, UniqueTableDataItem, UnknownColumn, Update, UpdateArg, UpdateCtx, UpdateCtxCollect, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdateSelf, UpdatedAtDataInjector, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereNotArgs, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WhereSearchItem, WhereSearchResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowItem, WithArgsOptions, WithConfigs, WithDataItem, WithDataItems, WithItem, WithMethods, WithOptions, WithQueryBuilder, WithRecursiveOptions, WithResult, WithSqlResult, WrapQueryArg, XMLColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
package/dist/index.js CHANGED
@@ -1270,11 +1270,17 @@ class TextBaseColumn extends ColumnType {
1270
1270
  }
1271
1271
  class LimitedTextBaseColumn extends TextBaseColumn {
1272
1272
  constructor(schema, limit) {
1273
- super(schema, schema.stringMax(limit));
1273
+ super(
1274
+ schema,
1275
+ limit !== void 0 ? schema.stringMax(limit) : schema.stringSchema()
1276
+ );
1274
1277
  this.data.maxChars = limit;
1275
1278
  }
1276
1279
  toSQL() {
1277
- return orchidCore.joinTruthy(this.dataType, `(${this.data.maxChars})`);
1280
+ return orchidCore.joinTruthy(
1281
+ this.dataType,
1282
+ this.data.maxChars !== void 0 && `(${this.data.maxChars})`
1283
+ );
1278
1284
  }
1279
1285
  }
1280
1286
  class VarCharColumn extends LimitedTextBaseColumn {
@@ -2200,37 +2206,16 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2200
2206
  );
2201
2207
  } else {
2202
2208
  const item = value;
2203
- const leftColumn = columnToSql(
2204
- ctx,
2205
- query,
2206
- query.shape,
2207
- item.on[0],
2208
- `"${getJoinItemSource(item.joinFrom)}"`
2209
+ const joinAs = `"${getJoinItemSource(item.joinFrom)}"`;
2210
+ const { on } = item;
2211
+ const q = item.useOuterJoinOverrides ? {
2212
+ joinedShapes: query.joinedShapes,
2213
+ joinOverrides: query.outerJoinOverrides,
2214
+ shape: query.shape
2215
+ } : query;
2216
+ ands.push(
2217
+ `${onColumnToSql(ctx, q, joinAs, on[0])} ${on.length === 2 ? "=" : on[1]} ${onColumnToSql(ctx, q, joinAs, on.length === 3 ? on[2] : on[1])}`
2209
2218
  );
2210
- const joinTo = getJoinItemSource(item.joinTo);
2211
- const joinedShape = query.joinedShapes[joinTo];
2212
- let op;
2213
- let rightColumn;
2214
- if (item.on.length === 2) {
2215
- op = "=";
2216
- rightColumn = columnToSql(
2217
- ctx,
2218
- query,
2219
- joinedShape,
2220
- item.on[1],
2221
- `"${joinTo}"`
2222
- );
2223
- } else {
2224
- op = item.on[1];
2225
- rightColumn = columnToSql(
2226
- ctx,
2227
- query,
2228
- joinedShape,
2229
- item.on[2],
2230
- `"${joinTo}"`
2231
- );
2232
- }
2233
- ands.push(`${leftColumn} ${op} ${rightColumn}`);
2234
2219
  }
2235
2220
  } else if (key === "IN") {
2236
2221
  orchidCore.toArray(value).forEach((item) => {
@@ -2326,6 +2311,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2326
2311
  }
2327
2312
  }
2328
2313
  };
2314
+ const onColumnToSql = (ctx, query, joinAs, column) => columnToSql(ctx, query, query.shape, column, joinAs);
2329
2315
  const getJoinItemSource = (joinItem) => {
2330
2316
  return typeof joinItem === "string" ? joinItem : getQueryAs(joinItem);
2331
2317
  };
@@ -2593,7 +2579,7 @@ var __spreadValues$g = (a, b) => {
2593
2579
  return a;
2594
2580
  };
2595
2581
  var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
2596
- const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
2582
+ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2597
2583
  var _a;
2598
2584
  if (typeof first === "string") {
2599
2585
  if (first in joinTo.relations) {
@@ -2603,7 +2589,11 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
2603
2589
  const r = args[0](
2604
2590
  makeJoinQueryBuilder(j, j.q.joinedShapes, joinTo)
2605
2591
  );
2606
- return { j: j.merge(r), s: joinSubQuery || getIsJoinSubQuery(r), r };
2592
+ return {
2593
+ j: j.merge(r),
2594
+ s: whereExists ? false : joinSubQuery || getIsJoinSubQuery(r),
2595
+ r
2596
+ };
2607
2597
  }
2608
2598
  return { j, s: joinSubQuery };
2609
2599
  } else if (typeof args[0] !== "function") {
@@ -2635,7 +2625,11 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
2635
2625
  joinTo
2636
2626
  )
2637
2627
  );
2638
- return { w: first, r, s: joinSubQuery || getIsJoinSubQuery(r) };
2628
+ return {
2629
+ w: first,
2630
+ r,
2631
+ s: whereExists ? false : joinSubQuery || getIsJoinSubQuery(r)
2632
+ };
2639
2633
  }
2640
2634
  }
2641
2635
  const args0 = args.length ? args[0] : orchidCore.returnArg;
@@ -5260,7 +5254,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
5260
5254
  const column = q.shape[key];
5261
5255
  quotedColumns[0] = `"${(column == null ? void 0 : column.data.name) || key}"`;
5262
5256
  if (Array.isArray(values) && Array.isArray(values[0])) {
5263
- values = [[void 0]];
5257
+ values = values.map(() => [void 0]);
5264
5258
  }
5265
5259
  }
5266
5260
  ctx.sql.push(
@@ -5956,12 +5950,14 @@ const makeRegexToFindInSql = (value) => {
5956
5950
  return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
5957
5951
  };
5958
5952
  const resolveSubQueryCallback = (q, cb) => {
5959
- const { subQuery, relChain } = q.q;
5953
+ const { subQuery, relChain, outerJoinOverrides } = q.q;
5960
5954
  q.q.subQuery = 1;
5961
5955
  q.q.relChain = void 0;
5956
+ q.q.outerJoinOverrides = q.q.joinOverrides;
5962
5957
  const result = cb(q);
5963
5958
  q.q.subQuery = subQuery;
5964
5959
  q.q.relChain = relChain;
5960
+ q.q.outerJoinOverrides = outerJoinOverrides;
5965
5961
  return result;
5966
5962
  };
5967
5963
  const joinSubQuery = (q, sub) => {
@@ -7150,7 +7146,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
7150
7146
  item[key]
7151
7147
  );
7152
7148
  }
7153
- if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.computed || shape === anyShape)) {
7149
+ if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.computed || shape === anyShape) && item[key] !== void 0) {
7154
7150
  ctx.columns.set(key, ctx.columns.size);
7155
7151
  encoders[key] = (_c = shape[key]) == null ? void 0 : _c.encodeFn;
7156
7152
  }
@@ -7161,11 +7157,6 @@ const createCtx = () => ({
7161
7157
  columns: /* @__PURE__ */ new Map(),
7162
7158
  resultAll: void 0
7163
7159
  });
7164
- const mapColumnValues = (columns, encoders, data) => {
7165
- return columns.map(
7166
- (key) => encoders[key] && !orchidCore.isExpression(data[key]) ? encoders[key](data[key]) : data[key]
7167
- );
7168
- };
7169
7160
  const handleOneData = (q, data, ctx) => {
7170
7161
  const encoders = {};
7171
7162
  const defaults = q.q.defaults;
@@ -7174,7 +7165,14 @@ const handleOneData = (q, data, ctx) => {
7174
7165
  }
7175
7166
  processCreateItem(q, data, 0, ctx, encoders);
7176
7167
  const columns = Array.from(ctx.columns.keys());
7177
- const values = [mapColumnValues(columns, encoders, data)];
7168
+ const values = [
7169
+ columns.map(
7170
+ (key) => (
7171
+ // undefined values were stripped and no need to check for them
7172
+ encoders[key] && !orchidCore.isExpression(data[key]) ? encoders[key](data[key]) : data[key]
7173
+ )
7174
+ )
7175
+ ];
7178
7176
  return { columns, values };
7179
7177
  };
7180
7178
  const handleManyData = (q, data, ctx) => {
@@ -7189,7 +7187,9 @@ const handleManyData = (q, data, ctx) => {
7189
7187
  const values = Array(data.length);
7190
7188
  const columns = Array.from(ctx.columns.keys());
7191
7189
  data.forEach((item, i) => {
7192
- values[i] = mapColumnValues(columns, encoders, item);
7190
+ values[i] = columns.map(
7191
+ (key) => encoders[key] && item[key] !== void 0 && !orchidCore.isExpression(item[key]) ? encoders[key](item[key]) : item[key]
7192
+ );
7193
7193
  });
7194
7194
  return { columns, values };
7195
7195
  };
@@ -8387,7 +8387,7 @@ class Join {
8387
8387
  *
8388
8388
  * All the `join` methods accept the same arguments, but returning type is different because with `join` it's guaranteed to load joined table, and with `leftJoin` the joined table columns may be `NULL` when no matching record was found.
8389
8389
  *
8390
- * For the following examples, imagine we have a `User` table with `id` and `name`, and `Message` table with `id`, `text`, messages belongs to user via `userId` column:
8390
+ * For the following examples, imagine you have a `User` table with `id` and `name`, and `Message` table with `id`, `text`, messages belongs to user via `userId` column:
8391
8391
  *
8392
8392
  * ```ts
8393
8393
  * export class UserTable extends BaseTable {
@@ -8465,7 +8465,7 @@ class Join {
8465
8465
  * ```ts
8466
8466
  * const result = await db.user
8467
8467
  * .join('messages')
8468
- * // after joining a table, we can use it in `where` conditions:
8468
+ * // after joining a table, you can use it in `where` conditions:
8469
8469
  * .where({ 'messages.text': { startsWith: 'Hi' } })
8470
8470
  * .select(
8471
8471
  * 'name', // name is User column, table name may be omitted
@@ -8476,8 +8476,8 @@ class Join {
8476
8476
  * const ok: { name: string; text: string }[] = result;
8477
8477
  * ```
8478
8478
  *
8479
- * The first argument can also be a callback, where instead of relation name as a string we're picking it as a property of `q`.
8480
- * In such a way, we can alias the relation with `as`, add `where` conditions, use other query methods.
8479
+ * The first argument can also be a callback, where instead of relation name as a string you're picking it as a property of `q`.
8480
+ * In such a way, you can alias the relation with `as`, add `where` conditions, use other query methods.
8481
8481
  *
8482
8482
  * ```ts
8483
8483
  * const result = await db.user.join((q) =>
@@ -8494,7 +8494,7 @@ class Join {
8494
8494
  * (q) => q.messages.as('m'),
8495
8495
  * (q) =>
8496
8496
  * q
8497
- * .on('text', 'name') // additionally, match message with user name
8497
+ * .on('messages.text', 'user.name') // additionally, match message with user name
8498
8498
  * .where({ text: 'some text' }), // you can add `where` in a second callback as well.
8499
8499
  * );
8500
8500
  * ```
@@ -8548,17 +8548,16 @@ class Join {
8548
8548
  * Joined table can be references from `where` and `select` by a table name.
8549
8549
  *
8550
8550
  * ```ts
8551
- * // Join message where userId = id:
8552
8551
  * db.user
8553
- * .join(db.message, 'userId', 'id')
8552
+ * .join(db.message, 'userId', 'user.id')
8554
8553
  * .where({ 'message.text': { startsWith: 'Hi' } })
8555
8554
  * .select('name', 'message.text');
8556
8555
  * ```
8557
8556
  *
8558
- * Columns in the join list may be prefixed with table names for clarity:
8557
+ * The name of the joining table can be omitted, but not the name of the main table:
8559
8558
  *
8560
8559
  * ```ts
8561
- * db.user.join(db.message, 'message.userId', 'user.id');
8560
+ * db.user.join(db.message, 'userId', 'user.id');
8562
8561
  * ```
8563
8562
  *
8564
8563
  * Joined table can have an alias for referencing it further:
@@ -8589,7 +8588,7 @@ class Join {
8589
8588
  * You can provide a custom comparison operator
8590
8589
  *
8591
8590
  * ```ts
8592
- * db.user.join(db.message, 'userId', '!=', 'id');
8591
+ * db.user.join(db.message, 'userId', '!=', 'user.id');
8593
8592
  * ```
8594
8593
  *
8595
8594
  * Join can accept raw SQL for the `ON` part of join:
@@ -8624,11 +8623,11 @@ class Join {
8624
8623
  *
8625
8624
  * ```ts
8626
8625
  * db.user.join(db.message, {
8627
- * userId: 'id',
8628
- *
8629
- * // with table names:
8630
8626
  * 'message.userId': 'user.id',
8631
8627
  *
8628
+ * // joined table name may be omitted
8629
+ * userId: 'user.id',
8630
+ *
8632
8631
  * // value can be a raw SQL expression:
8633
8632
  * text: sql`lower("user"."name")`,
8634
8633
  * });
@@ -8647,17 +8646,16 @@ class Join {
8647
8646
  * db.message,
8648
8647
  * (q) =>
8649
8648
  * q
8650
- * // left column is the db.message column, right column is the db.user column
8651
- * .on('userId', 'id')
8652
- * // table names can be provided:
8653
8649
  * .on('message.userId', 'user.id')
8650
+ * // joined table name may be omitted
8651
+ * .on('userId', 'user.id')
8654
8652
  * // operator can be specified:
8655
- * .on('userId', '!=', 'id')
8653
+ * .on('userId', '!=', 'user.id')
8656
8654
  * // operator can be specified with table names as well:
8657
8655
  * .on('message.userId', '!=', 'user.id')
8658
8656
  * // `.orOn` takes the same arguments as `.on` and acts like `.or`:
8659
- * .on('userId', 'id') // where message.userId = user.id
8660
- * .orOn('text', 'name'), // or message.text = user.name
8657
+ * .on('userId', 'user.id') // where message.userId = user.id
8658
+ * .orOn('text', 'user.name'), // or message.text = user.name
8661
8659
  * );
8662
8660
  * ```
8663
8661
  *
@@ -8666,7 +8664,7 @@ class Join {
8666
8664
  * ```ts
8667
8665
  * db.user.join(db.message, (q) =>
8668
8666
  * q
8669
- * .on('userId', 'id')
8667
+ * .on('userId', 'user.id')
8670
8668
  * .where({
8671
8669
  * // not prefixed column name is for joined table:
8672
8670
  * text: { startsWith: 'hello' },
@@ -8701,7 +8699,7 @@ class Join {
8701
8699
  * .where({ text: { startsWith: 'Hi' } })
8702
8700
  * .as('t'),
8703
8701
  * 'userId',
8704
- * 'id',
8702
+ * 'user.id',
8705
8703
  * );
8706
8704
  * ```
8707
8705
  *
@@ -8768,7 +8766,7 @@ class Join {
8768
8766
  *
8769
8767
  * // the same query, but joining table explicitly
8770
8768
  * const result2: typeof result = await db.user
8771
- * .leftJoin(db.message, 'userId', 'id')
8769
+ * .leftJoin(db.message, 'userId', 'user.id')
8772
8770
  * .select('name', 'message.text');
8773
8771
  *
8774
8772
  * // result has the following type:
@@ -8870,7 +8868,7 @@ class Join {
8870
8868
  * // select message columns
8871
8869
  * .select('text')
8872
8870
  * // join the message to the user, column names can be prefixed with table names
8873
- * .on('authorId', 'id')
8871
+ * .on('authorId', 'user.id')
8874
8872
  * // message columns are available without prefixing,
8875
8873
  * // outer table columns are available with a table name
8876
8874
  * .where({ text: 'some text', 'user.name': 'name' })
@@ -8952,14 +8950,22 @@ class Join {
8952
8950
  );
8953
8951
  }
8954
8952
  }
8955
- const makeOnItem = (joinTo, joinFrom, args) => {
8956
- return {
8953
+ const makeOnItem = (joinTo, joinFrom, args) => ({
8954
+ ON: {
8955
+ joinTo,
8956
+ joinFrom,
8957
+ on: args
8958
+ }
8959
+ });
8960
+ const pushQueryOnForOuter = (q, joinFrom, joinTo, ...on) => {
8961
+ return pushQueryValue(q, "and", {
8957
8962
  ON: {
8958
- joinTo,
8959
- joinFrom,
8960
- on: args
8963
+ joinTo: joinFrom,
8964
+ joinFrom: joinTo,
8965
+ useOuterJoinOverrides: true,
8966
+ on
8961
8967
  }
8962
- };
8968
+ });
8963
8969
  };
8964
8970
  const pushQueryOn = (q, joinFrom, joinTo, ...on) => {
8965
8971
  return pushQueryValue(
@@ -9010,16 +9016,13 @@ class OnMethods {
9010
9016
  *
9011
9017
  * ```ts
9012
9018
  * q
9013
- * // left column is the db.message column, right column is the db.user column
9014
- * .on('userId', 'id')
9015
- * // table names can be provided:
9016
9019
  * .on('message.userId', 'user.id')
9020
+ * // joined table name may be omitted
9021
+ * .on('userId', 'user.id')
9017
9022
  * // operator can be specified:
9018
- * .on('userId', '!=', 'id')
9023
+ * .on('userId', '!=', 'user.id')
9019
9024
  * // operator can be specified with table names as well:
9020
9025
  * .on('message.userId', '!=', 'user.id')
9021
- * // `.orOn` takes the same arguments as `.on` and acts like `.or`:
9022
- * .on('userId', 'id') // where message.userId = user.id
9023
9026
  * ```
9024
9027
  *
9025
9028
  * @param args - columns to join with
@@ -9364,6 +9367,7 @@ const resolveCallbacksInArgs = (q, args) => {
9364
9367
  qb.q = getClonedQueryData(q.q);
9365
9368
  qb.q.and = qb.q.or = qb.q.scopes = void 0;
9366
9369
  qb.q.subQuery = 1;
9370
+ qb.q.outerJoinOverrides = qb.q.joinOverrides;
9367
9371
  args[i] = resolveSubQueryCallback(qb, arg);
9368
9372
  }
9369
9373
  }
@@ -9454,20 +9458,7 @@ const _queryWhereIn = (q, and, arg, values, not) => {
9454
9458
  return q;
9455
9459
  };
9456
9460
  const existsArgs = (self, q, args) => {
9457
- let joinSubQuery;
9458
- if (typeof q === "object") {
9459
- joinSubQuery = getIsJoinSubQuery(q);
9460
- if (joinSubQuery) {
9461
- q = q.clone();
9462
- q.shape = getShapeFromSelect(
9463
- q,
9464
- true
9465
- );
9466
- }
9467
- } else {
9468
- joinSubQuery = false;
9469
- }
9470
- const joinArgs = processJoinArgs(self, q, args, joinSubQuery);
9461
+ const joinArgs = processJoinArgs(self, q, args, false, true);
9471
9462
  return [
9472
9463
  {
9473
9464
  EXISTS: joinArgs
@@ -12981,6 +12972,7 @@ exports.processSelectArg = processSelectArg;
12981
12972
  exports.pushLimitSQL = pushLimitSQL;
12982
12973
  exports.pushQueryArray = pushQueryArray;
12983
12974
  exports.pushQueryOn = pushQueryOn;
12975
+ exports.pushQueryOnForOuter = pushQueryOnForOuter;
12984
12976
  exports.pushQueryOrOn = pushQueryOrOn;
12985
12977
  exports.pushQueryValue = pushQueryValue;
12986
12978
  exports.pushTableDataCode = pushTableDataCode;