pqb 0.28.0 → 0.29.1
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 +182 -149
- package/dist/index.js +134 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -131
- 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 { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, QueryColumn, MaybeArray, SelectableBase, TemplateLiteralArgs, PickOutputTypeAndOperators, PickQueryResult, OperatorToSQL, ColumnsShapeBase, ColumnsParsers, RecordString, PickQueryTable, getValueKey, PickQueryShape, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, PickQueryMetaShape, PickQueryTableMetaResultShape, QueryColumnBooleanOrNull, SQLQueryArgs, ColumnSchemaConfig, DateColumnData, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, StaticSQLArgs, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ParseColumn, EncodeColumn, PickQueryMetaResult, QueryColumnsInit, DefaultSelectColumns, CoreQueryScopes, DbBase, QueryCatch, TransactionState, ColumnTypeBase, PickQueryMetaResultWindows, CoreBaseOperators, PickQueryUniqueProperties, IsQuery, PickQueryMetaShapeResultReturnType, MergeObjects, PickQueryResultUniqueColumns, QueryInternalBase, PickQueryReturnType, PickType, ColumnShapeOutput, PickOutputType,
|
|
2
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, QueryColumn, MaybeArray, SelectableBase, TemplateLiteralArgs, PickOutputTypeAndOperators, PickQueryResult, OperatorToSQL, ColumnsShapeBase, ColumnsParsers, RecordString, PickQueryTable, FnUnknownToUnknown, getValueKey, PickQueryShape, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, PickQueryMetaShape, PickQueryTableMetaResultShape, QueryColumnBooleanOrNull, SQLQueryArgs, ColumnSchemaConfig, DateColumnData, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, StaticSQLArgs, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ParseColumn, EncodeColumn, PickQueryMetaResult, QueryColumnsInit, DefaultSelectColumns, CoreQueryScopes, DbBase, QueryCatch, TransactionState, ColumnTypeBase, PickQueryMetaResultWindows, CoreBaseOperators, PickQueryUniqueProperties, IsQuery, PickQueryMetaShapeResultReturnType, MergeObjects, PickQueryResultUniqueColumns, QueryInternalBase, PickQueryReturnType, PickType, ColumnShapeOutput, PickOutputType, PickQueryMetaReturnType, UniqueColumn, TimestampHelpers, Codes, ColumnDataCheckBase, PickQueryTableMetaShape } from 'orchid-core';
|
|
3
3
|
import { PoolConfig, Pool, PoolClient } from 'pg';
|
|
4
4
|
import { inspect } from 'node:util';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -290,10 +290,13 @@ interface WindowDeclaration {
|
|
|
290
290
|
}
|
|
291
291
|
type UnionItem = Query | Expression;
|
|
292
292
|
type UnionKind = 'UNION' | 'UNION ALL' | 'INTERSECT' | 'INTERSECT ALL' | 'EXCEPT' | 'EXCEPT ALL';
|
|
293
|
-
type
|
|
293
|
+
type OnConflictTarget = string | string[] | Expression | {
|
|
294
294
|
constraint: string;
|
|
295
295
|
};
|
|
296
|
-
type
|
|
296
|
+
type OnConflictSet = RecordUnknown | Expression;
|
|
297
|
+
type OnConflictMerge = string | string[] | {
|
|
298
|
+
except: string | string[];
|
|
299
|
+
};
|
|
297
300
|
|
|
298
301
|
interface Operator<Value, Column extends PickOutputTypeAndOperators = PickOutputTypeAndOperators> {
|
|
299
302
|
<T extends PickQueryResult>(this: T, arg: Value): Omit<SetQueryReturnsColumnOrThrow<T, Column>, keyof T['result']['value']['operators']> & Column['operators'];
|
|
@@ -433,7 +436,7 @@ type CommonQueryData = {
|
|
|
433
436
|
logger: QueryLogger;
|
|
434
437
|
autoPreparedStatements?: boolean;
|
|
435
438
|
[toSQLCacheKey]?: Sql;
|
|
436
|
-
transform?:
|
|
439
|
+
transform?: FnUnknownToUnknown[];
|
|
437
440
|
language?: string;
|
|
438
441
|
isSubQuery?: true;
|
|
439
442
|
relChain?: (Query | RelationQuery)[];
|
|
@@ -487,12 +490,9 @@ type InsertQueryData = CommonQueryData & {
|
|
|
487
490
|
using?: JoinItem[];
|
|
488
491
|
join?: JoinItem[];
|
|
489
492
|
onConflict?: {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
type: 'merge';
|
|
494
|
-
expr?: OnConflictItem;
|
|
495
|
-
update?: OnConflictMergeUpdate;
|
|
493
|
+
target?: OnConflictTarget;
|
|
494
|
+
set?: OnConflictSet;
|
|
495
|
+
merge?: OnConflictMerge;
|
|
496
496
|
};
|
|
497
497
|
};
|
|
498
498
|
interface UpdateQueryDataObject {
|
|
@@ -3696,33 +3696,53 @@ declare class Clear {
|
|
|
3696
3696
|
interface CreateSelf extends QueryBase {
|
|
3697
3697
|
inputType: RecordUnknown;
|
|
3698
3698
|
}
|
|
3699
|
-
type CreateData<T extends CreateSelf
|
|
3699
|
+
type CreateData<T extends CreateSelf, BelongsToData = CreateBelongsToData<T>> = RelationsBase extends T['relations'] ? CreateDataWithDefaults<T, keyof T['meta']['defaults']> : CreateRelationsData<T, BelongsToData>;
|
|
3700
3700
|
type CreateDataWithDefaults<T extends CreateSelf, Defaults extends PropertyKey> = {
|
|
3701
|
-
[K in keyof T['inputType'] as K extends Defaults ? never : K]: CreateColumn<T['inputType'], K>;
|
|
3701
|
+
[K in keyof T['inputType'] as K extends Defaults ? never : K]: K extends Defaults ? never : CreateColumn<T['inputType'], K>;
|
|
3702
3702
|
} & {
|
|
3703
3703
|
[K in Defaults]?: K extends keyof T['inputType'] ? CreateColumn<T['inputType'], K> : never;
|
|
3704
3704
|
};
|
|
3705
|
-
type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends
|
|
3706
|
-
[K in keyof T['inputType'] as K extends Defaults | OmitFKeys ? never : K]: CreateColumn<T['inputType'], K>;
|
|
3705
|
+
type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends keyof T['inputType'], OmitFKeys extends PropertyKey> = {
|
|
3706
|
+
[K in keyof T['inputType'] as K extends Defaults | OmitFKeys ? never : K]: K extends Defaults | OmitFKeys ? never : CreateColumn<T['inputType'], K>;
|
|
3707
3707
|
} & {
|
|
3708
|
-
[K in Defaults
|
|
3708
|
+
[K in Defaults as K extends OmitFKeys ? never : K]?: CreateColumn<T['inputType'], K>;
|
|
3709
3709
|
};
|
|
3710
3710
|
type CreateColumn<InputType, Key extends keyof InputType> = Expression | InputType[Key] | {
|
|
3711
3711
|
__isQuery: true;
|
|
3712
3712
|
then: QueryThen<InputType[Key]>;
|
|
3713
3713
|
};
|
|
3714
|
-
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['meta']['defaults'], T['relations'][keyof T['relations']]['relationConfig']['omitForeignKeyInCreate']> &
|
|
3714
|
+
type CreateRelationsData<T extends CreateSelf, BelongsToData> = CreateDataWithDefaultsForRelations<T, keyof T['meta']['defaults'], T['relations'][keyof T['relations']]['relationConfig']['omitForeignKeyInCreate']> & BelongsToData & T['relations'][keyof T['relations']]['relationConfig']['optionalDataForCreate'];
|
|
3715
|
+
type CreateBelongsToData<T extends CreateSelf> = CreateRelationsDataOmittingFKeys<T, T['relations'][keyof T['relations']]['relationConfig']['dataForCreate']>;
|
|
3715
3716
|
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union extends RelationConfigDataForCreate ? (u: keyof Union['columns'] extends keyof T['meta']['defaults'] ? Omit<Union['columns'], keyof T['meta']['defaults']> & {
|
|
3716
3717
|
[P in keyof T['meta']['defaults'] & keyof Union['columns']]?: Union['columns'][P];
|
|
3717
3718
|
} & Partial<Union['nested']> : Union['columns'] | Union['nested']) => void : never) extends (u: infer Obj extends RecordUnknown) => void ? Obj : never;
|
|
3718
|
-
type CreateResult<T extends CreateSelf> = T extends {
|
|
3719
|
+
type CreateResult<T extends CreateSelf, BT> = T extends {
|
|
3720
|
+
isCount: true;
|
|
3721
|
+
} ? SetQueryKind<T, 'create'> : QueryReturnsAll<T['returnType']> extends true ? SetQueryReturnsOneKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>>;
|
|
3722
|
+
type CreateRawOrFromResult<T extends CreateSelf> = T extends {
|
|
3719
3723
|
isCount: true;
|
|
3720
3724
|
} ? SetQueryKind<T, 'create'> : QueryReturnsAll<T['returnType']> extends true ? SetQueryReturnsOneKind<T, 'create'> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKind<T, 'create'> : SetQueryKind<T, 'create'>;
|
|
3721
|
-
type InsertResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? QueryReturnsAll<T['returnType']> extends true ?
|
|
3722
|
-
type
|
|
3725
|
+
type InsertResult<T extends CreateSelf, BT> = T['meta']['hasSelect'] extends true ? QueryReturnsAll<T['returnType']> extends true ? SetQueryReturnsOneKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryReturnsRowCount<T, 'create'>;
|
|
3726
|
+
type InsertRawOrFromResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? QueryReturnsAll<T['returnType']> extends true ? SetQueryReturnsOneKind<T, 'create'> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKind<T, 'create'> : SetQueryKind<T, 'create'> : SetQueryReturnsRowCount<T, 'create'>;
|
|
3727
|
+
type CreateManyResult<T extends CreateSelf, BT> = T extends {
|
|
3728
|
+
isCount: true;
|
|
3729
|
+
} ? SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>>;
|
|
3730
|
+
type CreateManyRawOrFromResult<T extends CreateSelf> = T extends {
|
|
3723
3731
|
isCount: true;
|
|
3724
3732
|
} ? SetQueryKind<T, 'create'> : T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKind<T, 'create'> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKind<T, 'create'> : SetQueryKind<T, 'create'>;
|
|
3725
|
-
type InsertManyResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ?
|
|
3733
|
+
type InsertManyResult<T extends CreateSelf, BT> = T['meta']['hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryReturnsRowCount<T, 'create'>;
|
|
3734
|
+
type InsertManyRawOrFromResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKind<T, 'create'> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKind<T, 'create'> : SetQueryKind<T, 'create'> : SetQueryReturnsRowCount<T, 'create'>;
|
|
3735
|
+
/**
|
|
3736
|
+
* When creating a record with a *belongs to* nested record,
|
|
3737
|
+
* un-nullify foreign key columns of the result.
|
|
3738
|
+
*
|
|
3739
|
+
* The same should work as well with any non-null columns passed to `create`, but it's to be implemented later.
|
|
3740
|
+
*/
|
|
3741
|
+
type NarrowCreateResult<T extends CreateSelf, BT> = [
|
|
3742
|
+
T['relations'][keyof T['relations'] & keyof BT]['relationConfig']['omitForeignKeyInCreate']
|
|
3743
|
+
] extends [never] ? T['result'] : {
|
|
3744
|
+
[K in keyof T['result']]: K extends T['relations'][keyof T['relations'] & keyof BT]['relationConfig']['omitForeignKeyInCreate'] ? QueryColumn<Exclude<T['result'][K]['type'], null>, T['result'][K]['operators']> : T['result'][K];
|
|
3745
|
+
};
|
|
3726
3746
|
type IgnoreResult<T extends CreateSelf> = T['returnType'] extends 'oneOrThrow' ? SetQueryReturnsOneOptional<T> : T['returnType'] extends 'valueOrThrow' ? SetQueryReturnsColumnOptional<T, T['result']['value']> : T;
|
|
3727
3747
|
interface CreateRawData<T extends CreateSelf> {
|
|
3728
3748
|
columns: (keyof T['shape'])[];
|
|
@@ -3757,23 +3777,23 @@ interface CreateCtx {
|
|
|
3757
3777
|
returnTypeAll?: true;
|
|
3758
3778
|
resultAll: RecordUnknown[];
|
|
3759
3779
|
}
|
|
3760
|
-
declare const _queryCreate: <T extends CreateSelf
|
|
3761
|
-
declare const _queryInsert: <T extends CreateSelf
|
|
3762
|
-
declare const _queryCreateMany: <T extends CreateSelf
|
|
3763
|
-
declare const _queryInsertMany: <T extends CreateSelf
|
|
3764
|
-
declare const _queryCreateRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateRawData<T>>) =>
|
|
3765
|
-
declare const _queryInsertRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateRawData<T>>) =>
|
|
3766
|
-
declare const _queryCreateManyRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateManyRawData<T>>) =>
|
|
3767
|
-
declare const _queryInsertManyRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateManyRawData<T>>) =>
|
|
3780
|
+
declare const _queryCreate: <T extends CreateSelf, BT extends CreateRelationsDataOmittingFKeys<T, T["relations"][keyof T["relations"]]["relationConfig"]["dataForCreate"]>>(q: T, data: CreateData<T, BT>) => CreateResult<T, BT>;
|
|
3781
|
+
declare const _queryInsert: <T extends CreateSelf, BT extends CreateRelationsDataOmittingFKeys<T, T["relations"][keyof T["relations"]]["relationConfig"]["dataForCreate"]>>(q: T, data: CreateData<T, BT>) => InsertResult<T, BT>;
|
|
3782
|
+
declare const _queryCreateMany: <T extends CreateSelf, BT extends CreateRelationsDataOmittingFKeys<T, T["relations"][keyof T["relations"]]["relationConfig"]["dataForCreate"]>>(q: T, data: CreateData<T, BT>[]) => CreateManyResult<T, BT>;
|
|
3783
|
+
declare const _queryInsertMany: <T extends CreateSelf, BT extends CreateRelationsDataOmittingFKeys<T, T["relations"][keyof T["relations"]]["relationConfig"]["dataForCreate"]>>(q: T, data: CreateData<T, BT>[]) => InsertManyResult<T, BT>;
|
|
3784
|
+
declare const _queryCreateRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateRawData<T>>) => CreateRawOrFromResult<T>;
|
|
3785
|
+
declare const _queryInsertRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateRawData<T>>) => InsertRawOrFromResult<T>;
|
|
3786
|
+
declare const _queryCreateManyRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateManyRawData<T>>) => CreateManyRawOrFromResult<T>;
|
|
3787
|
+
declare const _queryInsertManyRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateManyRawData<T>>) => InsertManyRawOrFromResult<T>;
|
|
3768
3788
|
declare const _queryCreateFrom: <T extends CreateSelf, Q extends Query & {
|
|
3769
3789
|
returnType: 'one' | 'oneOrThrow';
|
|
3770
|
-
}>(q: T, query: Q, data?: Omit<CreateData<T
|
|
3790
|
+
}>(q: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>) => CreateRawOrFromResult<T>;
|
|
3771
3791
|
declare const _queryInsertFrom: <T extends CreateSelf, Q extends Query & {
|
|
3772
3792
|
returnType: 'one' | 'oneOrThrow';
|
|
3773
|
-
}>(q: T, query: Q, data?: Omit<CreateData<T
|
|
3774
|
-
declare const _queryCreateManyFrom: <T extends CreateSelf>(q: T, query: Query) =>
|
|
3775
|
-
declare const _queryInsertManyFrom: <T extends CreateSelf>(q: T, query: Query) =>
|
|
3776
|
-
declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T
|
|
3793
|
+
}>(q: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>) => InsertRawOrFromResult<T>;
|
|
3794
|
+
declare const _queryCreateManyFrom: <T extends CreateSelf>(q: T, query: Query) => CreateManyRawOrFromResult<T>;
|
|
3795
|
+
declare const _queryInsertManyFrom: <T extends CreateSelf>(q: T, query: Query) => InsertManyRawOrFromResult<T>;
|
|
3796
|
+
declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T, CreateRelationsDataOmittingFKeys<T, T["relations"][keyof T["relations"]]["relationConfig"]["dataForCreate"]>>>>(q: T, data: Data) => AddQueryDefaults<T, { [K in keyof Data]: true; }>;
|
|
3777
3797
|
/**
|
|
3778
3798
|
* Names of all create methods,
|
|
3779
3799
|
* is used in {@link RelationQuery} to remove these methods if chained relation shouldn't have them,
|
|
@@ -3792,9 +3812,9 @@ declare class Create {
|
|
|
3792
3812
|
* password: '1234',
|
|
3793
3813
|
* });
|
|
3794
3814
|
*
|
|
3795
|
-
* // When using `.
|
|
3815
|
+
* // When using `.onConflictDoNothing()`,
|
|
3796
3816
|
* // the record may be not created and the `createdCount` will be 0.
|
|
3797
|
-
* const createdCount = await db.table.insert(data).
|
|
3817
|
+
* const createdCount = await db.table.insert(data).onConflictDoNothing();
|
|
3798
3818
|
*
|
|
3799
3819
|
* await db.table.create({
|
|
3800
3820
|
* // raw SQL
|
|
@@ -3808,13 +3828,13 @@ declare class Create {
|
|
|
3808
3828
|
*
|
|
3809
3829
|
* @param data - data for the record, may have values, raw SQL, queries, relation operations.
|
|
3810
3830
|
*/
|
|
3811
|
-
create<T extends CreateSelf
|
|
3831
|
+
create<T extends CreateSelf, BT extends CreateBelongsToData<T>>(this: T, data: CreateData<T, BT>): CreateResult<T, BT>;
|
|
3812
3832
|
/**
|
|
3813
3833
|
* Works exactly as {@link create}, except that it returns inserted row count by default.
|
|
3814
3834
|
*
|
|
3815
3835
|
* @param data - data for the record, may have values, raw SQL, queries, relation operations.
|
|
3816
3836
|
*/
|
|
3817
|
-
insert<T extends CreateSelf
|
|
3837
|
+
insert<T extends CreateSelf, BT extends CreateBelongsToData<T>>(this: T, data: CreateData<T, BT>): InsertResult<T, BT>;
|
|
3818
3838
|
/**
|
|
3819
3839
|
* `createMany` and `insertMany` will create a batch of records.
|
|
3820
3840
|
*
|
|
@@ -3834,13 +3854,13 @@ declare class Create {
|
|
|
3834
3854
|
*
|
|
3835
3855
|
* @param data - array of records data, may have values, raw SQL, queries, relation operations
|
|
3836
3856
|
*/
|
|
3837
|
-
createMany<T extends CreateSelf
|
|
3857
|
+
createMany<T extends CreateSelf, BT extends CreateBelongsToData<T>>(this: T, data: CreateData<T, BT>[]): CreateManyResult<T, BT>;
|
|
3838
3858
|
/**
|
|
3839
3859
|
* Works exactly as {@link createMany}, except that it returns inserted row count by default.
|
|
3840
3860
|
*
|
|
3841
3861
|
* @param data - array of records data, may have values, raw SQL, queries, relation operations
|
|
3842
3862
|
*/
|
|
3843
|
-
insertMany<T extends CreateSelf
|
|
3863
|
+
insertMany<T extends CreateSelf, BT extends CreateBelongsToData<T>>(this: T, data: CreateData<T, BT>[]): InsertManyResult<T, BT>;
|
|
3844
3864
|
/**
|
|
3845
3865
|
* `createRaw` and `insertRaw` are for creating one record with a raw SQL expression.
|
|
3846
3866
|
*
|
|
@@ -3859,13 +3879,13 @@ declare class Create {
|
|
|
3859
3879
|
*
|
|
3860
3880
|
* @param args - object with columns list and raw SQL for values
|
|
3861
3881
|
*/
|
|
3862
|
-
createRaw<T extends CreateSelf>(this: T, ...args: CreateRawArgs<T, CreateRawData<T>>):
|
|
3882
|
+
createRaw<T extends CreateSelf>(this: T, ...args: CreateRawArgs<T, CreateRawData<T>>): CreateRawOrFromResult<T>;
|
|
3863
3883
|
/**
|
|
3864
3884
|
* Works exactly as {@link createRaw}, except that it returns inserted row count by default.
|
|
3865
3885
|
*
|
|
3866
3886
|
* @param args - object with columns list and raw SQL for values
|
|
3867
3887
|
*/
|
|
3868
|
-
insertRaw<T extends CreateSelf>(this: T, ...args: CreateRawArgs<T, CreateRawData<T>>):
|
|
3888
|
+
insertRaw<T extends CreateSelf>(this: T, ...args: CreateRawArgs<T, CreateRawData<T>>): InsertRawOrFromResult<T>;
|
|
3869
3889
|
/**
|
|
3870
3890
|
* `createManyRaw` and `insertManyRaw` are for creating many record with raw SQL expressions.
|
|
3871
3891
|
*
|
|
@@ -3884,13 +3904,13 @@ declare class Create {
|
|
|
3884
3904
|
*
|
|
3885
3905
|
* @param args - object with columns list and array of raw SQL for values
|
|
3886
3906
|
*/
|
|
3887
|
-
createManyRaw<T extends CreateSelf>(this: T, ...args: CreateRawArgs<T, CreateManyRawData<T>>):
|
|
3907
|
+
createManyRaw<T extends CreateSelf>(this: T, ...args: CreateRawArgs<T, CreateManyRawData<T>>): CreateManyRawOrFromResult<T>;
|
|
3888
3908
|
/**
|
|
3889
3909
|
* Works exactly as {@link createManyRaw}, except that it returns inserted row count by default.
|
|
3890
3910
|
*
|
|
3891
3911
|
* @param args - object with columns list and array of raw SQL for values
|
|
3892
3912
|
*/
|
|
3893
|
-
insertManyRaw<T extends CreateSelf>(this: T, ...args: CreateRawArgs<T, CreateManyRawData<T>>):
|
|
3913
|
+
insertManyRaw<T extends CreateSelf>(this: T, ...args: CreateRawArgs<T, CreateManyRawData<T>>): InsertManyRawOrFromResult<T>;
|
|
3894
3914
|
/**
|
|
3895
3915
|
* These methods are for creating a single record, for batch creating see {@link createManyFrom}.
|
|
3896
3916
|
*
|
|
@@ -3932,7 +3952,7 @@ declare class Create {
|
|
|
3932
3952
|
*/
|
|
3933
3953
|
createFrom<T extends CreateSelf, Q extends Query & {
|
|
3934
3954
|
returnType: 'one' | 'oneOrThrow';
|
|
3935
|
-
}>(this: T, query: Q, data?: Omit<CreateData<T
|
|
3955
|
+
}>(this: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>): CreateRawOrFromResult<T>;
|
|
3936
3956
|
/**
|
|
3937
3957
|
* Works exactly as {@link createFrom}, except that it returns inserted row count by default.
|
|
3938
3958
|
*
|
|
@@ -3941,7 +3961,7 @@ declare class Create {
|
|
|
3941
3961
|
*/
|
|
3942
3962
|
insertFrom<T extends CreateSelf, Q extends Query & {
|
|
3943
3963
|
returnType: 'one' | 'oneOrThrow';
|
|
3944
|
-
}>(this: T, query: Q, data?: Omit<CreateData<T
|
|
3964
|
+
}>(this: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>): InsertRawOrFromResult<T>;
|
|
3945
3965
|
/**
|
|
3946
3966
|
* Similar to `createFrom`, but intended to create many records.
|
|
3947
3967
|
*
|
|
@@ -3955,19 +3975,19 @@ declare class Create {
|
|
|
3955
3975
|
*
|
|
3956
3976
|
* @param query - query to create new records from
|
|
3957
3977
|
*/
|
|
3958
|
-
createManyFrom<T extends CreateSelf>(this: T, query: Query):
|
|
3978
|
+
createManyFrom<T extends CreateSelf>(this: T, query: Query): CreateManyRawOrFromResult<T>;
|
|
3959
3979
|
/**
|
|
3960
3980
|
* Works exactly as {@link createManyFrom}, except that it returns inserted row count by default.
|
|
3961
3981
|
*
|
|
3962
3982
|
* @param query - query to create new records from
|
|
3963
3983
|
*/
|
|
3964
|
-
insertManyFrom<T extends CreateSelf>(this: T, query: Query):
|
|
3984
|
+
insertManyFrom<T extends CreateSelf>(this: T, query: Query): InsertManyRawOrFromResult<T>;
|
|
3965
3985
|
/**
|
|
3966
3986
|
* `defaults` allows setting values that will be used later in `create`.
|
|
3967
3987
|
*
|
|
3968
3988
|
* Columns provided in `defaults` are marked as optional in the following `create`.
|
|
3969
3989
|
*
|
|
3970
|
-
* Default data is the same as in
|
|
3990
|
+
* Default data is the same as in {@link create} and {@link createMany},
|
|
3971
3991
|
* so you can provide a raw SQL, or a query with a query.
|
|
3972
3992
|
*
|
|
3973
3993
|
* ```ts
|
|
@@ -3984,7 +4004,7 @@ declare class Create {
|
|
|
3984
4004
|
*
|
|
3985
4005
|
* @param data - default values for `create` and `createMany` which will follow `defaults`
|
|
3986
4006
|
*/
|
|
3987
|
-
defaults<T extends CreateSelf, Data extends Partial<CreateData<T
|
|
4007
|
+
defaults<T extends CreateSelf, Data extends Partial<CreateData<T, CreateBelongsToData<T>>>>(this: T, data: Data): AddQueryDefaults<T, {
|
|
3988
4008
|
[K in keyof Data]: true;
|
|
3989
4009
|
}>;
|
|
3990
4010
|
/**
|
|
@@ -3995,8 +4015,9 @@ declare class Create {
|
|
|
3995
4015
|
* or a composite primary key unique index on a set of columns,
|
|
3996
4016
|
* and a row being created has the same value as a row that already exists in the table in this column(s).
|
|
3997
4017
|
*
|
|
3998
|
-
* Use
|
|
3999
|
-
* or `
|
|
4018
|
+
* Use {@link onConflictDoNothing} to suppress the error and continue without updating the record,
|
|
4019
|
+
* or the `merge` to update the record with new values automatically,
|
|
4020
|
+
* or the `set` to specify own values for the update.
|
|
4000
4021
|
*
|
|
4001
4022
|
* `onConflict` only accepts column names that are defined in `primaryKey` or `unique` in the table definition.
|
|
4002
4023
|
* To specify a constraint, its name also must be explicitly set in `primaryKey` or `unique` in the table code.
|
|
@@ -4005,11 +4026,11 @@ declare class Create {
|
|
|
4005
4026
|
* for updating the record.
|
|
4006
4027
|
*
|
|
4007
4028
|
* If your table has multiple potential reasons for unique constraint violation, such as username and email columns in a user table,
|
|
4008
|
-
* consider using
|
|
4029
|
+
* consider using `upsert` instead.
|
|
4009
4030
|
*
|
|
4010
4031
|
* ```ts
|
|
4011
4032
|
* // leave `onConflict` without argument to ignore or merge on any conflict
|
|
4012
|
-
* db.table.create(data).
|
|
4033
|
+
* db.table.create(data).onConflictDoNothing();
|
|
4013
4034
|
*
|
|
4014
4035
|
* // single column:
|
|
4015
4036
|
* db.table.create(data).onConfict('email').merge();
|
|
@@ -4042,11 +4063,26 @@ declare class Create {
|
|
|
4042
4063
|
* .ignore();
|
|
4043
4064
|
* ```
|
|
4044
4065
|
*
|
|
4066
|
+
* For `merge` and `set`, you can append `where` to update data only for the matching rows:
|
|
4067
|
+
*
|
|
4068
|
+
* ```ts
|
|
4069
|
+
* const timestamp = Date.now();
|
|
4070
|
+
*
|
|
4071
|
+
* db.table
|
|
4072
|
+
* .create(data)
|
|
4073
|
+
* .onConflict('email')
|
|
4074
|
+
* .set({
|
|
4075
|
+
* name: 'John Doe',
|
|
4076
|
+
* updatedAt: timestamp,
|
|
4077
|
+
* })
|
|
4078
|
+
* .where({ updatedAt: { lt: timestamp } });
|
|
4079
|
+
* ```
|
|
4080
|
+
*
|
|
4045
4081
|
* @param arg - optionally provide an array of columns
|
|
4046
4082
|
*/
|
|
4047
4083
|
onConflict<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg: Arg): OnConflictQueryBuilder<T, Arg>;
|
|
4048
4084
|
/**
|
|
4049
|
-
* Use `
|
|
4085
|
+
* Use `onConflictDoNothing` to suppress unique constraint violation error when creating a record.
|
|
4050
4086
|
*
|
|
4051
4087
|
* Adds `ON CONFLICT (columns) DO NOTHING` clause to the insert statement, columns are optional.
|
|
4052
4088
|
*
|
|
@@ -4059,142 +4095,110 @@ declare class Create {
|
|
|
4059
4095
|
* name: 'John Doe',
|
|
4060
4096
|
* })
|
|
4061
4097
|
* // on any conflict:
|
|
4062
|
-
* .
|
|
4098
|
+
* .onConflictDoNothing()
|
|
4063
4099
|
* // or, for a specific column:
|
|
4064
|
-
* .
|
|
4100
|
+
* .onConflictDoNothing('email')
|
|
4065
4101
|
* // or, for a specific constraint:
|
|
4066
|
-
* .
|
|
4102
|
+
* .onConflictDoNothing({ constraint: 'unique_index_name' });
|
|
4067
4103
|
* ```
|
|
4068
4104
|
*
|
|
4069
|
-
* When there is a conflict, nothing can be returned from the database, so `
|
|
4105
|
+
* When there is a conflict, nothing can be returned from the database, so `onConflictDoNothing` adds `| undefined` part to the response type.
|
|
4070
4106
|
*
|
|
4071
4107
|
* ```ts
|
|
4072
4108
|
* const maybeRecord: RecordType | undefined = await db.table
|
|
4073
4109
|
* .create(data)
|
|
4074
|
-
* .
|
|
4110
|
+
* .onConflictDoNothing();
|
|
4075
4111
|
*
|
|
4076
4112
|
* const maybeId: number | undefined = await db.table
|
|
4077
4113
|
* .get('id')
|
|
4078
4114
|
* .create(data)
|
|
4079
|
-
* .
|
|
4115
|
+
* .onConflictDoNothing();
|
|
4080
4116
|
* ```
|
|
4081
4117
|
*
|
|
4082
4118
|
* When creating multiple records, only created records will be returned. If no records were created, array will be empty:
|
|
4083
4119
|
*
|
|
4084
4120
|
* ```ts
|
|
4085
4121
|
* // array can be empty
|
|
4086
|
-
* const arr = await db.table.createMany([data, data, data]).
|
|
4122
|
+
* const arr = await db.table.createMany([data, data, data]).onConflictDoNothing();
|
|
4087
4123
|
* ```
|
|
4088
4124
|
*/
|
|
4089
|
-
|
|
4125
|
+
onConflictDoNothing<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg?: Arg): IgnoreResult<T>;
|
|
4090
4126
|
}
|
|
4091
4127
|
declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflictArg<T> | undefined> {
|
|
4092
4128
|
private query;
|
|
4093
4129
|
private onConflict;
|
|
4094
4130
|
constructor(query: T, onConflict: Arg);
|
|
4095
4131
|
/**
|
|
4096
|
-
* Available only after
|
|
4132
|
+
* Available only after `onConflict`.
|
|
4097
4133
|
*
|
|
4098
|
-
*
|
|
4134
|
+
* Updates the record with a given data when conflict occurs.
|
|
4099
4135
|
*
|
|
4100
4136
|
* ```ts
|
|
4101
|
-
* db.table
|
|
4102
|
-
*
|
|
4103
|
-
*
|
|
4104
|
-
* name: 'John Doe',
|
|
4105
|
-
* })
|
|
4106
|
-
* // for a specific column:
|
|
4107
|
-
* .onConflict('email')
|
|
4108
|
-
* // or, for a specific constraint:
|
|
4109
|
-
* .onConflict({ constraint: 'unique_constraint_name' })
|
|
4110
|
-
* .merge();
|
|
4137
|
+
* db.table.create(data).onConflict('column').set({
|
|
4138
|
+
* description: 'setting different data on conflict',
|
|
4139
|
+
* });
|
|
4111
4140
|
* ```
|
|
4112
4141
|
*
|
|
4113
|
-
*
|
|
4142
|
+
* The `set` can take a raw SQL expression:
|
|
4114
4143
|
*
|
|
4115
4144
|
* ```ts
|
|
4116
4145
|
* db.table
|
|
4117
|
-
* .
|
|
4118
|
-
*
|
|
4119
|
-
*
|
|
4120
|
-
* { email: 'alex@example.com', name: 'Alex Doe' },
|
|
4121
|
-
* ])
|
|
4122
|
-
* .onConflict('email')
|
|
4123
|
-
* .merge();
|
|
4124
|
-
* ```
|
|
4125
|
-
*
|
|
4126
|
-
* It is also possible to specify a subset of the columns to merge when a conflict occurs.
|
|
4127
|
-
* For example, you may want to set a `createdAt` column when creating but would prefer not to update it if the row already exists:
|
|
4128
|
-
*
|
|
4129
|
-
* ```ts
|
|
4130
|
-
* const timestamp = Date.now();
|
|
4146
|
+
* .create(data)
|
|
4147
|
+
* .onConflict()
|
|
4148
|
+
* .set(db.table.sql`raw SQL expression`);
|
|
4131
4149
|
*
|
|
4150
|
+
* // update records only on certain conditions
|
|
4132
4151
|
* db.table
|
|
4133
|
-
* .create(
|
|
4134
|
-
* email: 'ignore@example.com',
|
|
4135
|
-
* name: 'John Doe',
|
|
4136
|
-
* createdAt: timestamp,
|
|
4137
|
-
* updatedAt: timestamp,
|
|
4138
|
-
* })
|
|
4152
|
+
* .create(data)
|
|
4139
4153
|
* .onConflict('email')
|
|
4140
|
-
*
|
|
4141
|
-
* .
|
|
4142
|
-
* // or, update multiple columns
|
|
4143
|
-
* .merge(['email', 'name', 'updatedAt']);
|
|
4154
|
+
* .set({ key: 'value' })
|
|
4155
|
+
* .where({ ...certainConditions });
|
|
4144
4156
|
* ```
|
|
4145
4157
|
*
|
|
4146
|
-
*
|
|
4147
|
-
|
|
4148
|
-
|
|
4158
|
+
* @param set - object containing new column values, or raw SQL
|
|
4159
|
+
*/
|
|
4160
|
+
set(set: Partial<T['inputType']> | Expression): T;
|
|
4161
|
+
/**
|
|
4162
|
+
* Available only after `onConflict`.
|
|
4149
4163
|
*
|
|
4150
|
-
*
|
|
4151
|
-
* const timestamp = Date.now();
|
|
4164
|
+
* Use this method to merge all the data you have passed into `create` to update the existing record on conflict.
|
|
4152
4165
|
*
|
|
4153
|
-
*
|
|
4154
|
-
* .create({
|
|
4155
|
-
* email: 'ignore@example.com',
|
|
4156
|
-
* name: 'John Doe',
|
|
4157
|
-
* createdAt: timestamp,
|
|
4158
|
-
* updatedAt: timestamp,
|
|
4159
|
-
* })
|
|
4160
|
-
* .onConflict('email')
|
|
4161
|
-
* .merge({
|
|
4162
|
-
* name: 'John Doe The Second',
|
|
4163
|
-
* });
|
|
4164
|
-
* ```
|
|
4166
|
+
* If the table has columns with **dynamic** default values, such values will be applied as well.
|
|
4165
4167
|
*
|
|
4166
|
-
* You can
|
|
4168
|
+
* You can exclude certain columns from being merged by passing the `exclude` option.
|
|
4167
4169
|
*
|
|
4168
4170
|
* ```ts
|
|
4169
|
-
*
|
|
4171
|
+
* // merge the full data
|
|
4172
|
+
* db.table.create(data).onConflict('email').merge();
|
|
4173
|
+
*
|
|
4174
|
+
* // merge only a single column
|
|
4175
|
+
* db.table.create(data).onConflict('email').merge('name');
|
|
4170
4176
|
*
|
|
4177
|
+
* // merge multiple columns
|
|
4178
|
+
* db.table.create(data).onConflict('email').merge(['name', 'quantity']);
|
|
4179
|
+
*
|
|
4180
|
+
* // merge all columns except some
|
|
4171
4181
|
* db.table
|
|
4172
|
-
* .create(
|
|
4173
|
-
* email: 'ignore@example.com',
|
|
4174
|
-
* name: 'John Doe',
|
|
4175
|
-
* createdAt: timestamp,
|
|
4176
|
-
* updatedAt: timestamp,
|
|
4177
|
-
* })
|
|
4182
|
+
* .create(data)
|
|
4178
4183
|
* .onConflict('email')
|
|
4179
|
-
* .merge({
|
|
4180
|
-
* name: 'John Doe',
|
|
4181
|
-
* updatedAt: timestamp,
|
|
4182
|
-
* })
|
|
4183
|
-
* .where({ updatedAt: { lt: timestamp } });
|
|
4184
|
-
* ```
|
|
4184
|
+
* .merge({ except: ['name', 'quantity'] });
|
|
4185
4185
|
*
|
|
4186
|
-
*
|
|
4186
|
+
* // merge can be applied also for batch creates
|
|
4187
|
+
* db.table.createMany([data1, data2, data2]).onConflict('email').merge();
|
|
4187
4188
|
*
|
|
4188
|
-
*
|
|
4189
|
+
* // update records only on certain conditions
|
|
4189
4190
|
* db.table
|
|
4190
4191
|
* .create(data)
|
|
4191
|
-
* .onConflict()
|
|
4192
|
-
* .merge(
|
|
4192
|
+
* .onConflict('email')
|
|
4193
|
+
* .merge()
|
|
4194
|
+
* .where({ ...certainConditions });
|
|
4193
4195
|
* ```
|
|
4194
4196
|
*
|
|
4195
|
-
* @param
|
|
4197
|
+
* @param merge - no argument will merge all data, or provide a column(s) to merge, or provide `except` to update all except some.
|
|
4196
4198
|
*/
|
|
4197
|
-
merge(
|
|
4199
|
+
merge(merge?: keyof T['shape'] | (keyof T['shape'])[] | {
|
|
4200
|
+
except: keyof T['shape'] | (keyof T['shape'])[];
|
|
4201
|
+
}): T;
|
|
4198
4202
|
}
|
|
4199
4203
|
|
|
4200
4204
|
type DeleteMethodsNames = 'delete';
|
|
@@ -5707,14 +5711,14 @@ declare class SearchMethods {
|
|
|
5707
5711
|
search<T extends PickQueryMeta, As extends string>(this: T, arg: SearchArg<T, As>): WhereSearchResult<T, As>;
|
|
5708
5712
|
}
|
|
5709
5713
|
|
|
5710
|
-
type OrCreateArg<T extends Query> = CreateData<T> | (() => CreateData<T>);
|
|
5711
|
-
type UpsertArg<T extends Query, Data> = {
|
|
5714
|
+
type OrCreateArg<T extends Query, BT> = CreateData<T, BT> | (() => CreateData<T, BT>);
|
|
5715
|
+
type UpsertArg<T extends Query, Data, BT> = {
|
|
5712
5716
|
update: Data;
|
|
5713
|
-
create: CreateData<T> | ((update: Data) => CreateData<T>);
|
|
5714
|
-
} | UpsertArgWithData<T, Data>;
|
|
5715
|
-
type UpsertArgWithData<T extends Query, Data> = {
|
|
5717
|
+
create: CreateData<T, BT> | ((update: Data) => CreateData<T, BT>);
|
|
5718
|
+
} | UpsertArgWithData<T, Data, BT>;
|
|
5719
|
+
type UpsertArgWithData<T extends Query, Data, BT> = {
|
|
5716
5720
|
data: Data;
|
|
5717
|
-
create: UpsertCreate<keyof Data, CreateData<T>> | ((update: Data) => UpsertCreate<keyof Data, CreateData<T>>);
|
|
5721
|
+
create: UpsertCreate<keyof Data, CreateData<T, BT>> | ((update: Data) => UpsertCreate<keyof Data, CreateData<T, BT>>);
|
|
5718
5722
|
};
|
|
5719
5723
|
type UpsertCreate<DataKey extends PropertyKey, CD> = {
|
|
5720
5724
|
[K in keyof CD as K extends DataKey ? never : K]: CD[K];
|
|
@@ -5819,7 +5823,7 @@ declare class QueryUpsertOrCreate {
|
|
|
5819
5823
|
*
|
|
5820
5824
|
* @param data - `update` property for the data to update, `create` property for the data to create
|
|
5821
5825
|
*/
|
|
5822
|
-
upsert<T extends UpsertThis, Update extends UpdateData<T>>(this: T, data: UpsertArg<T, Update>): UpsertResult<T>;
|
|
5826
|
+
upsert<T extends UpsertThis, Update extends UpdateData<T>, BT extends CreateBelongsToData<T>>(this: T, data: UpsertArg<T, Update, BT>): UpsertResult<T>;
|
|
5823
5827
|
/**
|
|
5824
5828
|
* `orCreate` creates a record only if it was not found by conditions.
|
|
5825
5829
|
*
|
|
@@ -5851,7 +5855,7 @@ declare class QueryUpsertOrCreate {
|
|
|
5851
5855
|
*
|
|
5852
5856
|
* @param data - the same data as for `create`, it may be returned from a callback
|
|
5853
5857
|
*/
|
|
5854
|
-
orCreate<T extends UpsertThis
|
|
5858
|
+
orCreate<T extends UpsertThis, BT extends CreateBelongsToData<T>>(this: T, data: OrCreateArg<T, BT>): UpsertResult<T>;
|
|
5855
5859
|
}
|
|
5856
5860
|
|
|
5857
5861
|
declare abstract class RawSqlMethods<ColumnTypes> {
|
|
@@ -6772,6 +6776,11 @@ type SetQueryReturnsAllKind<T extends PickQueryMetaResult, Kind extends string>
|
|
|
6772
6776
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6773
6777
|
} : K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : T[K];
|
|
6774
6778
|
} & QueryMetaHasWhere;
|
|
6779
|
+
type SetQueryReturnsAllKindResult<T extends PickQueryMetaResult, Kind extends string, Result extends QueryColumns> = {
|
|
6780
|
+
[K in keyof T]: K extends 'meta' ? {
|
|
6781
|
+
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6782
|
+
} : K extends 'returnType' ? 'all' : K extends 'result' ? Result : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : T[K];
|
|
6783
|
+
} & QueryMetaHasWhere;
|
|
6775
6784
|
type SetQueryReturnsOneOptional<T extends PickQueryResult> = {
|
|
6776
6785
|
[K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']> | undefined> : T[K];
|
|
6777
6786
|
};
|
|
@@ -6783,6 +6792,11 @@ type SetQueryReturnsOneKind<T extends PickQueryMetaResult, Kind extends string>
|
|
|
6783
6792
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6784
6793
|
} : K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> : T[K];
|
|
6785
6794
|
};
|
|
6795
|
+
type SetQueryReturnsOneKindResult<T extends PickQueryMetaResult, Kind extends string, Result extends QueryColumns> = {
|
|
6796
|
+
[K in keyof T]: K extends 'meta' ? {
|
|
6797
|
+
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6798
|
+
} : K extends 'returnType' ? 'oneOrThrow' : K extends 'result' ? Result : K extends 'then' ? QueryThen<ColumnShapeOutput<Result>> : T[K];
|
|
6799
|
+
};
|
|
6786
6800
|
type SetQueryReturnsRows<T extends PickQueryResult> = {
|
|
6787
6801
|
[K in keyof T]: K extends 'returnType' ? 'rows' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[keyof T['result']][][]> : T[K];
|
|
6788
6802
|
};
|
|
@@ -6799,6 +6813,13 @@ type SetQueryReturnsPluckColumnKind<T extends PickQueryMetaResult, Kind extends
|
|
|
6799
6813
|
pluck: T['result']['value'];
|
|
6800
6814
|
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['result']['value']['outputType'][]> : T[K];
|
|
6801
6815
|
} & QueryMetaHasSelect;
|
|
6816
|
+
type SetQueryReturnsPluckColumnKindResult<T extends PickQueryMetaResult, Kind extends string, Result extends QueryColumns> = {
|
|
6817
|
+
[K in keyof T]: K extends 'meta' ? {
|
|
6818
|
+
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6819
|
+
} : K extends 'result' ? {
|
|
6820
|
+
pluck: T['result']['value'];
|
|
6821
|
+
} : K extends 'returnType' ? 'pluck' : K extends 'result' ? Result : K extends 'then' ? QueryThen<T['result']['value']['outputType'][]> : T[K];
|
|
6822
|
+
} & QueryMetaHasSelect;
|
|
6802
6823
|
type SetQueryReturnsValueOrThrow<T extends PickQueryMeta, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOrThrow<T, T['meta']['selectable'][Arg]['column']> & T['meta']['selectable'][Arg]['column']['operators'];
|
|
6803
6824
|
type SetQueryReturnsValueOptional<T extends PickQueryMeta, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOptional<T, T['meta']['selectable'][Arg]['column']> & T['meta']['selectable'][Arg]['column']['operators'];
|
|
6804
6825
|
type SetQueryReturnsColumnOrThrow<T, Column extends PickOutputType> = {
|
|
@@ -6818,6 +6839,13 @@ type SetQueryReturnsColumnKind<T extends PickQueryMetaResult, Kind extends strin
|
|
|
6818
6839
|
value: T['result']['pluck'];
|
|
6819
6840
|
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['pluck']['outputType']> : T[K];
|
|
6820
6841
|
} & QueryMetaHasSelect;
|
|
6842
|
+
type SetQueryReturnsColumnKindResult<T extends PickQueryMetaResult, Kind extends string, Result extends QueryColumns> = {
|
|
6843
|
+
[K in keyof T]: K extends 'meta' ? {
|
|
6844
|
+
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6845
|
+
} : K extends 'result' ? {
|
|
6846
|
+
value: T['result']['pluck'];
|
|
6847
|
+
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? Result : K extends 'then' ? QueryThen<Result['pluck']['outputType']> : T[K];
|
|
6848
|
+
} & QueryMetaHasSelect;
|
|
6821
6849
|
type SetQueryReturnsRowCount<T extends PickQueryMetaResult, Kind extends string> = {
|
|
6822
6850
|
[K in keyof T]: K extends 'meta' ? {
|
|
6823
6851
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
@@ -6836,6 +6864,11 @@ type SetQueryKind<T extends PickQueryMeta, Kind extends string> = {
|
|
|
6836
6864
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6837
6865
|
} : T[K];
|
|
6838
6866
|
};
|
|
6867
|
+
type SetQueryKindResult<T extends PickQueryMetaReturnType, Kind extends string, Result extends QueryColumns> = {
|
|
6868
|
+
[K in keyof T]: K extends 'meta' ? {
|
|
6869
|
+
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6870
|
+
} : K extends 'result' ? Result : K extends 'then' ? QueryThen<GetQueryResult<T, Result>> : T[K];
|
|
6871
|
+
};
|
|
6839
6872
|
type SetQueryTableAlias<T extends PickQueryMetaTableShape, As extends string> = {
|
|
6840
6873
|
[K in keyof T]: K extends 'meta' ? {
|
|
6841
6874
|
[K in keyof T['meta'] | 'as']: K extends 'as' ? As : K extends 'selectable' ? Omit<T['meta']['selectable'], `${AliasOrTable<T>}.${keyof T['shape'] & string}`> & {
|
|
@@ -6846,12 +6879,12 @@ type SetQueryTableAlias<T extends PickQueryMetaTableShape, As extends string> =
|
|
|
6846
6879
|
} : T['meta'][K];
|
|
6847
6880
|
} : T[K];
|
|
6848
6881
|
};
|
|
6849
|
-
type SetQueryWith<T, WithData
|
|
6882
|
+
type SetQueryWith<T, WithData> = {
|
|
6850
6883
|
[K in keyof T]: K extends 'withData' ? WithData : T[K];
|
|
6851
6884
|
};
|
|
6852
|
-
type AddQueryWith<T extends PickQueryWithData, With extends WithDataItem> = SetQueryWith<T,
|
|
6853
|
-
[K in With['table']]: With;
|
|
6854
|
-
}
|
|
6885
|
+
type AddQueryWith<T extends PickQueryWithData, With extends WithDataItem> = SetQueryWith<T, {
|
|
6886
|
+
[K in keyof T['withData'] | With['table']]: K extends With['table'] ? With : K extends keyof T['withData'] ? T['withData'][K] : never;
|
|
6887
|
+
}>;
|
|
6855
6888
|
|
|
6856
6889
|
interface ColumnData extends ColumnDataBase {
|
|
6857
6890
|
maxChars?: number;
|
|
@@ -7514,4 +7547,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
7514
7547
|
*/
|
|
7515
7548
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
7516
7549
|
|
|
7517
|
-
export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect, AddQueryWith, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BaseOperators, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, CloneSelfKeys, ColumnData, ColumnExpression, ColumnFromDbParams, ColumnInfoQueryData, ColumnOperators, ColumnRefExpression, ColumnType, ColumnsByType, ColumnsShape, ColumnsShapeToNullableObject, ColumnsShapeToObject, ColumnsShapeToObjectArray, ColumnsShapeToPluck, CommonQueryData, ComputedColumnsBase, CopyOptions, CopyQueryData, Create, CreateColumn, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CreateRelationsData, CreateRelationsDataOmittingFKeys, 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, ExpressionOutput, FnExpression, FnExpressionArgs, FnExpressionArgsPairs, FnExpressionArgsValue, For, From, FromArg, FromArgOptions, FromQuerySelf, FromResult, GetArg, GetColumnInfo, GetQueryResult, GetResult, GetResultOptional, GetStringArg, GroupArg, Having, HavingItem, HookAction, HookSelect, IdentityColumn, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinItemArgs, JoinLateralCallback, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinQueryBuilder, JoinQueryMethod, JoinResult, JoinedParsers, JoinedShapes, JsonItem, JsonMethods, JsonModifiers, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MapTableScopesOption, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumnData,
|
|
7550
|
+
export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect, AddQueryWith, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BaseOperators, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, CloneSelfKeys, ColumnData, ColumnExpression, ColumnFromDbParams, ColumnInfoQueryData, ColumnOperators, ColumnRefExpression, ColumnType, ColumnsByType, ColumnsShape, ColumnsShapeToNullableObject, ColumnsShapeToObject, ColumnsShapeToObjectArray, ColumnsShapeToPluck, CommonQueryData, ComputedColumnsBase, CopyOptions, CopyQueryData, Create, CreateBelongsToData, CreateColumn, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CreateRelationsData, CreateRelationsDataOmittingFKeys, 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, ExpressionOutput, FnExpression, FnExpressionArgs, FnExpressionArgsPairs, FnExpressionArgsValue, For, From, FromArg, FromArgOptions, FromQuerySelf, FromResult, GetArg, GetColumnInfo, GetQueryResult, GetResult, GetResultOptional, GetStringArg, GroupArg, Having, HavingItem, HookAction, HookSelect, IdentityColumn, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinItemArgs, JoinLateralCallback, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinQueryBuilder, JoinQueryMethod, JoinResult, JoinedParsers, JoinedShapes, JsonItem, JsonMethods, JsonModifiers, 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, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgSelf, OrderArgs, OrderItem, OrderTsQueryConfig, Over, PathColumn, PickColumnData, PickQueryBaseQuery, PickQueryDataShapeAndJoinedShapes, PickQueryInternal, PickQueryMetaRelations, PickQueryMetaResultRelations, PickQueryMetaResultRelationsWindows, PickQueryMetaResultRelationsWindowsColumnTypes, PickQueryMetaResultRelationsWithDataReturnType, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryMetaResultReturnTypeWithDataWindows, PickQueryMetaResultReturnTypeWithDataWindowsTable, PickQueryMetaShapeRelationsWithData, PickQueryMetaTable, PickQueryMetaTableShape, PickQueryMetaTableShapeReturnTypeWithData, PickQueryMetaWithData, PickQueryQ, PickQueryQAndBaseQuery, PickQueryQAndInternal, PickQueryRelations, PickQueryRelationsWithData, PickQueryShapeResultSinglePrimaryKey, PickQueryShapeSinglePrimaryKey, PickQuerySinglePrimaryKey, PickQueryWindows, PickQueryWithData, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBaseThen, QueryBeforeHook, QueryData, QueryDataJoinTo, QueryDefaultReturnData, QueryError, QueryErrorName, QueryGet, QueryGetSelf, QueryHelperResult, QueryHookSelect, QueryHooks, QueryInternal, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMetaHasSelect, QueryMetaHasWhere, QueryMethods, QueryResult, QueryReturnsAll, QueryScopeData, QueryScopes, QuerySourceItem, QueryTransform, QueryTransformFn, QueryUpsertOrCreate, QueryWithComputed, QueryWithTable, RawSQL, RawSqlMethods, RealColumn, RecordOfColumnsShapeBase, RelationConfigBase, RelationConfigDataForCreate, RelationJoinQuery, RelationQuery, RelationQueryBase, RelationsBase, SearchArg, SearchMethods, SearchWeight, SearchWeightRecord, Select, SelectArg, SelectAs, SelectItem, SelectQueryData, SelectSubQueryResult, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, 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, SetQueryWith, ShapeColumnPrimaryKeys, ShapeUniqueColumns, SimpleJoinItem, SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, SortDir, SqlFn, 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, UnionArg, UnionItem, UnionKind, UniqueConstraints, UniqueQueryTypeOrExpression, UniqueTableDataItem, UnknownColumn, Update, UpdateArg, UpdateCtx, UpdateCtxCollect, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdateSelf, UpdatedAtDataInjector, UpsertArg, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereNotArgs, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WhereSearchItem, WhereSearchResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowItem, With, WithDataBase, WithDataItem, WithDataItems, WithItem, WithOptions, 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, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addComputedColumns, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeExpression, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseResult, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|