pqb 0.11.28 → 0.11.30
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 +86 -32
- package/dist/index.js +742 -689
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +743 -688
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as orchid_core from 'orchid-core';
|
|
2
|
-
import { Sql, QueryBaseCommon, ColumnsShapeBase, QueryInternal, QueryMetaBase, EmptyObject, RawExpression, ColumnTypeBase, MaybeArray, QueryResultRow, AdapterBase, QueryInput, StringKey, ColumnOutput, QueryThen, QueryCatch, NullableColumn, EmptyTuple, ColumnTypesBase, ColumnShapeOutput, DefaultSelectColumns, DbBase, SetOptional, Spread, CoalesceString, QueryCommon, BaseNumberData, Code, ColumnWithDefault, numberTypeMethods, BaseStringData, PrimaryKeyColumn, DateColumnData, EncodeColumn, ParseColumn,
|
|
2
|
+
import { Sql, QueryBaseCommon, ColumnsShapeBase, QueryInternal, QueryMetaBase, EmptyObject, RawExpression, ColumnTypeBase, MaybeArray, QueryResultRow, AdapterBase, QueryInput, ColumnsParsers, getValueKey, StringKey, ColumnOutput, QueryThen, QueryCatch, NullableColumn, EmptyTuple, ColumnTypesBase, ColumnShapeOutput, DefaultSelectColumns, DbBase, SetOptional, Spread, CoalesceString, QueryCommon, BaseNumberData, Code, ColumnWithDefault, numberTypeMethods, BaseStringData, PrimaryKeyColumn, DateTypeMethods, DateColumnData, EncodeColumn, ParseColumn, JSONTypeAny, record, ArrayMethodsData, arrayMethods, ForeignKeyTable, name, ColumnNameOfTable, ColumnDataBase, BaseOperators, ValidationContext, MessageParam } from 'orchid-core';
|
|
3
3
|
import { PoolConfig, Pool, PoolClient } from 'pg';
|
|
4
4
|
import { inspect } from 'util';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -474,19 +474,6 @@ declare function maybeWrappedThen(this: Query, resolve?: Resolve, reject?: Rejec
|
|
|
474
474
|
declare const parseResult: (q: Query, parsers: ColumnsParsers | undefined, returnType: QueryReturnType | undefined, result: QueryResult, isSubQuery?: boolean) => unknown;
|
|
475
475
|
declare const parseRecord: (parsers: ColumnsParsers, row: any) => any;
|
|
476
476
|
|
|
477
|
-
type GetArg<T extends QueryBase> = StringKey<keyof T['selectable']> | RawExpression;
|
|
478
|
-
type UnwrapRaw<T extends Query, Arg extends GetArg<T>> = Arg extends RawExpression ? Arg['__column'] : Exclude<Arg, RawExpression>;
|
|
479
|
-
type GetResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValue<T, UnwrapRaw<T, Arg>>;
|
|
480
|
-
type GetOptionalResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValueOptional<T, UnwrapRaw<T, Arg>>;
|
|
481
|
-
type getValueKey = typeof getValueKey;
|
|
482
|
-
declare const getValueKey: unique symbol;
|
|
483
|
-
declare class QueryGet {
|
|
484
|
-
get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
485
|
-
_get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
486
|
-
getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
487
|
-
_getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
477
|
type SelectArg<T extends QueryBase> = '*' | StringKey<keyof T['selectable']> | SelectAsArg<T>;
|
|
491
478
|
type SelectAsArg<T extends QueryBase> = Record<string, SelectAsValue<T>>;
|
|
492
479
|
type SelectAsValue<T extends QueryBase> = StringKey<keyof T['selectable']> | RawExpression | ((q: T) => Query) | ((q: T) => RawExpression) | ((q: T) => Query | RawExpression);
|
|
@@ -528,12 +515,83 @@ type SelectSubQueryResult<Arg extends Query & {
|
|
|
528
515
|
}> = QueryReturnsAll<Arg['returnType']> extends true ? ArrayOfColumnsObjects<Arg['result']> : Arg['returnType'] extends 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? PluckResultColumnType<Arg['result']['pluck']> : Arg[isRequiredRelationKey] extends true ? ColumnsObject<Arg['result']> : NullableColumn<ColumnsObject<Arg['result']>>;
|
|
529
516
|
declare const addParserForRawExpression: (q: Query, key: string | getValueKey, raw: RawExpression) => void;
|
|
530
517
|
declare const addParserForSelectItem: <T extends Query>(q: T, as: string | getValueKey | undefined, key: string, arg: RawExpression | Query | StringKey<keyof T["selectable"]>) => string | RawExpression | Query;
|
|
531
|
-
declare const addParserToQuery: (query: QueryData, key: string | getValueKey, parser: ColumnParser) => void;
|
|
532
518
|
declare const processSelectArg: <T extends Query>(q: T, as: string | undefined, arg: SelectArg<T>, columnAs?: string | getValueKey) => SelectItem;
|
|
533
519
|
declare const getShapeFromSelect: (q: QueryBase, isSubQuery?: boolean) => ColumnsShapeBase;
|
|
534
520
|
declare class Select {
|
|
521
|
+
/**
|
|
522
|
+
* Takes a list of columns to be selected, and by default, the query builder will select all columns of the table.
|
|
523
|
+
*
|
|
524
|
+
* Pass an object to select columns with aliases. Keys of the object are column aliases, value can be a column name, sub-query, or raw expression.
|
|
525
|
+
*
|
|
526
|
+
* ```ts
|
|
527
|
+
* // select columns of the table:
|
|
528
|
+
* db.table.select('id', 'name', { idAlias: 'id' });
|
|
529
|
+
*
|
|
530
|
+
* // accepts columns with table names:
|
|
531
|
+
* db.table.select('user.id', 'user.name', { nameAlias: 'user.name' });
|
|
532
|
+
*
|
|
533
|
+
* // table name may refer to the current table or a joined table:
|
|
534
|
+
* db.table
|
|
535
|
+
* .join(Message, 'authorId', 'id')
|
|
536
|
+
* .select('user.name', 'message.text', { textAlias: 'message.text' });
|
|
537
|
+
*
|
|
538
|
+
* // select value from the sub-query,
|
|
539
|
+
* // this sub-query should return a single record and a single column:
|
|
540
|
+
* db.table.select({
|
|
541
|
+
* subQueryResult: Otherdb.table.select('column').take(),
|
|
542
|
+
* });
|
|
543
|
+
*
|
|
544
|
+
* // select raw SQL value, the first argument of `raw` is a column type, it is used for return type of the query
|
|
545
|
+
* db.table.select({
|
|
546
|
+
* raw: db.table.sql((t) => t.integer())`1 + 2`,
|
|
547
|
+
* });
|
|
548
|
+
*
|
|
549
|
+
* // same raw SQL query as above, but raw value is returned from a callback
|
|
550
|
+
* db.table.select({
|
|
551
|
+
* raw: (q) => q.sql((t) => t.integer())`1 + 2`,
|
|
552
|
+
* });
|
|
553
|
+
* ```
|
|
554
|
+
*
|
|
555
|
+
* When you use the ORM and defined relations, `select` can also accept callbacks with related table queries:
|
|
556
|
+
*
|
|
557
|
+
* ```ts
|
|
558
|
+
* await db.author.select({
|
|
559
|
+
* allBooks: (q) => q.books,
|
|
560
|
+
* firstBook: (q) => q.books.order({ createdAt: 'ASC' }).take(),
|
|
561
|
+
* booksCount: (q) => q.books.count(),
|
|
562
|
+
* });
|
|
563
|
+
* ```
|
|
564
|
+
*
|
|
565
|
+
* When you're selecting a relation that's connected via `belongsTo` or `hasOne`, it becomes available to use in `order` or in `where`:
|
|
566
|
+
*
|
|
567
|
+
* ```ts
|
|
568
|
+
* // select books with their authors included, order by author name and filter by author column:
|
|
569
|
+
* await db.books
|
|
570
|
+
* .select({
|
|
571
|
+
* author: (q) => q.author,
|
|
572
|
+
* })
|
|
573
|
+
* .order('author.name')
|
|
574
|
+
* .where({ 'author.isPopular': true });
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
535
577
|
select<T extends Query, K extends SelectArg<T>[]>(this: T, ...args: K): SelectResult<T, K>;
|
|
536
578
|
_select<T extends Query, K extends SelectArg<T>[]>(this: T, ...args: K): SelectResult<T, K>;
|
|
579
|
+
/**
|
|
580
|
+
* When querying the table or creating records, all columns are selected by default,
|
|
581
|
+
* but updating and deleting queries are returning affected row counts by default.
|
|
582
|
+
*
|
|
583
|
+
* Use `selectAll` to select all columns. If the `.select` method was applied before it will be discarded.
|
|
584
|
+
*
|
|
585
|
+
* ```ts
|
|
586
|
+
* const selectFull = await db.table
|
|
587
|
+
* .select('id', 'name') // discarded by `selectAll`
|
|
588
|
+
* .selectAll();
|
|
589
|
+
*
|
|
590
|
+
* const updatedFull = await db.table.selectAll().where(conditions).update(data);
|
|
591
|
+
*
|
|
592
|
+
* const deletedFull = await db.table.selectAll().where(conditions).delete();
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
537
595
|
selectAll<T extends Query>(this: T): SelectResult<T, ['*']>;
|
|
538
596
|
_selectAll<T extends Query>(this: T): SelectResult<T, ['*']>;
|
|
539
597
|
}
|
|
@@ -1367,6 +1425,17 @@ declare class QueryUpsertOrCreate {
|
|
|
1367
1425
|
_orCreate<T extends UpsertThis>(this: T, data: UpsertCreateArg<T>): UpsertResult<T>;
|
|
1368
1426
|
}
|
|
1369
1427
|
|
|
1428
|
+
type GetArg<T extends QueryBase> = StringKey<keyof T['selectable']> | RawExpression;
|
|
1429
|
+
type UnwrapRaw<T extends Query, Arg extends GetArg<T>> = Arg extends RawExpression ? Arg['__column'] : Exclude<Arg, RawExpression>;
|
|
1430
|
+
type GetResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValue<T, UnwrapRaw<T, Arg>>;
|
|
1431
|
+
type GetOptionalResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValueOptional<T, UnwrapRaw<T, Arg>>;
|
|
1432
|
+
declare class QueryGet {
|
|
1433
|
+
get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
1434
|
+
_get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
1435
|
+
getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
1436
|
+
_getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1370
1439
|
type MergeQuery<T extends Query, Q extends Query, ReturnType extends QueryReturnType = QueryReturnType extends Q['returnType'] ? T['returnType'] : Q['returnType'], Data = T['meta']['hasSelect'] extends true ? GetQueryResult<ReturnType, Spread<[T['result'], Q['result']]>> : GetQueryResult<ReturnType, Q['result']>> = Omit<T, 'result' | 'returnType' | 'then' | 'catch' | 'selectable' | 'windows' | 'withData'> & {
|
|
1371
1440
|
meta: Q['meta'];
|
|
1372
1441
|
result: T['meta']['hasSelect'] extends true ? Spread<[T['result'], Q['result']]> : Q['result'];
|
|
@@ -1629,8 +1698,6 @@ declare class Aggregate {
|
|
|
1629
1698
|
_selectStringAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T, As>): SelectAgg<T, 'string_agg', As, NullableColumn<StringColumn>>;
|
|
1630
1699
|
}
|
|
1631
1700
|
|
|
1632
|
-
type ColumnParser = (input: unknown) => unknown;
|
|
1633
|
-
type ColumnsParsers = Record<string | getValueKey, ColumnParser>;
|
|
1634
1701
|
type SelectableBase = Record<PropertyKey, {
|
|
1635
1702
|
as: string;
|
|
1636
1703
|
column: ColumnTypeBase;
|
|
@@ -3110,8 +3177,7 @@ declare class CitextColumn extends TextBaseColumn {
|
|
|
3110
3177
|
toCode(t: string): Code;
|
|
3111
3178
|
}
|
|
3112
3179
|
|
|
3113
|
-
|
|
3114
|
-
interface DateBaseColumn extends ColumnType<string, typeof Operators.date, string | number | Date>, DateMethods {
|
|
3180
|
+
interface DateBaseColumn extends ColumnType<string, typeof Operators.date, string | number | Date>, DateTypeMethods {
|
|
3115
3181
|
}
|
|
3116
3182
|
declare abstract class DateBaseColumn extends ColumnType<string, typeof Operators.date, string | number | Date> {
|
|
3117
3183
|
data: DateColumnData;
|
|
@@ -3649,14 +3715,6 @@ type IndexOptions = {
|
|
|
3649
3715
|
dropMode?: 'CASCADE' | 'RESTRICT';
|
|
3650
3716
|
};
|
|
3651
3717
|
type SingleColumnIndexOptions = IndexColumnOptions & IndexOptions;
|
|
3652
|
-
type ForeignKeyTable = new () => {
|
|
3653
|
-
schema?: string;
|
|
3654
|
-
table: string;
|
|
3655
|
-
columns: {
|
|
3656
|
-
shape: ColumnsShape;
|
|
3657
|
-
};
|
|
3658
|
-
};
|
|
3659
|
-
type ColumnNameOfTable<Table extends ForeignKeyTable> = StringKey<keyof InstanceType<Table>['columns']['shape']>;
|
|
3660
3718
|
type ColumnFromDbParams = {
|
|
3661
3719
|
isNullable?: boolean;
|
|
3662
3720
|
default?: string;
|
|
@@ -3675,10 +3733,6 @@ declare abstract class ColumnType<Type = unknown, Ops extends BaseOperators = Ba
|
|
|
3675
3733
|
foreignKey<T extends ColumnType, Table extends string, Column extends string>(this: T, table: Table, column: Column, options?: ForeignKeyOptions): Omit<T, 'foreignKeyData'> & {
|
|
3676
3734
|
foreignKeyData: ForeignKey<Table, [Column]>;
|
|
3677
3735
|
};
|
|
3678
|
-
hidden<T extends ColumnType>(this: T): HiddenColumn<T>;
|
|
3679
|
-
encode<T extends ColumnType, Input>(this: T, fn: (input: Input) => unknown): EncodeColumn<T, Input>;
|
|
3680
|
-
parse<T extends ColumnType, Output>(this: T, fn: (input: T['type']) => Output): ParseColumn<T, Output>;
|
|
3681
|
-
as<T extends ColumnType, C extends ColumnType<T['type'], BaseOperators, T['inputType']>>(this: T, column: C): C;
|
|
3682
3736
|
toSQL(): string;
|
|
3683
3737
|
index<T extends ColumnType>(this: T, options?: Omit<SingleColumnIndexOptions, 'column'>): T;
|
|
3684
3738
|
unique<T extends ColumnType>(this: T, options?: Omit<SingleColumnIndexOptions, 'column' | 'unique'>): T;
|
|
@@ -3777,4 +3831,4 @@ declare const testTransaction: {
|
|
|
3777
3831
|
close(arg: Arg): Promise<void>;
|
|
3778
3832
|
};
|
|
3779
3833
|
|
|
3780
|
-
export { Adapter, AdapterConfig, AdapterOptions, AddQuerySelect, AddQueryWith, AfterHook, AfterHookKey, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, ArrayColumn, ArrayData, ArrayOfColumnsObjects, BaseRelation, BeforeHook, BeforeHookKey, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, ColumnData, ColumnFromDbParams, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData,
|
|
3834
|
+
export { Adapter, AdapterConfig, AdapterOptions, AddQuerySelect, AddQueryWith, AfterHook, AfterHookKey, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, ArrayColumn, ArrayData, ArrayOfColumnsObjects, BaseRelation, BeforeHook, BeforeHookKey, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, ColumnData, ColumnFromDbParams, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnOperators, ColumnType, ColumnTypes, ColumnsObject, ColumnsShape, CommonQueryData, CopyOptions, CopyQueryData, Create, CreateCtx, CreateData, CreateMethodsNames, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DbOptions, DbResult, DbTableOptions, DecimalBaseColumn, DecimalColumn, DefaultColumnTypes, Delete, DeleteMethodsNames, DeleteQueryData, DomainColumn, DoublePrecisionColumn, DropMode, EnumColumn, Expression, ExpressionOfType, ExpressionOutput, For, ForeignKey, ForeignKeyAction, ForeignKeyMatch, ForeignKeyOptions, From, FromArgs, FromResult, GetArg, GetQueryResult, HasAndBelongsToManyRelation, HasManyRelation, HasOneRelation, Having, HavingArg, HavingArgs, HavingItem, IdentityColumn, IndexColumnOptions, IndexOptions, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, JSONTypes, Join, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinLateralCallback, JoinLateralItem, JoinLateralResult, JoinResult, JoinedParsers, JoinedShapes, Json, JsonItem, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, NumberExpression, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operators, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgs, OrderItem, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, Query, QueryArraysResult, QueryBase, QueryData, QueryError, QueryErrorName, QueryGet, QueryHooks, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryReturnType, QueryReturnsAll, QueryUpsertOrCreate, QueryWithTable, RawSqlMethods, RealColumn, Relation, RelationQuery, RelationQueryBase, RelationQueryData, RelationsBase, Select, SelectAgg, SelectArg, SelectFunctionItem, SelectItem, SelectQueryData, Selectable, SelectableBase, SelectableFromShape, SerialColumn, SerialColumnData, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumnInfo, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWith, SimpleJoinItem, SingleColumnIndexOptions, SmallIntColumn, SmallSerialColumn, SortDir, StringColumn, StringExpression, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, TimeColumn, TimeInterval, TimestampColumn, TimestampTZColumn, ToSqlCtx, ToSqlOptions, Transaction, TransactionAdapter, TransactionOptions, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnionKind, UnknownColumn, Update, UpdateCtx, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, UpsertCreateArg, UpsertData, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, 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, addQueryHook, addQueryOn, addQueryOrOn, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, anyShape, checkIfASimpleQuery, cloneQueryArrays, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnTypes, utils as columnUtils, columnsByType, columnsShapeToCode, constraintPropsToCode, constraintToCode, createDb, foreignKeyArgumentToCode, getClonedQueryData, getColumnTypes, getConstraintKind, getQueryAs, getRaw, getShapeFromSelect, getTableData, handleResult, identityToCode, indexToCode, instantiateColumn, isQueryReturnsAll, isRequiredRelationKey, jsonTypes, logColors, logParamToLogObject, makeRegexToFindInSql, makeSql, newTableData, parseRecord, parseResult, primaryKeyToCode, processSelectArg, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, quoteString, referencesArgsToCode, relationQueryKey, resetTableData, setQueryObjectValue, simplifyColumnDefault, testTransaction, toSql, toSqlCacheKey };
|