pqb 0.4.5 → 0.4.7
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 +24 -13
- package/dist/index.esm.js +44 -33
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +44 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/columnSchema/columnTypes.test.ts +55 -53
- package/src/columnSchema/timestamps.test.ts +3 -4
- package/src/columnSchema/timestamps.ts +1 -1
- package/src/columnsOperators.test.ts +18 -19
- package/src/columnsOperators.ts +1 -1
- package/src/common.ts +17 -30
- package/src/db.ts +19 -8
- package/src/errors.test.ts +2 -4
- package/src/index.ts +1 -1
- package/src/query.ts +7 -1
- package/src/queryMethods/aggregate.test.ts +9 -7
- package/src/queryMethods/create.test.ts +5 -5
- package/src/queryMethods/create.ts +1 -1
- package/src/queryMethods/delete.ts +2 -0
- package/src/queryMethods/for.test.ts +1 -2
- package/src/queryMethods/for.ts +1 -1
- package/src/queryMethods/from.test.ts +2 -3
- package/src/queryMethods/get.test.ts +5 -5
- package/src/queryMethods/having.test.ts +6 -5
- package/src/queryMethods/index.ts +1 -0
- package/src/queryMethods/json.ts +2 -2
- package/src/queryMethods/merge.test.ts +10 -4
- package/src/queryMethods/queryMethods.test.ts +10 -12
- package/src/queryMethods/queryMethods.ts +7 -4
- package/src/queryMethods/raw.test.ts +19 -0
- package/src/queryMethods/raw.ts +27 -0
- package/src/queryMethods/select.test.ts +5 -209
- package/src/queryMethods/then.test.ts +2 -4
- package/src/queryMethods/union.test.ts +11 -6
- package/src/queryMethods/update.test.ts +3 -3
- package/src/queryMethods/where.test.ts +65 -56
- package/src/queryMethods/where.ts +1 -1
- package/src/queryMethods/with.test.ts +5 -6
- package/src/relations.ts +15 -4
- package/src/sql/common.ts +0 -1
- package/src/sql/fromAndAs.ts +1 -1
- package/src/sql/insert.ts +1 -1
- package/src/sql/join.ts +1 -1
- package/src/sql/orderBy.ts +1 -1
- package/src/sql/select.ts +1 -2
- package/src/sql/toSql.ts +1 -1
- package/src/sql/update.ts +1 -1
- package/src/sql/where.ts +1 -1
- package/src/sql/window.ts +3 -4
- package/src/sql/with.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ declare type RawExpression<C extends ColumnType = ColumnType> = {
|
|
|
7
7
|
__values: unknown[];
|
|
8
8
|
__column: C;
|
|
9
9
|
};
|
|
10
|
+
declare const raw: (sql: string, ...values: unknown[]) => RawExpression;
|
|
11
|
+
declare const isRaw: (obj: object) => obj is RawExpression<ColumnType<unknown, Operators, unknown>>;
|
|
12
|
+
declare const getRaw: (raw: RawExpression, values: unknown[]) => string;
|
|
13
|
+
declare const getRawSql: (raw: RawExpression) => string;
|
|
10
14
|
declare type Expression<T extends Query = Query, C extends ColumnType = ColumnType> = StringKey<keyof T['selectable']> | RawExpression<C>;
|
|
11
15
|
declare type ExpressionOfType<T extends Query, C extends ColumnType, Type> = {
|
|
12
16
|
[K in keyof T['selectable']]: ColumnOutput<T['selectable'][K]['column']> extends Type | null ? K : never;
|
|
@@ -15,10 +19,6 @@ declare type NumberExpression<T extends Query, C extends ColumnType = ColumnType
|
|
|
15
19
|
declare type StringExpression<T extends Query, C extends ColumnType = ColumnType> = ExpressionOfType<T, C, string>;
|
|
16
20
|
declare type BooleanExpression<T extends Query, C extends ColumnType = ColumnType> = ExpressionOfType<T, C, boolean>;
|
|
17
21
|
declare type ExpressionOutput<T extends Query, Expr extends Expression<T>> = Expr extends keyof T['selectable'] ? T['selectable'][Expr]['column'] : Expr extends RawExpression<infer ColumnType> ? ColumnType : never;
|
|
18
|
-
declare const raw: <C extends ColumnType<unknown, Operators, unknown>>(...args: [column: C, sql: string, ...values: unknown[]] | [sql: string, ...values: unknown[]]) => RawExpression<C>;
|
|
19
|
-
declare const isRaw: (obj: object) => obj is RawExpression<ColumnType<unknown, Operators, unknown>>;
|
|
20
|
-
declare const getRaw: (raw: RawExpression, values: unknown[]) => string;
|
|
21
|
-
declare const getRawSql: (raw: RawExpression) => string;
|
|
22
22
|
declare const EMPTY_OBJECT: {};
|
|
23
23
|
declare const getQueryParsers: (q: Query) => ColumnsParsers | undefined;
|
|
24
24
|
|
|
@@ -155,9 +155,11 @@ declare type PrepareRelationQuery<T extends Query, RelationName extends Property
|
|
|
155
155
|
} & {
|
|
156
156
|
[defaultsKey]: Record<Populate, true>;
|
|
157
157
|
};
|
|
158
|
-
declare type RelationQuery<Name extends PropertyKey = string, Params extends Record<string, unknown> = never, Populate extends string = never, T extends Query = Query, Required extends boolean = boolean, ChainedCreate extends boolean = false, Q extends RelationQueryBase = ChainedCreate extends true ? PrepareRelationQuery<T, Name, Required, Populate> : PrepareRelationQuery<T, Name, Required, Populate> & {
|
|
158
|
+
declare type RelationQuery<Name extends PropertyKey = string, Params extends Record<string, unknown> = never, Populate extends string = never, T extends Query = Query, Required extends boolean = boolean, ChainedCreate extends boolean = false, ChainedDelete extends boolean = false, Q extends RelationQueryBase = (ChainedCreate extends true ? PrepareRelationQuery<T, Name, Required, Populate> : PrepareRelationQuery<T, Name, Required, Populate> & {
|
|
159
159
|
[K in CreateMethodsNames]: never;
|
|
160
|
-
}
|
|
160
|
+
}) & (ChainedDelete extends true ? EmptyObject : {
|
|
161
|
+
[K in DeleteMethodsNames]: never;
|
|
162
|
+
})> = ((params: Params) => Q) & Q;
|
|
161
163
|
|
|
162
164
|
interface QueryResultRow {
|
|
163
165
|
[column: string]: any;
|
|
@@ -875,11 +877,12 @@ declare class UnhandledTypeError extends PormInternalError {
|
|
|
875
877
|
declare type DbTableOptions = {
|
|
876
878
|
schema?: string;
|
|
877
879
|
} & QueryLogOptions;
|
|
878
|
-
interface Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations']> extends QueryMethods {
|
|
879
|
-
new (adapter: Adapter, queryBuilder: Db, table?: Table, shape?: Shape, options?: DbTableOptions): this;
|
|
880
|
+
interface Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations'], CT extends ColumnTypesBase = ColumnTypesBase> extends QueryMethods {
|
|
881
|
+
new (adapter: Adapter, queryBuilder: Db<Table, Shape, Relations, CT>, table?: Table, shape?: Shape, options?: DbTableOptions): this;
|
|
880
882
|
adapter: Adapter;
|
|
881
883
|
columns: (keyof ColumnShapeOutput<Shape>)[];
|
|
882
884
|
queryBuilder: Db;
|
|
885
|
+
columnTypes: CT;
|
|
883
886
|
whereQueryBuilder: Query['whereQueryBuilder'];
|
|
884
887
|
onQueryBuilder: Query['onQueryBuilder'];
|
|
885
888
|
table: Table;
|
|
@@ -918,16 +921,17 @@ interface Db<Table extends string | undefined = undefined, Shape extends Columns
|
|
|
918
921
|
[K in keyof Shape]: Shape[K]['hasDefault'] extends true ? K : never;
|
|
919
922
|
}[keyof Shape], true>;
|
|
920
923
|
}
|
|
921
|
-
declare class Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations']> implements Query {
|
|
924
|
+
declare class Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations'], CT extends ColumnTypesBase = ColumnTypesBase> implements Query {
|
|
922
925
|
adapter: Adapter;
|
|
923
926
|
queryBuilder: Db;
|
|
924
927
|
table: Table;
|
|
925
928
|
shape: Shape;
|
|
929
|
+
columnTypes: CT;
|
|
926
930
|
whereQueryBuilder: typeof WhereQueryBuilder;
|
|
927
931
|
onQueryBuilder: typeof OnQueryBuilder;
|
|
928
|
-
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: Shape, options: DbTableOptions);
|
|
932
|
+
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: Shape, columnTypes: CT, options: DbTableOptions);
|
|
929
933
|
}
|
|
930
|
-
declare type DbResult<CT extends ColumnTypesBase> = Db & {
|
|
934
|
+
declare type DbResult<CT extends ColumnTypesBase> = Db<string, Record<string, never>, Query['relations'], CT> & {
|
|
931
935
|
<Table extends string, Shape extends ColumnsShape = ColumnsShape>(table: Table, shape?: ((t: CT) => Shape) | Shape, options?: DbTableOptions): Db<Table, Shape>;
|
|
932
936
|
adapter: Adapter;
|
|
933
937
|
close: Adapter['close'];
|
|
@@ -1204,6 +1208,7 @@ declare class Update {
|
|
|
1204
1208
|
_decrement<T extends Query>(this: T, data: ChangeCountArg<T>): UpdateResult<T>;
|
|
1205
1209
|
}
|
|
1206
1210
|
|
|
1211
|
+
declare type DeleteMethodsNames = 'del' | '_del' | 'delete' | '_delete';
|
|
1207
1212
|
declare type DeleteArgs<T extends Query> = T['hasWhere'] extends true ? [forceAll?: boolean] : [true];
|
|
1208
1213
|
declare type DeleteResult<T extends Query> = T['hasSelect'] extends true ? T : SetQueryReturnsRowCount<T>;
|
|
1209
1214
|
declare class Delete {
|
|
@@ -1310,6 +1315,11 @@ declare class MergeQueryMethods {
|
|
|
1310
1315
|
_merge<T extends Query, Q extends Query>(this: T, q: Q): MergeQuery<T, Q>;
|
|
1311
1316
|
}
|
|
1312
1317
|
|
|
1318
|
+
declare type RawArgs<CT extends ColumnTypesBase, C extends ColumnType> = [column: (types: CT) => C, sql: string, ...values: unknown[]] | [sql: string, ...values: unknown[]];
|
|
1319
|
+
declare class RawMethods {
|
|
1320
|
+
raw<T extends Query, C extends ColumnType>(this: T, ...args: RawArgs<T['columnTypes'], C>): RawExpression<C>;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1313
1323
|
declare type WindowArg<T extends Query> = Record<string, WindowArgDeclaration<T> | RawExpression>;
|
|
1314
1324
|
declare type WindowArgDeclaration<T extends Query = Query> = {
|
|
1315
1325
|
partitionBy?: Expression<T> | Expression<T>[];
|
|
@@ -1322,7 +1332,7 @@ declare type OrderArg<T extends Query> = keyof T['selectable'] | {
|
|
|
1322
1332
|
nulls: 'FIRST' | 'LAST';
|
|
1323
1333
|
};
|
|
1324
1334
|
} | RawExpression;
|
|
1325
|
-
interface QueryMethods extends Aggregate, Select, From, Join, With, Union, Json, Create, Update, Delete, Transaction, For, ColumnInfoMethods, Where, Clear, Having, Window, Then, QueryLog, QueryCallbacks, QueryUpsert, QueryGet, MergeQueryMethods {
|
|
1335
|
+
interface QueryMethods extends Aggregate, Select, From, Join, With, Union, Json, Create, Update, Delete, Transaction, For, ColumnInfoMethods, Where, Clear, Having, Window, Then, QueryLog, QueryCallbacks, QueryUpsert, QueryGet, MergeQueryMethods, RawMethods {
|
|
1326
1336
|
}
|
|
1327
1337
|
declare class QueryMethods {
|
|
1328
1338
|
windows: EmptyObject;
|
|
@@ -1539,6 +1549,7 @@ declare type defaultsKey = typeof defaultsKey;
|
|
|
1539
1549
|
declare const defaultsKey: unique symbol;
|
|
1540
1550
|
declare type Query = QueryMethods & {
|
|
1541
1551
|
queryBuilder: Db;
|
|
1552
|
+
columnTypes: ColumnTypesBase;
|
|
1542
1553
|
whereQueryBuilder: typeof WhereQueryBuilder;
|
|
1543
1554
|
onQueryBuilder: typeof OnQueryBuilder;
|
|
1544
1555
|
table?: string;
|
|
@@ -4326,4 +4337,4 @@ declare const setQueryObjectValue: <T extends {
|
|
|
4326
4337
|
query: QueryData;
|
|
4327
4338
|
}>(q: T, object: string, key: string, value: unknown) => T;
|
|
4328
4339
|
|
|
4329
|
-
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, Create, CreateData, CreateMethodsNames, 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, HasAndBelongsToManyRelation, HasManyNestedInsert, HasManyNestedUpdate, HasManyRelation, HasOneNestedInsert, HasOneNestedUpdate, 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, NestedInsertItem, NestedInsertManyItems, NestedInsertOneItem, NestedUpdateItem, NestedUpdateManyItems, NestedUpdateOneItem, 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, 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, UnknownKeysParam, Update, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, 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, checkIfASimpleQuery, 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, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, 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 };
|
|
4340
|
+
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, Create, 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, HasManyNestedInsert, HasManyNestedUpdate, HasManyRelation, HasOneNestedInsert, HasOneNestedUpdate, 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, NestedInsertItem, NestedInsertManyItems, NestedInsertOneItem, NestedUpdateItem, NestedUpdateManyItems, NestedUpdateOneItem, 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, UnknownKeysParam, Update, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, 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, checkIfASimpleQuery, 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, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, 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 };
|
package/dist/index.esm.js
CHANGED
|
@@ -115,33 +115,6 @@ class ColumnType {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
const raw = (...args) => {
|
|
119
|
-
if (typeof args[0] === "string") {
|
|
120
|
-
return {
|
|
121
|
-
__raw: args[0],
|
|
122
|
-
__values: args.slice(1)
|
|
123
|
-
};
|
|
124
|
-
} else {
|
|
125
|
-
return {
|
|
126
|
-
__column: args[0],
|
|
127
|
-
__raw: args[1],
|
|
128
|
-
__values: args.slice(2)
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
const isRaw = (obj) => "__raw" in obj;
|
|
133
|
-
const getRaw = (raw2, values) => {
|
|
134
|
-
values.push(...raw2.__values);
|
|
135
|
-
return raw2.__raw;
|
|
136
|
-
};
|
|
137
|
-
const getRawSql = (raw2) => {
|
|
138
|
-
return raw2.__raw;
|
|
139
|
-
};
|
|
140
|
-
const EMPTY_OBJECT = {};
|
|
141
|
-
const getQueryParsers = (q) => {
|
|
142
|
-
return q.query.parsers || q.columnsParsers;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
118
|
const singleQuoteRegex = /'/g;
|
|
146
119
|
const doubleQuoteRegex = /"/g;
|
|
147
120
|
const quoteValue$1 = (value) => {
|
|
@@ -180,6 +153,23 @@ const quote = (value) => {
|
|
|
180
153
|
return `'${JSON.stringify(value).replace(singleQuoteRegex, "''")}'`;
|
|
181
154
|
};
|
|
182
155
|
|
|
156
|
+
const raw = (sql, ...values) => ({
|
|
157
|
+
__raw: sql,
|
|
158
|
+
__values: values
|
|
159
|
+
});
|
|
160
|
+
const isRaw = (obj) => "__raw" in obj;
|
|
161
|
+
const getRaw = (raw2, values) => {
|
|
162
|
+
values.push(...raw2.__values);
|
|
163
|
+
return raw2.__raw;
|
|
164
|
+
};
|
|
165
|
+
const getRawSql = (raw2) => {
|
|
166
|
+
return raw2.__raw;
|
|
167
|
+
};
|
|
168
|
+
const EMPTY_OBJECT = {};
|
|
169
|
+
const getQueryParsers = (q) => {
|
|
170
|
+
return q.query.parsers || q.columnsParsers;
|
|
171
|
+
};
|
|
172
|
+
|
|
183
173
|
const q = (sql) => `"${sql}"`;
|
|
184
174
|
const qc = (column, quotedAs) => quotedAs ? `${quotedAs}.${q(column)}` : column;
|
|
185
175
|
const quoteFullColumn = (fullColumn, quotedAs) => {
|
|
@@ -4762,7 +4752,7 @@ class Json {
|
|
|
4762
4752
|
_json() {
|
|
4763
4753
|
const q = this._wrap(this.__model.clone());
|
|
4764
4754
|
q._getOptional(
|
|
4765
|
-
raw(
|
|
4755
|
+
this.raw(
|
|
4766
4756
|
queryTypeWithLimitOne[this.query.returnType] ? `row_to_json("t".*)` : `COALESCE(json_agg(row_to_json("t".*)), '[]')`
|
|
4767
4757
|
)
|
|
4768
4758
|
);
|
|
@@ -5377,6 +5367,23 @@ class QueryUpsert {
|
|
|
5377
5367
|
}
|
|
5378
5368
|
}
|
|
5379
5369
|
|
|
5370
|
+
class RawMethods {
|
|
5371
|
+
raw(...args) {
|
|
5372
|
+
if (typeof args[0] === "string") {
|
|
5373
|
+
return {
|
|
5374
|
+
__raw: args[0],
|
|
5375
|
+
__values: args.slice(1)
|
|
5376
|
+
};
|
|
5377
|
+
} else {
|
|
5378
|
+
return {
|
|
5379
|
+
__column: args[0](this.columnTypes),
|
|
5380
|
+
__raw: args[1],
|
|
5381
|
+
__values: args.slice(2)
|
|
5382
|
+
};
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
}
|
|
5386
|
+
|
|
5380
5387
|
class QueryMethods {
|
|
5381
5388
|
all() {
|
|
5382
5389
|
return this.clone()._all();
|
|
@@ -5496,7 +5503,7 @@ class QueryMethods {
|
|
|
5496
5503
|
_wrap(query, as) {
|
|
5497
5504
|
const sql = this.toSql();
|
|
5498
5505
|
return query.as(as != null ? as : "t")._from(
|
|
5499
|
-
raw(`(${sql.text})`, ...sql.values)
|
|
5506
|
+
this.raw(`(${sql.text})`, ...sql.values)
|
|
5500
5507
|
);
|
|
5501
5508
|
}
|
|
5502
5509
|
order(...args) {
|
|
@@ -5523,7 +5530,7 @@ class QueryMethods {
|
|
|
5523
5530
|
return this.clone()._exists();
|
|
5524
5531
|
}
|
|
5525
5532
|
_exists() {
|
|
5526
|
-
const q = this._getOptional(raw("true"));
|
|
5533
|
+
const q = this._getOptional(this.raw("true"));
|
|
5527
5534
|
q.query.notFoundDefault = false;
|
|
5528
5535
|
q.query.coalesceValue = false;
|
|
5529
5536
|
return q;
|
|
@@ -5566,7 +5573,8 @@ applyMixins(QueryMethods, [
|
|
|
5566
5573
|
QueryCallbacks,
|
|
5567
5574
|
QueryUpsert,
|
|
5568
5575
|
QueryGet,
|
|
5569
|
-
MergeQueryMethods
|
|
5576
|
+
MergeQueryMethods,
|
|
5577
|
+
RawMethods
|
|
5570
5578
|
]);
|
|
5571
5579
|
|
|
5572
5580
|
var __defProp = Object.defineProperty;
|
|
@@ -5598,11 +5606,12 @@ var __objRest = (source, exclude) => {
|
|
|
5598
5606
|
return target;
|
|
5599
5607
|
};
|
|
5600
5608
|
class Db {
|
|
5601
|
-
constructor(adapter, queryBuilder, table = void 0, shape = {}, options) {
|
|
5609
|
+
constructor(adapter, queryBuilder, table = void 0, shape = {}, columnTypes, options) {
|
|
5602
5610
|
this.adapter = adapter;
|
|
5603
5611
|
this.queryBuilder = queryBuilder;
|
|
5604
5612
|
this.table = table;
|
|
5605
5613
|
this.shape = shape;
|
|
5614
|
+
this.columnTypes = columnTypes;
|
|
5606
5615
|
this.whereQueryBuilder = WhereQueryBuilder;
|
|
5607
5616
|
this.onQueryBuilder = OnQueryBuilder;
|
|
5608
5617
|
this.__model = this;
|
|
@@ -5677,6 +5686,7 @@ const createDb = (_a) => {
|
|
|
5677
5686
|
void 0,
|
|
5678
5687
|
void 0,
|
|
5679
5688
|
{},
|
|
5689
|
+
ct,
|
|
5680
5690
|
commonOptions
|
|
5681
5691
|
);
|
|
5682
5692
|
qb.queryBuilder = qb;
|
|
@@ -5687,6 +5697,7 @@ const createDb = (_a) => {
|
|
|
5687
5697
|
qb,
|
|
5688
5698
|
table,
|
|
5689
5699
|
typeof shape === "function" ? getColumnTypes(ct, shape) : shape,
|
|
5700
|
+
ct,
|
|
5690
5701
|
__spreadValues(__spreadValues({}, commonOptions), options2)
|
|
5691
5702
|
);
|
|
5692
5703
|
},
|
|
@@ -5699,5 +5710,5 @@ const createDb = (_a) => {
|
|
|
5699
5710
|
return db;
|
|
5700
5711
|
};
|
|
5701
5712
|
|
|
5702
|
-
export { Adapter, Aggregate, ArrayColumn, ArrayOfColumnsObjects, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ColumnInfoMethods, ColumnType, ColumnsObject, Create, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeWithTimeZoneBaseClass, Db, DecimalBaseColumn, DecimalColumn, Delete, DoublePrecisionColumn, EMPTY_OBJECT, EnumColumn, For, From, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, Json, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnQueryBuilder, Operators, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, QueryCallbacks, QueryError, QueryGet, QueryLog, QueryMethods, QueryUpsert, RealColumn, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, Transaction, TransactionAdapter, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, Update, VarCharColumn, Where, WhereQueryBuilder, With, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, 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 };
|
|
5713
|
+
export { Adapter, Aggregate, ArrayColumn, ArrayOfColumnsObjects, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ColumnInfoMethods, ColumnType, ColumnsObject, Create, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeWithTimeZoneBaseClass, Db, DecimalBaseColumn, DecimalColumn, Delete, DoublePrecisionColumn, EMPTY_OBJECT, EnumColumn, For, From, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, Json, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnQueryBuilder, Operators, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, QueryCallbacks, QueryError, QueryGet, QueryLog, QueryMethods, QueryUpsert, RawMethods, RealColumn, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, Transaction, TransactionAdapter, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, Update, VarCharColumn, Where, WhereQueryBuilder, With, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, 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 };
|
|
5703
5714
|
//# sourceMappingURL=index.esm.js.map
|