pqb 0.7.11 → 0.7.13
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +46 -69
- package/dist/index.esm.js +307 -385
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +307 -384
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/columnSchema/index.ts +1 -0
- package/src/columnSchema/timestamps.test.ts +12 -6
- package/src/columnSchema/virtual.ts +21 -0
- package/src/common.ts +38 -5
- package/src/queryMethods/create.ts +49 -162
- package/src/queryMethods/queryMethods.test.ts +2 -2
- package/src/queryMethods/raw.test.ts +44 -1
- package/src/queryMethods/raw.ts +4 -4
- package/src/queryMethods/update.ts +37 -112
- package/src/relations.ts +2 -103
- package/src/sql/insert.ts +3 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ declare type AliasOrTable<T extends Pick<Query, 'tableAlias' | 'table'>> = T['ta
|
|
|
4
4
|
declare type StringKey<K extends PropertyKey> = Exclude<K, symbol | number>;
|
|
5
5
|
declare type RawExpression<C extends ColumnType = ColumnType> = {
|
|
6
6
|
__raw: string;
|
|
7
|
-
__values
|
|
7
|
+
__values?: Record<string, unknown> | false;
|
|
8
8
|
__column: C;
|
|
9
9
|
};
|
|
10
|
-
declare const raw: (sql: string,
|
|
10
|
+
declare const raw: (sql: string, values?: Record<string, unknown> | false) => RawExpression;
|
|
11
11
|
declare const isRaw: (obj: object) => obj is RawExpression<ColumnType<unknown, Operators, unknown>>;
|
|
12
|
-
declare const getRaw: (raw: RawExpression,
|
|
12
|
+
declare const getRaw: (raw: RawExpression, valuesArray: unknown[]) => string;
|
|
13
13
|
declare const getRawSql: (raw: RawExpression) => string;
|
|
14
14
|
declare type Expression<T extends Query = Query, C extends ColumnType = ColumnType> = StringKey<keyof T['selectable']> | RawExpression<C>;
|
|
15
15
|
declare type ExpressionOfType<T extends Query, C extends ColumnType, Type> = {
|
|
@@ -22,60 +22,6 @@ declare type ExpressionOutput<T extends Query, Expr extends Expression<T>> = Exp
|
|
|
22
22
|
declare const EMPTY_OBJECT: {};
|
|
23
23
|
declare const getQueryParsers: (q: Query) => ColumnsParsers | undefined;
|
|
24
24
|
|
|
25
|
-
declare type NestedInsertOneItem = {
|
|
26
|
-
create?: Record<string, unknown>;
|
|
27
|
-
connect?: WhereArg<QueryBase>;
|
|
28
|
-
connectOrCreate?: {
|
|
29
|
-
where: WhereArg<QueryBase>;
|
|
30
|
-
create: Record<string, unknown>;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
declare type NestedInsertManyItems = {
|
|
34
|
-
create?: Record<string, unknown>[];
|
|
35
|
-
connect?: WhereArg<QueryBase>[];
|
|
36
|
-
connectOrCreate?: {
|
|
37
|
-
where: WhereArg<QueryBase>;
|
|
38
|
-
create: Record<string, unknown>;
|
|
39
|
-
}[];
|
|
40
|
-
};
|
|
41
|
-
declare type NestedInsertItem = NestedInsertOneItem | NestedInsertManyItems;
|
|
42
|
-
declare type BelongsToNestedInsert = (query: Query, relationData: NestedInsertOneItem[]) => Promise<Record<string, unknown>[]>;
|
|
43
|
-
declare type HasOneNestedInsert = (query: Query, data: [
|
|
44
|
-
selfData: Record<string, unknown>,
|
|
45
|
-
relationData: NestedInsertOneItem
|
|
46
|
-
][]) => Promise<void>;
|
|
47
|
-
declare type HasManyNestedInsert = (query: Query, data: [
|
|
48
|
-
selfData: Record<string, unknown>,
|
|
49
|
-
relationData: NestedInsertManyItems
|
|
50
|
-
][]) => Promise<void>;
|
|
51
|
-
declare type NestedUpdateOneItem = {
|
|
52
|
-
disconnect?: boolean;
|
|
53
|
-
set?: WhereArg<QueryBase>;
|
|
54
|
-
delete?: boolean;
|
|
55
|
-
update?: UpdateData<Query>;
|
|
56
|
-
upsert?: {
|
|
57
|
-
update: UpdateData<Query>;
|
|
58
|
-
create: Record<string, unknown>;
|
|
59
|
-
};
|
|
60
|
-
create: Record<string, unknown>;
|
|
61
|
-
};
|
|
62
|
-
declare type NestedUpdateManyItems = {
|
|
63
|
-
disconnect?: MaybeArray<WhereArg<QueryBase>>;
|
|
64
|
-
set?: MaybeArray<WhereArg<QueryBase>>;
|
|
65
|
-
delete?: MaybeArray<WhereArg<QueryBase>>;
|
|
66
|
-
update?: {
|
|
67
|
-
where: MaybeArray<WhereArg<QueryBase>>;
|
|
68
|
-
data: UpdateData<Query>;
|
|
69
|
-
};
|
|
70
|
-
create: Record<string, unknown>[];
|
|
71
|
-
};
|
|
72
|
-
declare type NestedUpdateItem = NestedUpdateOneItem | NestedUpdateManyItems;
|
|
73
|
-
declare type BelongsToNestedUpdate = (q: Query, update: Record<string, unknown>, params: NestedUpdateOneItem, state: {
|
|
74
|
-
updateLater?: Record<string, unknown>;
|
|
75
|
-
updateLaterPromises?: Promise<void>[];
|
|
76
|
-
}) => boolean;
|
|
77
|
-
declare type HasOneNestedUpdate = (query: Query, data: Record<string, unknown>[], relationData: NestedUpdateOneItem) => Promise<void>;
|
|
78
|
-
declare type HasManyNestedUpdate = (query: Query, data: Record<string, unknown>[], relationData: NestedUpdateManyItems) => Promise<void>;
|
|
79
25
|
declare type BaseRelation = {
|
|
80
26
|
type: string;
|
|
81
27
|
key: string;
|
|
@@ -83,8 +29,6 @@ declare type BaseRelation = {
|
|
|
83
29
|
query: QueryWithTable;
|
|
84
30
|
joinQuery(fromQuery: QueryBase, toQuery: Query): Query;
|
|
85
31
|
nestedCreateQuery: Query;
|
|
86
|
-
nestedInsert?: BelongsToNestedInsert | HasOneNestedInsert | HasManyNestedInsert;
|
|
87
|
-
nestedUpdate?: BelongsToNestedUpdate | HasOneNestedUpdate | HasManyNestedUpdate;
|
|
88
32
|
primaryKey: string;
|
|
89
33
|
options: {
|
|
90
34
|
scope?(q: QueryWithTable): QueryWithTable;
|
|
@@ -1092,6 +1036,12 @@ declare type CreateRawData = {
|
|
|
1092
1036
|
values: RawExpression;
|
|
1093
1037
|
};
|
|
1094
1038
|
declare type OnConflictArg<T extends Query> = keyof T['shape'] | (keyof T['shape'])[] | RawExpression;
|
|
1039
|
+
declare type CreateCtx = {
|
|
1040
|
+
requiredReturning: Record<string, boolean>;
|
|
1041
|
+
columns: Map<string, number>;
|
|
1042
|
+
returnTypeAll?: true;
|
|
1043
|
+
resultAll: Record<string, unknown>[];
|
|
1044
|
+
};
|
|
1095
1045
|
declare type CreateMethodsNames = 'create' | '_create' | 'createMany' | '_createMany' | 'createRaw' | '_createRaw' | 'createFrom' | '_createFrom';
|
|
1096
1046
|
declare class Create {
|
|
1097
1047
|
create<T extends Query>(this: T, data: CreateData<T>): CreateResult<T>;
|
|
@@ -1187,6 +1137,13 @@ declare type UpdateArg<T extends Query> = T['hasWhere'] extends true ? UpdateDat
|
|
|
1187
1137
|
declare type UpdateRawArg<T extends Query> = T['hasWhere'] extends true ? RawExpression : never;
|
|
1188
1138
|
declare type UpdateResult<T extends Query> = T['hasSelect'] extends true ? T : SetQueryReturnsRowCount<T>;
|
|
1189
1139
|
declare type ChangeCountArg<T extends Query> = keyof T['shape'] | Partial<Record<keyof T['shape'], number>>;
|
|
1140
|
+
declare type UpdateCtx = {
|
|
1141
|
+
willSetKeys?: true;
|
|
1142
|
+
updateLater?: Record<string, unknown>;
|
|
1143
|
+
updateLaterPromises?: Promise<void>[];
|
|
1144
|
+
returnTypeAll?: true;
|
|
1145
|
+
resultAll: Record<string, unknown>[];
|
|
1146
|
+
};
|
|
1190
1147
|
declare class Update {
|
|
1191
1148
|
update<T extends Query>(this: T, arg: UpdateArg<T>): UpdateResult<T>;
|
|
1192
1149
|
_update<T extends Query>(this: T, arg: UpdateArg<T>): UpdateResult<T>;
|
|
@@ -1356,7 +1313,7 @@ declare class MergeQueryMethods {
|
|
|
1356
1313
|
_merge<T extends Query, Q extends Query>(this: T, q: Q): MergeQuery<T, Q>;
|
|
1357
1314
|
}
|
|
1358
1315
|
|
|
1359
|
-
declare type RawArgs<CT extends ColumnTypesBase, C extends ColumnType> = [column: (types: CT) => C, sql: string,
|
|
1316
|
+
declare type RawArgs<CT extends ColumnTypesBase, C extends ColumnType> = [column: (types: CT) => C, sql: string, values?: Record<string, unknown>] | [sql: string, values?: Record<string, unknown>];
|
|
1360
1317
|
declare class RawMethods {
|
|
1361
1318
|
raw<T extends Query, C extends ColumnType>(this: T, ...args: RawArgs<T['columnTypes'], C>): RawExpression<C>;
|
|
1362
1319
|
}
|
|
@@ -1900,11 +1857,11 @@ declare const Operators: {
|
|
|
1900
1857
|
not: Fn<unknown> & {
|
|
1901
1858
|
type: unknown;
|
|
1902
1859
|
};
|
|
1903
|
-
in: Fn<Query |
|
|
1904
|
-
type: Query |
|
|
1860
|
+
in: Fn<Query | RawExpression<ColumnType<unknown, Operators, unknown>> | unknown[]> & {
|
|
1861
|
+
type: Query | RawExpression<ColumnType<unknown, Operators, unknown>> | unknown[];
|
|
1905
1862
|
};
|
|
1906
|
-
notIn: Fn<Query |
|
|
1907
|
-
type: Query |
|
|
1863
|
+
notIn: Fn<Query | RawExpression<ColumnType<unknown, Operators, unknown>> | unknown[]> & {
|
|
1864
|
+
type: Query | RawExpression<ColumnType<unknown, Operators, unknown>> | unknown[];
|
|
1908
1865
|
};
|
|
1909
1866
|
};
|
|
1910
1867
|
array: {
|
|
@@ -4195,11 +4152,11 @@ declare class JSONColumn<Type extends JSONTypeAny = JSONTypeAny> extends ColumnT
|
|
|
4195
4152
|
not: ((key: string, value: unknown, values: unknown[]) => string) & {
|
|
4196
4153
|
type: unknown;
|
|
4197
4154
|
};
|
|
4198
|
-
in: ((key: string, value: Query |
|
|
4199
|
-
type: Query |
|
|
4155
|
+
in: ((key: string, value: Query | RawExpression<ColumnType<unknown, Operators, unknown>> | unknown[], values: unknown[]) => string) & {
|
|
4156
|
+
type: Query | RawExpression<ColumnType<unknown, Operators, unknown>> | unknown[];
|
|
4200
4157
|
};
|
|
4201
|
-
notIn: ((key: string, value: Query |
|
|
4202
|
-
type: Query |
|
|
4158
|
+
notIn: ((key: string, value: Query | RawExpression<ColumnType<unknown, Operators, unknown>> | unknown[], values: unknown[]) => string) & {
|
|
4159
|
+
type: Query | RawExpression<ColumnType<unknown, Operators, unknown>> | unknown[];
|
|
4203
4160
|
};
|
|
4204
4161
|
};
|
|
4205
4162
|
data: ColumnData & {
|
|
@@ -4398,6 +4355,26 @@ declare namespace utils {
|
|
|
4398
4355
|
};
|
|
4399
4356
|
}
|
|
4400
4357
|
|
|
4358
|
+
declare abstract class VirtualColumn extends ColumnType<unknown, typeof Operators.any> {
|
|
4359
|
+
dataType: string;
|
|
4360
|
+
operators: {
|
|
4361
|
+
equals: ((key: string, value: any, values: unknown[]) => string) & {
|
|
4362
|
+
type: any;
|
|
4363
|
+
};
|
|
4364
|
+
not: ((key: string, value: any, values: unknown[]) => string) & {
|
|
4365
|
+
type: any;
|
|
4366
|
+
};
|
|
4367
|
+
in: ((key: string, value: any[] | Query | RawExpression<ColumnType<unknown, Operators, unknown>>, values: unknown[]) => string) & {
|
|
4368
|
+
type: any[] | Query | RawExpression<ColumnType<unknown, Operators, unknown>>;
|
|
4369
|
+
};
|
|
4370
|
+
notIn: ((key: string, value: any[] | Query | RawExpression<ColumnType<unknown, Operators, unknown>>, values: unknown[]) => string) & {
|
|
4371
|
+
type: any[] | Query | RawExpression<ColumnType<unknown, Operators, unknown>>;
|
|
4372
|
+
};
|
|
4373
|
+
};
|
|
4374
|
+
create?(q: Query, ctx: CreateCtx, item: Record<string, unknown>, rowIndex: number): void;
|
|
4375
|
+
update?(q: Query, ctx: UpdateCtx, set: Record<string, unknown>): void;
|
|
4376
|
+
}
|
|
4377
|
+
|
|
4401
4378
|
declare type Value = any;
|
|
4402
4379
|
declare const quote: (value: Value) => string;
|
|
4403
4380
|
|
|
@@ -4411,4 +4388,4 @@ declare const setQueryObjectValue: <T extends {
|
|
|
4411
4388
|
query: QueryData;
|
|
4412
4389
|
}>(q: T, object: string, key: string, value: unknown) => T;
|
|
4413
4390
|
|
|
4414
|
-
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,
|
|
4391
|
+
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, 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, CopyOptions, CopyQueryData, Create, CreateCtx, CreateData, CreateMethodsNames, DateBaseColumn, DateColumn, DateColumnData, DateTimeBaseClass, DateTimeColumnData, DateTimeWithTimeZoneBaseClass, Db, DbOptions, DbTableOptions, DecimalBaseColumn, DecimalColumn, DecimalColumnData, DeepPartial, DefaultSelectColumns, Delete, DeleteMethodsNames, DeleteQueryData, DoublePrecisionColumn, DropMode, EMPTY_OBJECT, EmptyObject, EnumColumn, EnumLike, Except, Expression, ExpressionOfType, ExpressionOutput, FilterTuple, For, ForeignKey, ForeignKeyModel, ForeignKeyModelWithColumns, ForeignKeyOptions, From, GetArg, HasAndBelongsToManyRelation, HasManyRelation, HasOneRelation, Having, HavingArg, HavingItem, IndexColumnOptions, IndexOptions, InetColumn, 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, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NullableColumn, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, NumberExpression, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OrderArg, OrderItem, OutputTypeOfTuple, OutputTypeOfTupleWithRest, OwnTypeProps, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, Primitive, Query, QueryArraysResult, QueryBase, QueryCallbacks, QueryData, QueryError, QueryErrorName, QueryGet, QueryInput, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryResultRow, QueryReturnType, QueryReturnsAll, QuerySelectAll, QueryThen, QueryUpsert, QueryWithTable, RawExpression, RawMethods, RealColumn, Relation, RelationQuery, RelationQueryBase, RelationQueryData, 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, SinglePrimaryKey, SmallIntColumn, SmallSerialColumn, SomeIsTrue, SortDir, Spread, Sql, StringColumn, StringExpression, StringKey, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, ThenResult, TimeColumn, TimeInterval, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, ToSqlCtx, ToSqlOptions, Transaction, TransactionAdapter, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnionKind, UnknownKeysParam, Update, UpdateCtx, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, UpsertData, UpsertResult, UpsertThis, ValidationContext, VarCharColumn, VirtualColumn, 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, anyShape, applyMixins, array, arrayToEnum, baseObjectOutputType, checkIfASimpleQuery, cloneQueryArrays, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, flatten, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, identity, instanceOf, intersection, isQueryReturnsAll, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, makeSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
|