pqb 0.36.16 → 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 +30 -32
- package/dist/index.js +53 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -67
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
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,
|
|
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
|
|
910
|
-
* In such a way,
|
|
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
|
-
*
|
|
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, '
|
|
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
|
|
@@ -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
|
@@ -2206,37 +2206,16 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2206
2206
|
);
|
|
2207
2207
|
} else {
|
|
2208
2208
|
const item = value;
|
|
2209
|
-
const
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
query.
|
|
2213
|
-
|
|
2214
|
-
|
|
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])}`
|
|
2215
2218
|
);
|
|
2216
|
-
const joinTo = getJoinItemSource(item.joinTo);
|
|
2217
|
-
const joinedShape = query.joinedShapes[joinTo];
|
|
2218
|
-
let op;
|
|
2219
|
-
let rightColumn;
|
|
2220
|
-
if (item.on.length === 2) {
|
|
2221
|
-
op = "=";
|
|
2222
|
-
rightColumn = columnToSql(
|
|
2223
|
-
ctx,
|
|
2224
|
-
query,
|
|
2225
|
-
joinedShape,
|
|
2226
|
-
item.on[1],
|
|
2227
|
-
`"${joinTo}"`
|
|
2228
|
-
);
|
|
2229
|
-
} else {
|
|
2230
|
-
op = item.on[1];
|
|
2231
|
-
rightColumn = columnToSql(
|
|
2232
|
-
ctx,
|
|
2233
|
-
query,
|
|
2234
|
-
joinedShape,
|
|
2235
|
-
item.on[2],
|
|
2236
|
-
`"${joinTo}"`
|
|
2237
|
-
);
|
|
2238
|
-
}
|
|
2239
|
-
ands.push(`${leftColumn} ${op} ${rightColumn}`);
|
|
2240
2219
|
}
|
|
2241
2220
|
} else if (key === "IN") {
|
|
2242
2221
|
orchidCore.toArray(value).forEach((item) => {
|
|
@@ -2332,6 +2311,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2332
2311
|
}
|
|
2333
2312
|
}
|
|
2334
2313
|
};
|
|
2314
|
+
const onColumnToSql = (ctx, query, joinAs, column) => columnToSql(ctx, query, query.shape, column, joinAs);
|
|
2335
2315
|
const getJoinItemSource = (joinItem) => {
|
|
2336
2316
|
return typeof joinItem === "string" ? joinItem : getQueryAs(joinItem);
|
|
2337
2317
|
};
|
|
@@ -5970,12 +5950,14 @@ const makeRegexToFindInSql = (value) => {
|
|
|
5970
5950
|
return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
|
|
5971
5951
|
};
|
|
5972
5952
|
const resolveSubQueryCallback = (q, cb) => {
|
|
5973
|
-
const { subQuery, relChain } = q.q;
|
|
5953
|
+
const { subQuery, relChain, outerJoinOverrides } = q.q;
|
|
5974
5954
|
q.q.subQuery = 1;
|
|
5975
5955
|
q.q.relChain = void 0;
|
|
5956
|
+
q.q.outerJoinOverrides = q.q.joinOverrides;
|
|
5976
5957
|
const result = cb(q);
|
|
5977
5958
|
q.q.subQuery = subQuery;
|
|
5978
5959
|
q.q.relChain = relChain;
|
|
5960
|
+
q.q.outerJoinOverrides = outerJoinOverrides;
|
|
5979
5961
|
return result;
|
|
5980
5962
|
};
|
|
5981
5963
|
const joinSubQuery = (q, sub) => {
|
|
@@ -8405,7 +8387,7 @@ class Join {
|
|
|
8405
8387
|
*
|
|
8406
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.
|
|
8407
8389
|
*
|
|
8408
|
-
* For the following examples, imagine
|
|
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:
|
|
8409
8391
|
*
|
|
8410
8392
|
* ```ts
|
|
8411
8393
|
* export class UserTable extends BaseTable {
|
|
@@ -8483,7 +8465,7 @@ class Join {
|
|
|
8483
8465
|
* ```ts
|
|
8484
8466
|
* const result = await db.user
|
|
8485
8467
|
* .join('messages')
|
|
8486
|
-
* // after joining a table,
|
|
8468
|
+
* // after joining a table, you can use it in `where` conditions:
|
|
8487
8469
|
* .where({ 'messages.text': { startsWith: 'Hi' } })
|
|
8488
8470
|
* .select(
|
|
8489
8471
|
* 'name', // name is User column, table name may be omitted
|
|
@@ -8494,8 +8476,8 @@ class Join {
|
|
|
8494
8476
|
* const ok: { name: string; text: string }[] = result;
|
|
8495
8477
|
* ```
|
|
8496
8478
|
*
|
|
8497
|
-
* The first argument can also be a callback, where instead of relation name as a string
|
|
8498
|
-
* In such a way,
|
|
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.
|
|
8499
8481
|
*
|
|
8500
8482
|
* ```ts
|
|
8501
8483
|
* const result = await db.user.join((q) =>
|
|
@@ -8512,7 +8494,7 @@ class Join {
|
|
|
8512
8494
|
* (q) => q.messages.as('m'),
|
|
8513
8495
|
* (q) =>
|
|
8514
8496
|
* q
|
|
8515
|
-
* .on('text', 'name') // additionally, match message with user name
|
|
8497
|
+
* .on('messages.text', 'user.name') // additionally, match message with user name
|
|
8516
8498
|
* .where({ text: 'some text' }), // you can add `where` in a second callback as well.
|
|
8517
8499
|
* );
|
|
8518
8500
|
* ```
|
|
@@ -8566,17 +8548,16 @@ class Join {
|
|
|
8566
8548
|
* Joined table can be references from `where` and `select` by a table name.
|
|
8567
8549
|
*
|
|
8568
8550
|
* ```ts
|
|
8569
|
-
* // Join message where userId = id:
|
|
8570
8551
|
* db.user
|
|
8571
|
-
* .join(db.message, 'userId', 'id')
|
|
8552
|
+
* .join(db.message, 'userId', 'user.id')
|
|
8572
8553
|
* .where({ 'message.text': { startsWith: 'Hi' } })
|
|
8573
8554
|
* .select('name', 'message.text');
|
|
8574
8555
|
* ```
|
|
8575
8556
|
*
|
|
8576
|
-
*
|
|
8557
|
+
* The name of the joining table can be omitted, but not the name of the main table:
|
|
8577
8558
|
*
|
|
8578
8559
|
* ```ts
|
|
8579
|
-
* db.user.join(db.message, '
|
|
8560
|
+
* db.user.join(db.message, 'userId', 'user.id');
|
|
8580
8561
|
* ```
|
|
8581
8562
|
*
|
|
8582
8563
|
* Joined table can have an alias for referencing it further:
|
|
@@ -8607,7 +8588,7 @@ class Join {
|
|
|
8607
8588
|
* You can provide a custom comparison operator
|
|
8608
8589
|
*
|
|
8609
8590
|
* ```ts
|
|
8610
|
-
* db.user.join(db.message, 'userId', '!=', 'id');
|
|
8591
|
+
* db.user.join(db.message, 'userId', '!=', 'user.id');
|
|
8611
8592
|
* ```
|
|
8612
8593
|
*
|
|
8613
8594
|
* Join can accept raw SQL for the `ON` part of join:
|
|
@@ -8642,11 +8623,11 @@ class Join {
|
|
|
8642
8623
|
*
|
|
8643
8624
|
* ```ts
|
|
8644
8625
|
* db.user.join(db.message, {
|
|
8645
|
-
* userId: 'id',
|
|
8646
|
-
*
|
|
8647
|
-
* // with table names:
|
|
8648
8626
|
* 'message.userId': 'user.id',
|
|
8649
8627
|
*
|
|
8628
|
+
* // joined table name may be omitted
|
|
8629
|
+
* userId: 'user.id',
|
|
8630
|
+
*
|
|
8650
8631
|
* // value can be a raw SQL expression:
|
|
8651
8632
|
* text: sql`lower("user"."name")`,
|
|
8652
8633
|
* });
|
|
@@ -8665,17 +8646,16 @@ class Join {
|
|
|
8665
8646
|
* db.message,
|
|
8666
8647
|
* (q) =>
|
|
8667
8648
|
* q
|
|
8668
|
-
* // left column is the db.message column, right column is the db.user column
|
|
8669
|
-
* .on('userId', 'id')
|
|
8670
|
-
* // table names can be provided:
|
|
8671
8649
|
* .on('message.userId', 'user.id')
|
|
8650
|
+
* // joined table name may be omitted
|
|
8651
|
+
* .on('userId', 'user.id')
|
|
8672
8652
|
* // operator can be specified:
|
|
8673
|
-
* .on('userId', '!=', 'id')
|
|
8653
|
+
* .on('userId', '!=', 'user.id')
|
|
8674
8654
|
* // operator can be specified with table names as well:
|
|
8675
8655
|
* .on('message.userId', '!=', 'user.id')
|
|
8676
8656
|
* // `.orOn` takes the same arguments as `.on` and acts like `.or`:
|
|
8677
|
-
* .on('userId', 'id') // where message.userId = user.id
|
|
8678
|
-
* .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
|
|
8679
8659
|
* );
|
|
8680
8660
|
* ```
|
|
8681
8661
|
*
|
|
@@ -8684,7 +8664,7 @@ class Join {
|
|
|
8684
8664
|
* ```ts
|
|
8685
8665
|
* db.user.join(db.message, (q) =>
|
|
8686
8666
|
* q
|
|
8687
|
-
* .on('userId', 'id')
|
|
8667
|
+
* .on('userId', 'user.id')
|
|
8688
8668
|
* .where({
|
|
8689
8669
|
* // not prefixed column name is for joined table:
|
|
8690
8670
|
* text: { startsWith: 'hello' },
|
|
@@ -8719,7 +8699,7 @@ class Join {
|
|
|
8719
8699
|
* .where({ text: { startsWith: 'Hi' } })
|
|
8720
8700
|
* .as('t'),
|
|
8721
8701
|
* 'userId',
|
|
8722
|
-
* 'id',
|
|
8702
|
+
* 'user.id',
|
|
8723
8703
|
* );
|
|
8724
8704
|
* ```
|
|
8725
8705
|
*
|
|
@@ -8786,7 +8766,7 @@ class Join {
|
|
|
8786
8766
|
*
|
|
8787
8767
|
* // the same query, but joining table explicitly
|
|
8788
8768
|
* const result2: typeof result = await db.user
|
|
8789
|
-
* .leftJoin(db.message, 'userId', 'id')
|
|
8769
|
+
* .leftJoin(db.message, 'userId', 'user.id')
|
|
8790
8770
|
* .select('name', 'message.text');
|
|
8791
8771
|
*
|
|
8792
8772
|
* // result has the following type:
|
|
@@ -8888,7 +8868,7 @@ class Join {
|
|
|
8888
8868
|
* // select message columns
|
|
8889
8869
|
* .select('text')
|
|
8890
8870
|
* // join the message to the user, column names can be prefixed with table names
|
|
8891
|
-
* .on('authorId', 'id')
|
|
8871
|
+
* .on('authorId', 'user.id')
|
|
8892
8872
|
* // message columns are available without prefixing,
|
|
8893
8873
|
* // outer table columns are available with a table name
|
|
8894
8874
|
* .where({ text: 'some text', 'user.name': 'name' })
|
|
@@ -8970,14 +8950,22 @@ class Join {
|
|
|
8970
8950
|
);
|
|
8971
8951
|
}
|
|
8972
8952
|
}
|
|
8973
|
-
const makeOnItem = (joinTo, joinFrom, args) => {
|
|
8974
|
-
|
|
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", {
|
|
8975
8962
|
ON: {
|
|
8976
|
-
joinTo,
|
|
8977
|
-
joinFrom,
|
|
8978
|
-
|
|
8963
|
+
joinTo: joinFrom,
|
|
8964
|
+
joinFrom: joinTo,
|
|
8965
|
+
useOuterJoinOverrides: true,
|
|
8966
|
+
on
|
|
8979
8967
|
}
|
|
8980
|
-
};
|
|
8968
|
+
});
|
|
8981
8969
|
};
|
|
8982
8970
|
const pushQueryOn = (q, joinFrom, joinTo, ...on) => {
|
|
8983
8971
|
return pushQueryValue(
|
|
@@ -9028,16 +9016,13 @@ class OnMethods {
|
|
|
9028
9016
|
*
|
|
9029
9017
|
* ```ts
|
|
9030
9018
|
* q
|
|
9031
|
-
* // left column is the db.message column, right column is the db.user column
|
|
9032
|
-
* .on('userId', 'id')
|
|
9033
|
-
* // table names can be provided:
|
|
9034
9019
|
* .on('message.userId', 'user.id')
|
|
9020
|
+
* // joined table name may be omitted
|
|
9021
|
+
* .on('userId', 'user.id')
|
|
9035
9022
|
* // operator can be specified:
|
|
9036
|
-
* .on('userId', '!=', 'id')
|
|
9023
|
+
* .on('userId', '!=', 'user.id')
|
|
9037
9024
|
* // operator can be specified with table names as well:
|
|
9038
9025
|
* .on('message.userId', '!=', 'user.id')
|
|
9039
|
-
* // `.orOn` takes the same arguments as `.on` and acts like `.or`:
|
|
9040
|
-
* .on('userId', 'id') // where message.userId = user.id
|
|
9041
9026
|
* ```
|
|
9042
9027
|
*
|
|
9043
9028
|
* @param args - columns to join with
|
|
@@ -9382,6 +9367,7 @@ const resolveCallbacksInArgs = (q, args) => {
|
|
|
9382
9367
|
qb.q = getClonedQueryData(q.q);
|
|
9383
9368
|
qb.q.and = qb.q.or = qb.q.scopes = void 0;
|
|
9384
9369
|
qb.q.subQuery = 1;
|
|
9370
|
+
qb.q.outerJoinOverrides = qb.q.joinOverrides;
|
|
9385
9371
|
args[i] = resolveSubQueryCallback(qb, arg);
|
|
9386
9372
|
}
|
|
9387
9373
|
}
|
|
@@ -12986,6 +12972,7 @@ exports.processSelectArg = processSelectArg;
|
|
|
12986
12972
|
exports.pushLimitSQL = pushLimitSQL;
|
|
12987
12973
|
exports.pushQueryArray = pushQueryArray;
|
|
12988
12974
|
exports.pushQueryOn = pushQueryOn;
|
|
12975
|
+
exports.pushQueryOnForOuter = pushQueryOnForOuter;
|
|
12989
12976
|
exports.pushQueryOrOn = pushQueryOrOn;
|
|
12990
12977
|
exports.pushQueryValue = pushQueryValue;
|
|
12991
12978
|
exports.pushTableDataCode = pushTableDataCode;
|