pqb 0.36.16 → 0.38.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 +43 -34
- package/dist/index.js +79 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -76
- 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
|
|
@@ -1503,6 +1501,9 @@ interface JsonPathQuery {
|
|
|
1503
1501
|
*
|
|
1504
1502
|
* Optionally takes `vars` and `silent` parameters, see [Postgres docs](https://www.postgresql.org/docs/current/functions-json.html) for details.
|
|
1505
1503
|
*
|
|
1504
|
+
* The `type` option sets the output type when selecting a value,
|
|
1505
|
+
* also it makes specific operators available in `where`, so that you can apply `contains` if the type is text, and `gt` if the type is numeric.
|
|
1506
|
+
*
|
|
1506
1507
|
* ```ts
|
|
1507
1508
|
* // query a single value from a JSON data,
|
|
1508
1509
|
* // because of the provided type, string JSON value will be parsed to a Date object.
|
|
@@ -1533,6 +1534,14 @@ interface JsonPathQuery {
|
|
|
1533
1534
|
* name: (q) =>
|
|
1534
1535
|
* q.get('data').jsonPathQueryFirst('$.name', { type: (t) => t.string() }),
|
|
1535
1536
|
* });
|
|
1537
|
+
*
|
|
1538
|
+
* // filtering records to contain 'word' in the json property "name"
|
|
1539
|
+
* await db.table.where((q) =>
|
|
1540
|
+
* q
|
|
1541
|
+
* .get('data')
|
|
1542
|
+
* .jsonPathQueryFirst('$.name', { type: (t) => t.string() })
|
|
1543
|
+
* .contains('word'),
|
|
1544
|
+
* );
|
|
1536
1545
|
* ```
|
|
1537
1546
|
*
|
|
1538
1547
|
* @param path - JSON path
|
|
@@ -1815,9 +1824,9 @@ type WhereArg<T extends PickQueryMetaRelations> = {
|
|
|
1815
1824
|
* ```
|
|
1816
1825
|
*/
|
|
1817
1826
|
type WhereQueryBuilder<T extends PickQueryRelations> = EmptyObject extends T['relations'] ? {
|
|
1818
|
-
[K in keyof T]: K extends keyof QueryBase | keyof Where | keyof ExpressionMethods | 'sql' | 'get' | 'ref' ? T[K] : never;
|
|
1827
|
+
[K in keyof T]: K extends keyof QueryBase | keyof Where | keyof ExpressionMethods | 'sql' | 'get' | 'ref' | 'columnTypes' ? T[K] : never;
|
|
1819
1828
|
} : {
|
|
1820
|
-
[K in keyof T]: K extends keyof T['relations'] ? T['relations'][K] : K extends keyof QueryBase | keyof Where | keyof ExpressionMethods | 'sql' | 'get' | 'ref' ? T[K] : never;
|
|
1829
|
+
[K in keyof T]: K extends keyof T['relations'] ? T['relations'][K] : K extends keyof QueryBase | keyof Where | keyof ExpressionMethods | 'sql' | 'get' | 'ref' | 'columnTypes' ? T[K] : never;
|
|
1821
1830
|
};
|
|
1822
1831
|
type WhereArgs<T extends PickQueryMetaRelations> = WhereArg<T>[];
|
|
1823
1832
|
type WhereNotArgs<T extends PickQueryMetaRelations> = [WhereArg<T>];
|
|
@@ -5180,7 +5189,7 @@ declare class Select {
|
|
|
5180
5189
|
*
|
|
5181
5190
|
* // table name may refer to the current table or a joined table:
|
|
5182
5191
|
* db.table
|
|
5183
|
-
* .join(Message, 'authorId', 'id')
|
|
5192
|
+
* .join(Message, 'authorId', 'user.id')
|
|
5184
5193
|
* .select('user.name', 'message.text', { textAlias: 'message.text' });
|
|
5185
5194
|
*
|
|
5186
5195
|
* // select value from the sub-query,
|
|
@@ -5309,7 +5318,7 @@ declare class SqlMethod<ColumnTypes> {
|
|
|
5309
5318
|
*
|
|
5310
5319
|
* ```ts
|
|
5311
5320
|
* // ids will be prefixed with proper table names, no ambiguity:
|
|
5312
|
-
* db.table.join(db.otherTable, 'id', 'otherId').where`
|
|
5321
|
+
* db.table.join(db.otherTable, 'id', 'other.otherId').where`
|
|
5313
5322
|
* ${db.table.column('id')} = 1 AND
|
|
5314
5323
|
* ${db.otherTable.ref('id')} = 2
|
|
5315
5324
|
* `;
|
|
@@ -8033,4 +8042,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
8033
8042
|
*/
|
|
8034
8043
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
8035
8044
|
|
|
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 };
|
|
8045
|
+
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
|
@@ -935,6 +935,22 @@ const quoteValue$1 = (arg, ctx, quotedAs, jsonArray) => {
|
|
|
935
935
|
}
|
|
936
936
|
return orchidCore.addValue(ctx.values, arg);
|
|
937
937
|
};
|
|
938
|
+
const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
|
|
939
|
+
if (arg && typeof arg === "object") {
|
|
940
|
+
if (!jsonArray && Array.isArray(arg)) {
|
|
941
|
+
return `(${arg.map((value) => orchidCore.addValue(ctx.values, value)).join(", ")})`;
|
|
942
|
+
}
|
|
943
|
+
if (orchidCore.isExpression(arg)) {
|
|
944
|
+
return arg.toSQL(ctx, quotedAs);
|
|
945
|
+
}
|
|
946
|
+
if ("toSQL" in arg) {
|
|
947
|
+
return `replace(replace((${getSqlText(
|
|
948
|
+
arg.toSQL({ values: ctx.values })
|
|
949
|
+
)}), '%', '\\\\%'), '_', '\\\\_')`;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return orchidCore.addValue(ctx.values, arg.replace(/[%_]/g, "\\$&"));
|
|
953
|
+
};
|
|
938
954
|
const base = {
|
|
939
955
|
equals: make(
|
|
940
956
|
(key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue$1(value, ctx, quotedAs)}`
|
|
@@ -980,22 +996,22 @@ const numeric = __spreadProps$9(__spreadValues$j({}, base), {
|
|
|
980
996
|
});
|
|
981
997
|
const text = __spreadProps$9(__spreadValues$j({}, base), {
|
|
982
998
|
contains: make(
|
|
983
|
-
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${
|
|
999
|
+
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
984
1000
|
),
|
|
985
1001
|
containsSensitive: make(
|
|
986
|
-
(key, value, ctx, quotedAs) => `${key} LIKE '%' || ${
|
|
1002
|
+
(key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
987
1003
|
),
|
|
988
1004
|
startsWith: make(
|
|
989
|
-
(key, value, ctx, quotedAs) => `${key} ILIKE ${
|
|
1005
|
+
(key, value, ctx, quotedAs) => `${key} ILIKE ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
990
1006
|
),
|
|
991
1007
|
startsWithSensitive: make(
|
|
992
|
-
(key, value, ctx, quotedAs) => `${key} LIKE ${
|
|
1008
|
+
(key, value, ctx, quotedAs) => `${key} LIKE ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
993
1009
|
),
|
|
994
1010
|
endsWith: make(
|
|
995
|
-
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${
|
|
1011
|
+
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)}`
|
|
996
1012
|
),
|
|
997
1013
|
endsWithSensitive: make(
|
|
998
|
-
(key, value, ctx, quotedAs) => `${key} LIKE '%' || ${
|
|
1014
|
+
(key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)}`
|
|
999
1015
|
)
|
|
1000
1016
|
});
|
|
1001
1017
|
const encodeJsonPath = (ctx, path) => orchidCore.addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
|
|
@@ -1009,9 +1025,10 @@ const json = __spreadProps$9(__spreadValues$j({}, base), {
|
|
|
1009
1025
|
this.q.parsers[orchidCore.getValueKey] = void 0;
|
|
1010
1026
|
}
|
|
1011
1027
|
if (options == null ? void 0 : options.type) {
|
|
1012
|
-
const
|
|
1013
|
-
if (
|
|
1014
|
-
((_e = (_d = this.q).parsers) != null ? _e : _d.parsers = {})[orchidCore.getValueKey] =
|
|
1028
|
+
const type = options.type(this.columnTypes);
|
|
1029
|
+
if (type.parseFn)
|
|
1030
|
+
((_e = (_d = this.q).parsers) != null ? _e : _d.parsers = {})[orchidCore.getValueKey] = type.parseFn;
|
|
1031
|
+
return setQueryOperators(this, type.operators);
|
|
1015
1032
|
}
|
|
1016
1033
|
return this;
|
|
1017
1034
|
},
|
|
@@ -2206,37 +2223,16 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2206
2223
|
);
|
|
2207
2224
|
} else {
|
|
2208
2225
|
const item = value;
|
|
2209
|
-
const
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
query.
|
|
2213
|
-
|
|
2214
|
-
|
|
2226
|
+
const joinAs = `"${getJoinItemSource(item.joinFrom)}"`;
|
|
2227
|
+
const { on } = item;
|
|
2228
|
+
const q = item.useOuterJoinOverrides ? {
|
|
2229
|
+
joinedShapes: query.joinedShapes,
|
|
2230
|
+
joinOverrides: query.outerJoinOverrides,
|
|
2231
|
+
shape: query.shape
|
|
2232
|
+
} : query;
|
|
2233
|
+
ands.push(
|
|
2234
|
+
`${onColumnToSql(ctx, q, joinAs, on[0])} ${on.length === 2 ? "=" : on[1]} ${onColumnToSql(ctx, q, joinAs, on.length === 3 ? on[2] : on[1])}`
|
|
2215
2235
|
);
|
|
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
2236
|
}
|
|
2241
2237
|
} else if (key === "IN") {
|
|
2242
2238
|
orchidCore.toArray(value).forEach((item) => {
|
|
@@ -2332,6 +2328,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2332
2328
|
}
|
|
2333
2329
|
}
|
|
2334
2330
|
};
|
|
2331
|
+
const onColumnToSql = (ctx, query, joinAs, column) => columnToSql(ctx, query, query.shape, column, joinAs);
|
|
2335
2332
|
const getJoinItemSource = (joinItem) => {
|
|
2336
2333
|
return typeof joinItem === "string" ? joinItem : getQueryAs(joinItem);
|
|
2337
2334
|
};
|
|
@@ -5970,12 +5967,14 @@ const makeRegexToFindInSql = (value) => {
|
|
|
5970
5967
|
return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
|
|
5971
5968
|
};
|
|
5972
5969
|
const resolveSubQueryCallback = (q, cb) => {
|
|
5973
|
-
const { subQuery, relChain } = q.q;
|
|
5970
|
+
const { subQuery, relChain, outerJoinOverrides } = q.q;
|
|
5974
5971
|
q.q.subQuery = 1;
|
|
5975
5972
|
q.q.relChain = void 0;
|
|
5973
|
+
q.q.outerJoinOverrides = q.q.joinOverrides;
|
|
5976
5974
|
const result = cb(q);
|
|
5977
5975
|
q.q.subQuery = subQuery;
|
|
5978
5976
|
q.q.relChain = relChain;
|
|
5977
|
+
q.q.outerJoinOverrides = outerJoinOverrides;
|
|
5979
5978
|
return result;
|
|
5980
5979
|
};
|
|
5981
5980
|
const joinSubQuery = (q, sub) => {
|
|
@@ -8405,7 +8404,7 @@ class Join {
|
|
|
8405
8404
|
*
|
|
8406
8405
|
* 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
8406
|
*
|
|
8408
|
-
* For the following examples, imagine
|
|
8407
|
+
* 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
8408
|
*
|
|
8410
8409
|
* ```ts
|
|
8411
8410
|
* export class UserTable extends BaseTable {
|
|
@@ -8483,7 +8482,7 @@ class Join {
|
|
|
8483
8482
|
* ```ts
|
|
8484
8483
|
* const result = await db.user
|
|
8485
8484
|
* .join('messages')
|
|
8486
|
-
* // after joining a table,
|
|
8485
|
+
* // after joining a table, you can use it in `where` conditions:
|
|
8487
8486
|
* .where({ 'messages.text': { startsWith: 'Hi' } })
|
|
8488
8487
|
* .select(
|
|
8489
8488
|
* 'name', // name is User column, table name may be omitted
|
|
@@ -8494,8 +8493,8 @@ class Join {
|
|
|
8494
8493
|
* const ok: { name: string; text: string }[] = result;
|
|
8495
8494
|
* ```
|
|
8496
8495
|
*
|
|
8497
|
-
* The first argument can also be a callback, where instead of relation name as a string
|
|
8498
|
-
* In such a way,
|
|
8496
|
+
* 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`.
|
|
8497
|
+
* In such a way, you can alias the relation with `as`, add `where` conditions, use other query methods.
|
|
8499
8498
|
*
|
|
8500
8499
|
* ```ts
|
|
8501
8500
|
* const result = await db.user.join((q) =>
|
|
@@ -8512,7 +8511,7 @@ class Join {
|
|
|
8512
8511
|
* (q) => q.messages.as('m'),
|
|
8513
8512
|
* (q) =>
|
|
8514
8513
|
* q
|
|
8515
|
-
* .on('text', 'name') // additionally, match message with user name
|
|
8514
|
+
* .on('messages.text', 'user.name') // additionally, match message with user name
|
|
8516
8515
|
* .where({ text: 'some text' }), // you can add `where` in a second callback as well.
|
|
8517
8516
|
* );
|
|
8518
8517
|
* ```
|
|
@@ -8566,17 +8565,16 @@ class Join {
|
|
|
8566
8565
|
* Joined table can be references from `where` and `select` by a table name.
|
|
8567
8566
|
*
|
|
8568
8567
|
* ```ts
|
|
8569
|
-
* // Join message where userId = id:
|
|
8570
8568
|
* db.user
|
|
8571
|
-
* .join(db.message, 'userId', 'id')
|
|
8569
|
+
* .join(db.message, 'userId', 'user.id')
|
|
8572
8570
|
* .where({ 'message.text': { startsWith: 'Hi' } })
|
|
8573
8571
|
* .select('name', 'message.text');
|
|
8574
8572
|
* ```
|
|
8575
8573
|
*
|
|
8576
|
-
*
|
|
8574
|
+
* The name of the joining table can be omitted, but not the name of the main table:
|
|
8577
8575
|
*
|
|
8578
8576
|
* ```ts
|
|
8579
|
-
* db.user.join(db.message, '
|
|
8577
|
+
* db.user.join(db.message, 'userId', 'user.id');
|
|
8580
8578
|
* ```
|
|
8581
8579
|
*
|
|
8582
8580
|
* Joined table can have an alias for referencing it further:
|
|
@@ -8607,7 +8605,7 @@ class Join {
|
|
|
8607
8605
|
* You can provide a custom comparison operator
|
|
8608
8606
|
*
|
|
8609
8607
|
* ```ts
|
|
8610
|
-
* db.user.join(db.message, 'userId', '!=', 'id');
|
|
8608
|
+
* db.user.join(db.message, 'userId', '!=', 'user.id');
|
|
8611
8609
|
* ```
|
|
8612
8610
|
*
|
|
8613
8611
|
* Join can accept raw SQL for the `ON` part of join:
|
|
@@ -8642,11 +8640,11 @@ class Join {
|
|
|
8642
8640
|
*
|
|
8643
8641
|
* ```ts
|
|
8644
8642
|
* db.user.join(db.message, {
|
|
8645
|
-
* userId: 'id',
|
|
8646
|
-
*
|
|
8647
|
-
* // with table names:
|
|
8648
8643
|
* 'message.userId': 'user.id',
|
|
8649
8644
|
*
|
|
8645
|
+
* // joined table name may be omitted
|
|
8646
|
+
* userId: 'user.id',
|
|
8647
|
+
*
|
|
8650
8648
|
* // value can be a raw SQL expression:
|
|
8651
8649
|
* text: sql`lower("user"."name")`,
|
|
8652
8650
|
* });
|
|
@@ -8665,17 +8663,16 @@ class Join {
|
|
|
8665
8663
|
* db.message,
|
|
8666
8664
|
* (q) =>
|
|
8667
8665
|
* 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
8666
|
* .on('message.userId', 'user.id')
|
|
8667
|
+
* // joined table name may be omitted
|
|
8668
|
+
* .on('userId', 'user.id')
|
|
8672
8669
|
* // operator can be specified:
|
|
8673
|
-
* .on('userId', '!=', 'id')
|
|
8670
|
+
* .on('userId', '!=', 'user.id')
|
|
8674
8671
|
* // operator can be specified with table names as well:
|
|
8675
8672
|
* .on('message.userId', '!=', 'user.id')
|
|
8676
8673
|
* // `.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
|
|
8674
|
+
* .on('userId', 'user.id') // where message.userId = user.id
|
|
8675
|
+
* .orOn('text', 'user.name'), // or message.text = user.name
|
|
8679
8676
|
* );
|
|
8680
8677
|
* ```
|
|
8681
8678
|
*
|
|
@@ -8684,7 +8681,7 @@ class Join {
|
|
|
8684
8681
|
* ```ts
|
|
8685
8682
|
* db.user.join(db.message, (q) =>
|
|
8686
8683
|
* q
|
|
8687
|
-
* .on('userId', 'id')
|
|
8684
|
+
* .on('userId', 'user.id')
|
|
8688
8685
|
* .where({
|
|
8689
8686
|
* // not prefixed column name is for joined table:
|
|
8690
8687
|
* text: { startsWith: 'hello' },
|
|
@@ -8719,7 +8716,7 @@ class Join {
|
|
|
8719
8716
|
* .where({ text: { startsWith: 'Hi' } })
|
|
8720
8717
|
* .as('t'),
|
|
8721
8718
|
* 'userId',
|
|
8722
|
-
* 'id',
|
|
8719
|
+
* 'user.id',
|
|
8723
8720
|
* );
|
|
8724
8721
|
* ```
|
|
8725
8722
|
*
|
|
@@ -8786,7 +8783,7 @@ class Join {
|
|
|
8786
8783
|
*
|
|
8787
8784
|
* // the same query, but joining table explicitly
|
|
8788
8785
|
* const result2: typeof result = await db.user
|
|
8789
|
-
* .leftJoin(db.message, 'userId', 'id')
|
|
8786
|
+
* .leftJoin(db.message, 'userId', 'user.id')
|
|
8790
8787
|
* .select('name', 'message.text');
|
|
8791
8788
|
*
|
|
8792
8789
|
* // result has the following type:
|
|
@@ -8888,7 +8885,7 @@ class Join {
|
|
|
8888
8885
|
* // select message columns
|
|
8889
8886
|
* .select('text')
|
|
8890
8887
|
* // join the message to the user, column names can be prefixed with table names
|
|
8891
|
-
* .on('authorId', 'id')
|
|
8888
|
+
* .on('authorId', 'user.id')
|
|
8892
8889
|
* // message columns are available without prefixing,
|
|
8893
8890
|
* // outer table columns are available with a table name
|
|
8894
8891
|
* .where({ text: 'some text', 'user.name': 'name' })
|
|
@@ -8970,14 +8967,22 @@ class Join {
|
|
|
8970
8967
|
);
|
|
8971
8968
|
}
|
|
8972
8969
|
}
|
|
8973
|
-
const makeOnItem = (joinTo, joinFrom, args) => {
|
|
8974
|
-
|
|
8970
|
+
const makeOnItem = (joinTo, joinFrom, args) => ({
|
|
8971
|
+
ON: {
|
|
8972
|
+
joinTo,
|
|
8973
|
+
joinFrom,
|
|
8974
|
+
on: args
|
|
8975
|
+
}
|
|
8976
|
+
});
|
|
8977
|
+
const pushQueryOnForOuter = (q, joinFrom, joinTo, ...on) => {
|
|
8978
|
+
return pushQueryValue(q, "and", {
|
|
8975
8979
|
ON: {
|
|
8976
|
-
joinTo,
|
|
8977
|
-
joinFrom,
|
|
8978
|
-
|
|
8980
|
+
joinTo: joinFrom,
|
|
8981
|
+
joinFrom: joinTo,
|
|
8982
|
+
useOuterJoinOverrides: true,
|
|
8983
|
+
on
|
|
8979
8984
|
}
|
|
8980
|
-
};
|
|
8985
|
+
});
|
|
8981
8986
|
};
|
|
8982
8987
|
const pushQueryOn = (q, joinFrom, joinTo, ...on) => {
|
|
8983
8988
|
return pushQueryValue(
|
|
@@ -9028,16 +9033,13 @@ class OnMethods {
|
|
|
9028
9033
|
*
|
|
9029
9034
|
* ```ts
|
|
9030
9035
|
* 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
9036
|
* .on('message.userId', 'user.id')
|
|
9037
|
+
* // joined table name may be omitted
|
|
9038
|
+
* .on('userId', 'user.id')
|
|
9035
9039
|
* // operator can be specified:
|
|
9036
|
-
* .on('userId', '!=', 'id')
|
|
9040
|
+
* .on('userId', '!=', 'user.id')
|
|
9037
9041
|
* // operator can be specified with table names as well:
|
|
9038
9042
|
* .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
9043
|
* ```
|
|
9042
9044
|
*
|
|
9043
9045
|
* @param args - columns to join with
|
|
@@ -9382,6 +9384,7 @@ const resolveCallbacksInArgs = (q, args) => {
|
|
|
9382
9384
|
qb.q = getClonedQueryData(q.q);
|
|
9383
9385
|
qb.q.and = qb.q.or = qb.q.scopes = void 0;
|
|
9384
9386
|
qb.q.subQuery = 1;
|
|
9387
|
+
qb.q.outerJoinOverrides = qb.q.joinOverrides;
|
|
9385
9388
|
args[i] = resolveSubQueryCallback(qb, arg);
|
|
9386
9389
|
}
|
|
9387
9390
|
}
|
|
@@ -12986,6 +12989,7 @@ exports.processSelectArg = processSelectArg;
|
|
|
12986
12989
|
exports.pushLimitSQL = pushLimitSQL;
|
|
12987
12990
|
exports.pushQueryArray = pushQueryArray;
|
|
12988
12991
|
exports.pushQueryOn = pushQueryOn;
|
|
12992
|
+
exports.pushQueryOnForOuter = pushQueryOnForOuter;
|
|
12989
12993
|
exports.pushQueryOrOn = pushQueryOrOn;
|
|
12990
12994
|
exports.pushQueryValue = pushQueryValue;
|
|
12991
12995
|
exports.pushTableDataCode = pushTableDataCode;
|