pqb 0.0.7 → 0.0.8
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 +10 -14
- package/dist/index.esm.js +24 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +24 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/queryMethods/where.test.ts +14 -2
- package/src/queryMethods/where.ts +3 -0
- package/src/relations.ts +1 -1
- package/src/sql/aggregate.ts +1 -4
- package/src/sql/having.ts +2 -8
- package/src/sql/insert.ts +2 -8
- package/src/sql/join.ts +19 -15
- package/src/sql/select.ts +2 -8
- package/src/sql/types.ts +6 -2
- package/src/sql/where.ts +9 -15
package/dist/index.d.ts
CHANGED
|
@@ -431,7 +431,7 @@ declare type BaseRelation = {
|
|
|
431
431
|
key: string;
|
|
432
432
|
model: QueryWithTable;
|
|
433
433
|
query: QueryWithTable;
|
|
434
|
-
joinQuery: Query;
|
|
434
|
+
joinQuery(fromQuery: Query, toQuery: Query): Query;
|
|
435
435
|
nestedCreateQuery: Query;
|
|
436
436
|
nestedInsert?: BelongsToNestedInsert | HasOneNestedInsert | HasManyNestedInsert;
|
|
437
437
|
nestedUpdate?: BelongsToNestedUpdate | HasOneNestedUpdate | HasManyNestedUpdate;
|
|
@@ -774,20 +774,16 @@ declare type WhereJsonPathEqualsItem = [
|
|
|
774
774
|
rightPath: string
|
|
775
775
|
];
|
|
776
776
|
declare type WhereOnItem = {
|
|
777
|
-
joinFrom:
|
|
778
|
-
|
|
779
|
-
query: {
|
|
780
|
-
as?: string;
|
|
781
|
-
};
|
|
782
|
-
} | string;
|
|
783
|
-
joinTo: {
|
|
784
|
-
table?: string;
|
|
785
|
-
query: {
|
|
786
|
-
as?: string;
|
|
787
|
-
};
|
|
788
|
-
} | string;
|
|
777
|
+
joinFrom: WhereOnJoinItem;
|
|
778
|
+
joinTo: WhereOnJoinItem;
|
|
789
779
|
on: [leftFullColumn: string, rightFullColumn: string] | [leftFullColumn: string, op: string, rightFullColumn: string];
|
|
790
780
|
};
|
|
781
|
+
declare type WhereOnJoinItem = {
|
|
782
|
+
table?: string;
|
|
783
|
+
query: {
|
|
784
|
+
as?: string;
|
|
785
|
+
};
|
|
786
|
+
} | string;
|
|
791
787
|
declare type AggregateItemOptions = {
|
|
792
788
|
as?: string;
|
|
793
789
|
distinct?: boolean;
|
|
@@ -4284,4 +4280,4 @@ declare class NotFoundError extends Error {
|
|
|
4284
4280
|
declare class MoreThanOneRowError extends Error {
|
|
4285
4281
|
}
|
|
4286
4282
|
|
|
4287
|
-
export { Adapter, AdapterOptions, AddQueryJoinedTable, AddQuerySelect, AddQueryWith, AfterCallback, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, AnyColumnType, AnyColumnTypeCreator, ArrayCardinality, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AssertArray, BaseNumberData, BaseRelation, BaseStringData, BeforeCallback, BelongsToNestedInsert, BelongsToNestedUpdate, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ClearStatement, CoalesceString, ColumnData, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnInput, ColumnNameOfModel, ColumnOperators, ColumnOutput, ColumnParser, ColumnShapeInput, ColumnShapeOutput, ColumnType, ColumnTypes, ColumnTypesBase, ColumnsObject, ColumnsParsers, ColumnsShape, CommonQueryData, DateBaseColumn, DateColumn, DateColumnData, DateTimeBaseClass, DateTimeColumnData, DateTimeWithTimeZoneBaseClass, Db, DbOptions, DbTableOptions, DecimalBaseColumn, DecimalColumn, DecimalColumnData, DeepPartial, DefaultSelectColumns, Delete, DeleteQueryData, DoublePrecisionColumn, DropMode, EMPTY_OBJECT, EmptyObject, EnumColumn, EnumLike, Except, Expression, ExpressionOfType, ExpressionOutput, FilterTuple, For, ForeignKey, ForeignKeyModel, ForeignKeyModelWithColumns, ForeignKeyOptions, From, GetArg, GetTypeOrRaw, GetTypesOrRaw, HasAndBelongsToManyRelation, HasManyNestedInsert, HasManyNestedUpdate, HasManyRelation, HasOneNestedInsert, HasOneNestedUpdate, HasOneRelation, Having, HavingArg, HavingItem, IndexColumnOptions, IndexOptions, InetColumn, Insert, InsertData, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsEqual, JSONAny, JSONArray, JSONBigInt, JSONBoolean, JSONColumn, JSONDate, JSONDiscriminatedObject, JSONDiscriminatedUnion, JSONEnum, JSONInstanceOf, JSONIntersection, JSONLazy, JSONLiteral, JSONMap, JSONNaN, JSONNativeEnum, JSONNever, JSONNotNullable, JSONNotNullish, JSONNull, JSONNullable, JSONNullish, JSONNumber, JSONObject, JSONObjectShape, JSONOptional, JSONRecord, JSONRecordKeyType, JSONRequired, JSONSet, JSONString, JSONTextColumn, JSONTuple, JSONTupleItems, JSONType, JSONTypeAny, JSONTypeData, JSONTypes, JSONUndefined, JSONUnion, JSONUnknown, JSONVoid, Join, JoinArgs, JoinCallback, JoinCallbackArg, JoinItem, JoinedTablesBase, Json, JsonItem, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MaybeArray, Merge, MoneyColumn, MoreThanOneRowError, NestedInsertItem, NestedInsertManyItems, NestedInsertOneItem, NestedUpdateItem, NestedUpdateManyItems, NestedUpdateOneItem, NotFoundError, NullableColumn, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, NumberExpression, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OptionalKeys, OrderArg, OrderItem, OutputTypeOfTuple, OutputTypeOfTupleWithRest, OwnTypeProps, PathColumn, PointColumn, PolygonColumn, Primitive, PropertyKeyUnionToArray, Query, QueryArraysResult, QueryBase, QueryCallbacks, QueryData, QueryGet, QueryInput, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryResultRow, QueryReturnType, QuerySelectAll, QueryUpsert, QueryWithTable, RawExpression, RealColumn, Relation, RelationQuery, RelationQueryBase, RelationsBase, Select, SelectAgg, SelectArg, SelectFunctionItem, SelectItem, SelectQueryData, Selectable, SelectableBase, SerialColumn, SetOptional, SetQueryJoinedTables, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumnInfo, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWindows, SetQueryWith, SimpleSpread, SingleColumnIndexOptions, SmallIntColumn, SmallSerialColumn, SortDir, Spread, Sql, StringColumn, StringExpression, StringKey, TableData, TableSchema, TextBaseColumn, TextColumn, TextColumnData, Then, ThenResult, TimeColumn, TimeInterval, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, Transaction, TransactionAdapter, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, Union, UnionArg, UnionItem, UnionToArray, UnionToIntersection, UnionToOvlds, UnknownKeysParam, Update, UpdateData, UpdateQueryData, UpsertData, UpsertResult, UpsertThis, ValidationContext, VarCharColumn, Where, WhereArg, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereOnItem, WhereQueryBuilder, WhereResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowFunctionOptions, WindowItem, With, WithDataBase, WithDataItem, WithItem, WithOptions, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addQuestionMarks, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, baseObjectOutputType, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, flatten, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getTableData, getValidEnumValues, getValueKey, handleResult, identity, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryKeysOfNotSimpleQuery, queryMethodByReturnType, quote, raw, record, relationQueryKey, removeFromQuery, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, tuple, union };
|
|
4283
|
+
export { Adapter, AdapterOptions, AddQueryJoinedTable, AddQuerySelect, AddQueryWith, AfterCallback, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, AnyColumnType, AnyColumnTypeCreator, ArrayCardinality, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AssertArray, BaseNumberData, BaseRelation, BaseStringData, BeforeCallback, BelongsToNestedInsert, BelongsToNestedUpdate, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ClearStatement, CoalesceString, ColumnData, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnInput, ColumnNameOfModel, ColumnOperators, ColumnOutput, ColumnParser, ColumnShapeInput, ColumnShapeOutput, ColumnType, ColumnTypes, ColumnTypesBase, ColumnsObject, ColumnsParsers, ColumnsShape, CommonQueryData, DateBaseColumn, DateColumn, DateColumnData, DateTimeBaseClass, DateTimeColumnData, DateTimeWithTimeZoneBaseClass, Db, DbOptions, DbTableOptions, DecimalBaseColumn, DecimalColumn, DecimalColumnData, DeepPartial, DefaultSelectColumns, Delete, DeleteQueryData, DoublePrecisionColumn, DropMode, EMPTY_OBJECT, EmptyObject, EnumColumn, EnumLike, Except, Expression, ExpressionOfType, ExpressionOutput, FilterTuple, For, ForeignKey, ForeignKeyModel, ForeignKeyModelWithColumns, ForeignKeyOptions, From, GetArg, GetTypeOrRaw, GetTypesOrRaw, HasAndBelongsToManyRelation, HasManyNestedInsert, HasManyNestedUpdate, HasManyRelation, HasOneNestedInsert, HasOneNestedUpdate, HasOneRelation, Having, HavingArg, HavingItem, IndexColumnOptions, IndexOptions, InetColumn, Insert, InsertData, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsEqual, JSONAny, JSONArray, JSONBigInt, JSONBoolean, JSONColumn, JSONDate, JSONDiscriminatedObject, JSONDiscriminatedUnion, JSONEnum, JSONInstanceOf, JSONIntersection, JSONLazy, JSONLiteral, JSONMap, JSONNaN, JSONNativeEnum, JSONNever, JSONNotNullable, JSONNotNullish, JSONNull, JSONNullable, JSONNullish, JSONNumber, JSONObject, JSONObjectShape, JSONOptional, JSONRecord, JSONRecordKeyType, JSONRequired, JSONSet, JSONString, JSONTextColumn, JSONTuple, JSONTupleItems, JSONType, JSONTypeAny, JSONTypeData, JSONTypes, JSONUndefined, JSONUnion, JSONUnknown, JSONVoid, Join, JoinArgs, JoinCallback, JoinCallbackArg, JoinItem, JoinedTablesBase, Json, JsonItem, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MaybeArray, Merge, MoneyColumn, MoreThanOneRowError, NestedInsertItem, NestedInsertManyItems, NestedInsertOneItem, NestedUpdateItem, NestedUpdateManyItems, NestedUpdateOneItem, NotFoundError, NullableColumn, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, NumberExpression, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OptionalKeys, OrderArg, OrderItem, OutputTypeOfTuple, OutputTypeOfTupleWithRest, OwnTypeProps, PathColumn, PointColumn, PolygonColumn, Primitive, PropertyKeyUnionToArray, Query, QueryArraysResult, QueryBase, QueryCallbacks, QueryData, QueryGet, QueryInput, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryResultRow, QueryReturnType, QuerySelectAll, QueryUpsert, QueryWithTable, RawExpression, RealColumn, Relation, RelationQuery, RelationQueryBase, RelationsBase, Select, SelectAgg, SelectArg, SelectFunctionItem, SelectItem, SelectQueryData, Selectable, SelectableBase, SerialColumn, SetOptional, SetQueryJoinedTables, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumnInfo, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWindows, SetQueryWith, SimpleSpread, SingleColumnIndexOptions, SmallIntColumn, SmallSerialColumn, SortDir, Spread, Sql, StringColumn, StringExpression, StringKey, TableData, TableSchema, TextBaseColumn, TextColumn, TextColumnData, Then, ThenResult, TimeColumn, TimeInterval, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, Transaction, TransactionAdapter, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, Union, UnionArg, UnionItem, UnionToArray, UnionToIntersection, UnionToOvlds, UnknownKeysParam, Update, UpdateData, UpdateQueryData, UpsertData, UpsertResult, UpsertThis, ValidationContext, VarCharColumn, Where, WhereArg, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowFunctionOptions, WindowItem, With, WithDataBase, WithDataItem, WithItem, WithOptions, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addQuestionMarks, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, baseObjectOutputType, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, flatten, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getTableData, getValidEnumValues, getValueKey, handleResult, identity, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryKeysOfNotSimpleQuery, queryMethodByReturnType, quote, raw, record, relationQueryKey, removeFromQuery, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, tuple, union };
|
package/dist/index.esm.js
CHANGED
|
@@ -2001,21 +2001,28 @@ const processJoinItem = (model, query, values, args, quotedAs) => {
|
|
|
2001
2001
|
const [first] = args;
|
|
2002
2002
|
if (typeof first === "string") {
|
|
2003
2003
|
if (first in model.relations) {
|
|
2004
|
-
const {
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2004
|
+
const {
|
|
2005
|
+
key,
|
|
2006
|
+
query: toQuery,
|
|
2007
|
+
joinQuery: joinQuery2
|
|
2008
|
+
} = model.relations[first];
|
|
2009
|
+
const joinedQuery = joinQuery2(model, toQuery);
|
|
2010
|
+
const joinedQueryData = joinedQuery.query;
|
|
2011
|
+
const table = typeof joinedQueryData.from === "string" ? joinedQueryData.from : joinedQuery.table;
|
|
2012
|
+
let target3 = quoteSchemaAndTable(joinedQueryData.schema, table);
|
|
2013
|
+
const as = joinedQueryData.as || key;
|
|
2008
2014
|
if (as !== table) {
|
|
2009
2015
|
target3 += ` AS ${q(as)}`;
|
|
2010
2016
|
}
|
|
2011
2017
|
const queryData = {
|
|
2018
|
+
as: joinedQuery.query.as,
|
|
2012
2019
|
and: [],
|
|
2013
2020
|
or: []
|
|
2014
2021
|
};
|
|
2015
|
-
if (
|
|
2016
|
-
queryData.and.push(...
|
|
2017
|
-
if (
|
|
2018
|
-
queryData.or.push(...
|
|
2022
|
+
if (joinedQueryData.and)
|
|
2023
|
+
queryData.and.push(...joinedQueryData.and);
|
|
2024
|
+
if (joinedQueryData.or)
|
|
2025
|
+
queryData.or.push(...joinedQueryData.or);
|
|
2019
2026
|
const arg = (_a = args[1]) == null ? void 0 : _a.call(
|
|
2020
2027
|
args,
|
|
2021
2028
|
new model.onQueryBuilder({ table: model.table, query }, args[0])
|
|
@@ -2028,7 +2035,7 @@ const processJoinItem = (model, query, values, args, quotedAs) => {
|
|
|
2028
2035
|
}
|
|
2029
2036
|
const joinAs2 = q(as);
|
|
2030
2037
|
const onConditions = whereToSql(
|
|
2031
|
-
|
|
2038
|
+
joinedQuery,
|
|
2032
2039
|
queryData,
|
|
2033
2040
|
values,
|
|
2034
2041
|
quotedAs,
|
|
@@ -2324,9 +2331,9 @@ const whereHandlers = {
|
|
|
2324
2331
|
const item = value;
|
|
2325
2332
|
const leftColumn = quoteFullColumn(
|
|
2326
2333
|
item.on[0],
|
|
2327
|
-
|
|
2334
|
+
getJoinItemSource(item.joinTo)
|
|
2328
2335
|
);
|
|
2329
|
-
const joinTo =
|
|
2336
|
+
const joinTo = getJoinItemSource(item.joinFrom);
|
|
2330
2337
|
const [op, rightColumn] = item.on.length === 2 ? ["=", quoteFullColumn(item.on[1], joinTo)] : [item.on[1], quoteFullColumn(item.on[2], joinTo)];
|
|
2331
2338
|
ands.push(`${prefix}${leftColumn} ${op} ${rightColumn}`);
|
|
2332
2339
|
}
|
|
@@ -2352,6 +2359,9 @@ const whereHandlers = {
|
|
|
2352
2359
|
});
|
|
2353
2360
|
}
|
|
2354
2361
|
};
|
|
2362
|
+
const getJoinItemSource = (joinItem) => {
|
|
2363
|
+
return typeof joinItem === "string" ? q(joinItem) : q(getQueryAs(joinItem));
|
|
2364
|
+
};
|
|
2355
2365
|
const pushIn = (ands, prefix, quotedAs, values, arg) => {
|
|
2356
2366
|
let value;
|
|
2357
2367
|
if (Array.isArray(arg.values)) {
|
|
@@ -3932,6 +3942,9 @@ class WhereQueryBuilder extends Where {
|
|
|
3932
3942
|
this.relations = {};
|
|
3933
3943
|
this.withData = {};
|
|
3934
3944
|
this.__model = this;
|
|
3945
|
+
if (tableAlias) {
|
|
3946
|
+
this.query.as = tableAlias;
|
|
3947
|
+
}
|
|
3935
3948
|
}
|
|
3936
3949
|
clone() {
|
|
3937
3950
|
const cloned = Object.create(this.__model);
|