pqb 0.67.4 → 0.67.6
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 +63 -18
- package/dist/index.js +64 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +36 -15
- package/dist/internal.js +18 -0
- package/dist/internal.mjs +2 -2
- package/dist/postgres-js.js +1 -1
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +1 -1
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2742,7 +2742,7 @@ type SelectArgs<T extends SelectSelf> = ('*' | keyof T['__selectable'])[];
|
|
|
2742
2742
|
interface SubQueryAddition<T extends PickQueryWithData> extends IsSubQuery {
|
|
2743
2743
|
withData: T['withData'];
|
|
2744
2744
|
}
|
|
2745
|
-
type SelectAsFnArg<T extends PickQueryRelationsWithData> = EmptyObject extends T['relations'] ? T : { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? T['relations'][K]
|
|
2745
|
+
type SelectAsFnArg<T extends PickQueryRelationsWithData> = EmptyObject extends T['relations'] ? T : { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? RelationQueryMaybeSingle<T['relations'][K]> & SubQueryAddition<T> : K extends keyof T ? T[K] : never };
|
|
2746
2746
|
interface SelectAsArg<T extends SelectSelf> {
|
|
2747
2747
|
[K: string]: keyof T['__selectable'] | Expression | ((q: SelectAsFnArg<T>) => unknown);
|
|
2748
2748
|
}
|
|
@@ -4822,6 +4822,8 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
|
|
|
4822
4822
|
noPrimaryKey: boolean;
|
|
4823
4823
|
comment?: string;
|
|
4824
4824
|
readOnly?: boolean;
|
|
4825
|
+
materialized?: boolean;
|
|
4826
|
+
generatorIgnored?: true;
|
|
4825
4827
|
primaryKeys?: string[];
|
|
4826
4828
|
singlePrimaryKey: SinglePrimaryKey;
|
|
4827
4829
|
uniqueColumns: UniqueColumns;
|
|
@@ -4835,6 +4837,15 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
|
|
|
4835
4837
|
rls?: Rls.Options;
|
|
4836
4838
|
tableRls?: Rls.TableConfig;
|
|
4837
4839
|
tableGrants?: Grant.TableClassGrant[];
|
|
4840
|
+
viewData?: {
|
|
4841
|
+
query?: Query;
|
|
4842
|
+
sql?: string | RawSqlBase;
|
|
4843
|
+
recursive?: boolean;
|
|
4844
|
+
checkOption?: 'LOCAL' | 'CASCADED';
|
|
4845
|
+
securityBarrier?: boolean;
|
|
4846
|
+
securityInvoker?: boolean;
|
|
4847
|
+
withData?: boolean;
|
|
4848
|
+
};
|
|
4838
4849
|
managedRolesSql?: string;
|
|
4839
4850
|
defaultGrantedBy?: string;
|
|
4840
4851
|
grants?: Grant.InternalPrivilege[];
|
|
@@ -4915,6 +4926,14 @@ interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape ex
|
|
|
4915
4926
|
* Disallow runtime create, update, and delete operations.
|
|
4916
4927
|
*/
|
|
4917
4928
|
readOnly?: true | undefined;
|
|
4929
|
+
/**
|
|
4930
|
+
* Mark query objects as backed by a materialized relation.
|
|
4931
|
+
*/
|
|
4932
|
+
materialized?: true | undefined;
|
|
4933
|
+
/**
|
|
4934
|
+
* Exclude a table-like definition from migration DDL generation.
|
|
4935
|
+
*/
|
|
4936
|
+
generatorIgnore?: true | undefined;
|
|
4918
4937
|
/**
|
|
4919
4938
|
* Computed SQL or JS columns definitions
|
|
4920
4939
|
*/
|
|
@@ -4928,7 +4947,7 @@ type DbTableOptionScopes<Table extends string | undefined, Shape extends Column.
|
|
|
4928
4947
|
interface QueryBuilder extends Query.NotReadOnlyQuery {
|
|
4929
4948
|
returnType: undefined;
|
|
4930
4949
|
}
|
|
4931
|
-
declare class Db<Table extends string | undefined = undefined, Shape extends Column.QueryColumnsInit = Column.QueryColumnsInit, PrimaryKeys = never, UniqueColumns = never, UniqueColumnTuples = never, UniqueConstraints = never, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends Column.QueryColumnsInit = Shape, Scopes extends RecordUnknown | undefined = EmptyObject, DefaultSelect extends keyof Shape = keyof Shape, ReadOnly extends true | undefined = undefined> extends QueryMethods<ColumnTypes> implements Query {
|
|
4950
|
+
declare class Db<Table extends string | undefined = undefined, Shape extends Column.QueryColumnsInit = Column.QueryColumnsInit, PrimaryKeys = never, UniqueColumns = never, UniqueColumnTuples = never, UniqueConstraints = never, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends Column.QueryColumnsInit = Shape, Scopes extends RecordUnknown | undefined = EmptyObject, DefaultSelect extends keyof Shape = keyof Shape, ReadOnly extends true | undefined = undefined, Materialized extends true | undefined = undefined> extends QueryMethods<ColumnTypes> implements Query {
|
|
4932
4951
|
adapterNotInTransaction: Adapter;
|
|
4933
4952
|
qb: QueryBuilder;
|
|
4934
4953
|
table: Table;
|
|
@@ -4937,7 +4956,8 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
4937
4956
|
__isQuery: true;
|
|
4938
4957
|
__as: Table & string;
|
|
4939
4958
|
__selectable: SelectableFromShape<ShapeWithComputed, Table>;
|
|
4940
|
-
|
|
4959
|
+
__readOnly: ReadOnly;
|
|
4960
|
+
__materialized: Materialized;
|
|
4941
4961
|
__hasSelect: boolean;
|
|
4942
4962
|
__hasWhere: boolean;
|
|
4943
4963
|
__defaults: { [K in { [K in keyof Shape]: unknown extends Shape[K]['data']['default'] ? never : K }[keyof Shape]]: true };
|
|
@@ -4958,7 +4978,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
4958
4978
|
internal: QueryInternal<{ [K in keyof PrimaryKeys]: (keyof PrimaryKeys extends K ? never : keyof PrimaryKeys) extends never ? PrimaryKeys[K] : never }[keyof PrimaryKeys], PrimaryKeys | UniqueColumns, { [K in keyof Shape]: Shape[K]['data']['unique'] extends string ? K : never }[keyof Shape] | keyof PrimaryKeys, UniqueColumnTuples, UniqueConstraints>;
|
|
4959
4979
|
catch: QueryCatch;
|
|
4960
4980
|
shape: ShapeWithComputed;
|
|
4961
|
-
constructor(adapterNotInTransaction: Adapter, qb: QueryBuilder, table: Table | undefined, shape: ShapeWithComputed, columnTypes: ColumnTypes, asyncStorage: AsyncLocalStorage<AsyncState>, options: DbTableOptions<ColumnTypes, Table, ShapeWithComputed>, tableData?: TableData);
|
|
4981
|
+
constructor(adapterNotInTransaction: Adapter, qb: QueryBuilder, table: Table | undefined, shape: ShapeWithComputed, columnTypes: ColumnTypes, asyncStorage: AsyncLocalStorage<AsyncState>, options: DbTableOptions<ColumnTypes, Table, ShapeWithComputed>, tableData?: TableData, viewData?: QueryInternal['viewData']);
|
|
4962
4982
|
/**
|
|
4963
4983
|
* When in transaction, returns a db adapter object for the transaction,
|
|
4964
4984
|
* returns a default adapter object otherwise.
|
|
@@ -5027,7 +5047,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
5027
5047
|
queryArrays<R extends any[] = any[]>(...args: SQLQueryArgs): Promise<QueryResult<R>>;
|
|
5028
5048
|
}
|
|
5029
5049
|
interface DbTableConstructor<ColumnTypes> {
|
|
5030
|
-
<Table extends string, Shape extends Column.QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<ColumnTypes, Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options): Db<Table, Shape, keyof ShapeColumnPrimaryKeys<Shape> extends never ? never : ShapeColumnPrimaryKeys<Shape>, ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>, ColumnTypes, Shape & ComputedColumnsFromOptions<Options['computed']>, MapTableScopesOption<Options>, ColumnsShape.DefaultSelectKeys<Shape>, Options['readOnly'] extends true ? true : undefined>;
|
|
5050
|
+
<Table extends string, Shape extends Column.QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<ColumnTypes, Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options): Db<Table, Shape, keyof ShapeColumnPrimaryKeys<Shape> extends never ? never : ShapeColumnPrimaryKeys<Shape>, ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>, ColumnTypes, Shape & ComputedColumnsFromOptions<Options['computed']>, MapTableScopesOption<Options>, ColumnsShape.DefaultSelectKeys<Shape>, Options['readOnly'] extends true ? true : undefined, Options['materialized'] extends true ? true : undefined>;
|
|
5031
5051
|
}
|
|
5032
5052
|
interface DbSqlMethod<ColumnTypes> {
|
|
5033
5053
|
<T>(...args: StaticSQLArgs): RawSql<Column.Pick.QueryColumnOfType<T>, ColumnTypes>;
|
|
@@ -5304,6 +5324,9 @@ interface BatchSql extends SqlCommonOptions {
|
|
|
5304
5324
|
type Sql = SingleSql | BatchSql;
|
|
5305
5325
|
declare const quoteTableWithSchema: (query: ToSQLQuery) => string;
|
|
5306
5326
|
declare const getSqlText: (sql: Sql) => string;
|
|
5327
|
+
declare const queryToSql: (query: Query) => SingleSql;
|
|
5328
|
+
declare const rawSqlToSql: (sql: string | RawSqlBase) => SingleSql;
|
|
5329
|
+
declare const sqlToRawSql: (sql: SingleSql) => RawSqlBase;
|
|
5307
5330
|
declare class QuerySql<ColumnTypes> {
|
|
5308
5331
|
/**
|
|
5309
5332
|
* @deprecated: use `sql` exported from the `createBaseTable` (see "define a base table" in the docs)
|
|
@@ -7511,8 +7534,8 @@ type CreateData<T extends CreateSelf> = EmptyObject extends T['relations'] ? Cre
|
|
|
7511
7534
|
type CreateDataWithDefaults<T extends CreateSelf, Defaults extends PropertyKey> = { [K in keyof T['inputType'] as K extends Defaults ? never : K]: K extends Defaults ? never : CreateColumn<T, K> } & { [K in Defaults]?: K extends keyof T['inputType'] ? CreateColumn<T, K> : never };
|
|
7512
7535
|
type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends keyof T['inputType'], OmitFKeys extends PropertyKey> = { [K in keyof T['inputType'] as K extends Defaults | OmitFKeys ? never : K]: K extends Defaults | OmitFKeys ? never : CreateColumn<T, K> } & { [K in Defaults as K extends OmitFKeys ? never : K]?: CreateColumn<T, K> };
|
|
7513
7536
|
type CreateColumn<T extends CreateSelf, K extends keyof T['inputType']> = T['inputType'][K] | ((q: T) => QueryOrExpression<T['inputType'][K]>);
|
|
7514
|
-
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['__defaults'], T['relations'][keyof T['relations']]['omitForeignKeyInCreate']> & CreateRelationsDataOmittingFKeys<T, T['relations'][keyof T['relations']]['dataForCreate']
|
|
7515
|
-
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union extends RelationConfigDataForCreate ? (u: Union['columns'] extends keyof T['__defaults'] ?
|
|
7537
|
+
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['__defaults'], T['relations'][keyof T['relations']]['omitForeignKeyInCreate']> & CreateRelationsDataOmittingFKeys<T, T['relations'][keyof T['relations']]['dataForCreate']>;
|
|
7538
|
+
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union extends RelationConfigDataForCreate ? (u: Union['columns'] extends keyof T['__defaults'] ? Pick<CreateDataWithDefaults<T, keyof T['__defaults']>, Union['columns']> & Partial<Union['nested']> : (Pick<{ [P in keyof T['inputType']]: CreateColumn<T, P> }, Union['columns'] & keyof T['inputType']> & { [K in keyof Union['nested']]?: never }) | Union['nested']) => void : (u: Union) => void) extends ((u: infer Obj) => void) ? Obj : never;
|
|
7516
7539
|
type CreateResult<T extends CreateSelf, Data> = T extends {
|
|
7517
7540
|
isCount: true;
|
|
7518
7541
|
} ? T : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneResult<T, NarrowCreateResult<T, Data>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnResult<T, NarrowCreateResult<T, Data>> : SetQueryResult<T, NarrowCreateResult<T, Data>>;
|
|
@@ -10231,8 +10254,8 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
10231
10254
|
if<T extends PickQueryResultReturnType, R extends PickQueryResult>(this: T, condition: boolean | null | undefined, fn: (q: T) => R & {
|
|
10232
10255
|
returnType: T['returnType'];
|
|
10233
10256
|
}): QueryIfResult<T, R>;
|
|
10234
|
-
queryRelated<T extends PickQueryRelations, RelName extends keyof T['relations']>(this: T, relName: RelName, params: T['relations'][RelName]['params']): T['relations'][RelName]
|
|
10235
|
-
chain<T extends PickQuerySelectableShapeRelationsReturnTypeIsSubQuery, RelName extends keyof T['relations']>(this: T, relName: RelName): T['__subQuery'] extends true | undefined ? [T['returnType'], T['relations'][RelName]['returnsOne']] extends ['one' | 'oneOrThrow', true] ? { [K in keyof T['relations'][RelName]
|
|
10257
|
+
queryRelated<T extends PickQueryRelations, RelName extends keyof T['relations']>(this: T, relName: RelName, params: T['relations'][RelName]['params']): RelationQueryMaybeSingle<T['relations'][RelName]>;
|
|
10258
|
+
chain<T extends PickQuerySelectableShapeRelationsReturnTypeIsSubQuery, RelName extends keyof T['relations']>(this: T, relName: RelName): T['__subQuery'] extends true | undefined ? [T['returnType'], T['relations'][RelName]['returnsOne']] extends ['one' | 'oneOrThrow', true] ? { [K in keyof RelationQueryMaybeSingle<T['relations'][RelName]>]: K extends '__selectable' ? RelationQueryMaybeSingle<T['relations'][RelName]>['__selectable'] & Omit<T['__selectable'], keyof T['shape']> : RelationQueryMaybeSingle<T['relations'][RelName]>[K] } & IsSubQuery : JoinResultRequireMain<T['relations'][RelName]['query'], Omit<T['__selectable'], keyof T['shape']>> : T['relations'][RelName]['query'];
|
|
10236
10259
|
}
|
|
10237
10260
|
interface DbExtension {
|
|
10238
10261
|
name: string;
|
|
@@ -10244,6 +10267,8 @@ interface GeneratorIgnore {
|
|
|
10244
10267
|
domains?: string[];
|
|
10245
10268
|
extensions?: string[];
|
|
10246
10269
|
tables?: string[];
|
|
10270
|
+
/** Regular views to ignore during migration generation. */
|
|
10271
|
+
views?: (string | RegExp)[];
|
|
10247
10272
|
grants?: Grant.Ignore;
|
|
10248
10273
|
}
|
|
10249
10274
|
interface DbDomainArg<ColumnTypes> {
|
|
@@ -10307,11 +10332,15 @@ interface Query extends IsQuery, PickQueryTable, PickQueryShape, PickQuerySelect
|
|
|
10307
10332
|
relations: RelationsBase;
|
|
10308
10333
|
relationQueries: IsQueries;
|
|
10309
10334
|
error: new (message: string, length: number, name: QueryErrorName) => QueryError;
|
|
10310
|
-
|
|
10335
|
+
__readOnly: true | undefined;
|
|
10336
|
+
__materialized: true | undefined;
|
|
10311
10337
|
}
|
|
10312
10338
|
declare namespace Query {
|
|
10313
10339
|
interface NotReadOnlyQuery extends Query {
|
|
10314
|
-
|
|
10340
|
+
__readOnly: undefined;
|
|
10341
|
+
}
|
|
10342
|
+
interface MaterializedQuery extends Query {
|
|
10343
|
+
__materialized: true;
|
|
10315
10344
|
}
|
|
10316
10345
|
namespace Order {
|
|
10317
10346
|
type Arg<T extends Order.ArgThis> = Order.Arg<T>;
|
|
@@ -10325,7 +10354,10 @@ declare namespace Query {
|
|
|
10325
10354
|
returnType: 'value' | 'valueOrThrow';
|
|
10326
10355
|
}
|
|
10327
10356
|
interface IsNotReadOnly {
|
|
10328
|
-
|
|
10357
|
+
__readOnly: undefined;
|
|
10358
|
+
}
|
|
10359
|
+
interface IsMaterialized {
|
|
10360
|
+
__materialized: true;
|
|
10329
10361
|
}
|
|
10330
10362
|
}
|
|
10331
10363
|
}
|
|
@@ -10386,19 +10418,18 @@ declare const isQueryReturnsAll: (q: Query) => boolean;
|
|
|
10386
10418
|
interface RelationJoinQuery {
|
|
10387
10419
|
(joiningQuery: IsQuery, baseQuery: IsQuery): IsQuery;
|
|
10388
10420
|
}
|
|
10389
|
-
interface RelationConfigQuery extends PickQueryResult, PickQuerySelectable, PickQueryShape, PickQueryTable, PickQueryAs, PickQueryRelations {}
|
|
10421
|
+
interface RelationConfigQuery extends PickQueryResult, PickQuerySelectable, PickQueryShape, PickQueryTable, PickQueryAs, PickQueryRelations, PickQueryReturnType {}
|
|
10390
10422
|
interface RelationConfigBase extends IsQuery {
|
|
10391
10423
|
returnsOne: boolean;
|
|
10424
|
+
required?: unknown;
|
|
10392
10425
|
query: RelationConfigQuery;
|
|
10393
10426
|
joinQuery: RelationJoinQuery;
|
|
10394
10427
|
reverseJoin: RelationJoinQuery;
|
|
10395
10428
|
params: unknown;
|
|
10396
10429
|
queryRelated(params: unknown): unknown;
|
|
10397
10430
|
modifyRelatedQuery?(relatedQuery: IsQuery): (query: IsQuery) => void;
|
|
10398
|
-
maybeSingle: PickQuerySelectableReturnType;
|
|
10399
10431
|
omitForeignKeyInCreate: PropertyKey;
|
|
10400
|
-
dataForCreate:
|
|
10401
|
-
optionalDataForCreate: unknown;
|
|
10432
|
+
dataForCreate: unknown;
|
|
10402
10433
|
dataForUpdate: unknown;
|
|
10403
10434
|
dataForUpdateOne: unknown;
|
|
10404
10435
|
primaryKeys: string[];
|
|
@@ -10410,6 +10441,7 @@ interface RelationConfigDataForCreate {
|
|
|
10410
10441
|
interface RelationsBase {
|
|
10411
10442
|
[K: string]: RelationConfigBase;
|
|
10412
10443
|
}
|
|
10444
|
+
type RelationQueryMaybeSingle<T extends RelationConfigBase> = T['returnsOne'] extends true ? T['required'] extends true ? QueryManyTake<T['query']> : QueryManyTakeOptional<T['query']> : T['query'];
|
|
10413
10445
|
interface PickQueryTable {
|
|
10414
10446
|
table?: string;
|
|
10415
10447
|
}
|
|
@@ -10457,7 +10489,6 @@ interface PickQuerySelectableResultRelationsWithDataReturnTypeShapeAs extends Pi
|
|
|
10457
10489
|
interface PickQuerySelectableShape extends PickQuerySelectable, PickQueryShape {}
|
|
10458
10490
|
interface PickQuerySelectableColumnTypes extends PickQuerySelectable, PickQueryColumTypes {}
|
|
10459
10491
|
interface PickQuerySelectableShapeRelationsReturnTypeIsSubQuery extends PickQueryIsSubQuery, PickQuerySelectable, PickQueryShape, PickQueryRelations, PickQueryReturnType {}
|
|
10460
|
-
interface PickQuerySelectableReturnType extends PickQuerySelectable, PickQueryReturnType {}
|
|
10461
10492
|
interface PickQuerySelectableResultInputTypeAs extends PickQuerySelectableResult, PickQueryInputType, PickQueryAs {}
|
|
10462
10493
|
interface PickQuerySelectableResultAs extends PickQuerySelectable, PickQueryResult, PickQueryAs {}
|
|
10463
10494
|
interface PickQueryIsSubQuery {
|
|
@@ -10561,6 +10592,20 @@ declare abstract class QueryAsMethods {
|
|
|
10561
10592
|
}
|
|
10562
10593
|
declare const _appendQuery: (main: Query, append: Query, asFn: (as: string) => void) => Query;
|
|
10563
10594
|
declare const _appendQueryOnUpsertCreate: (main: Query, append: Query, asFn: (as: string) => void) => Query;
|
|
10595
|
+
interface RefreshMaterializedViewOptions {
|
|
10596
|
+
/**
|
|
10597
|
+
* Refresh the materialized view without blocking concurrent selects.
|
|
10598
|
+
*/
|
|
10599
|
+
concurrently?: boolean;
|
|
10600
|
+
/**
|
|
10601
|
+
* Use `WITH DATA` or `WITH NO DATA` for the refreshed materialized view.
|
|
10602
|
+
*/
|
|
10603
|
+
withData?: boolean;
|
|
10604
|
+
}
|
|
10605
|
+
/**
|
|
10606
|
+
* Refresh a materialized view.
|
|
10607
|
+
*/
|
|
10608
|
+
declare const refreshMaterializedView: <T extends Query.MaterializedQuery>(query: T, options?: RefreshMaterializedViewOptions) => Promise<void>;
|
|
10564
10609
|
declare const getPrimaryKeys: (q: Query) => string[];
|
|
10565
10610
|
/**
|
|
10566
10611
|
* Set value into the object in query data, create the object if it doesn't yet exist.
|
|
@@ -10716,4 +10761,4 @@ declare const testTransaction: {
|
|
|
10716
10761
|
*/
|
|
10717
10762
|
close(arg: Arg$1): Promise<void>;
|
|
10718
10763
|
};
|
|
10719
|
-
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AdapterSchemaConfigOptions, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type ExpressionData, type FromArg, type FromResult, type GeneratorIgnore, type Grant, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type Rls, type RlsPolicy, type SchemaConfigFnWithOptions, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, type ToSQLCtx, type ToSqlValues, type TransactionAdapter, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _appendQueryOnUpsertCreate, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
|
10764
|
+
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AdapterSchemaConfigOptions, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type ExpressionData, type FromArg, type FromResult, type GeneratorIgnore, type Grant, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RefreshMaterializedViewOptions, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type Rls, type RlsPolicy, type SchemaConfigFnWithOptions, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, type ToSQLCtx, type ToSqlValues, type TransactionAdapter, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _appendQueryOnUpsertCreate, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, queryToSql, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, rawSqlToSql, referencesArgsToCode, refreshMaterializedView, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, sqlToRawSql, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
package/dist/index.js
CHANGED
|
@@ -8033,12 +8033,12 @@ var FnExpression = class extends Expression {
|
|
|
8033
8033
|
if (options.distinct && !options.withinGroup) sql.push("DISTINCT ");
|
|
8034
8034
|
const q = this.q;
|
|
8035
8035
|
sql.push(this.args.map((arg) => {
|
|
8036
|
-
if (typeof arg === "string") return arg === "*" ? "*" :
|
|
8036
|
+
if (typeof arg === "string") return arg === "*" ? "*" : fnArgToSql(ctx, q, arg, quotedAs);
|
|
8037
8037
|
else if (arg instanceof Expression) return arg.toSQL(ctx, quotedAs);
|
|
8038
8038
|
else if ("pairs" in arg) {
|
|
8039
8039
|
const args = [];
|
|
8040
8040
|
const { pairs } = arg;
|
|
8041
|
-
for (const key in pairs) args.push(`${addValue(values, key)}::text, ${
|
|
8041
|
+
for (const key in pairs) args.push(`${addValue(values, key)}::text, ${fnArgToSql(ctx, q, pairs[key], quotedAs)}`);
|
|
8042
8042
|
return args.join(", ");
|
|
8043
8043
|
} else return addValue(values, arg.value);
|
|
8044
8044
|
}).join(", "));
|
|
@@ -8062,6 +8062,13 @@ var FnExpression = class extends Expression {
|
|
|
8062
8062
|
return sql.join("");
|
|
8063
8063
|
}
|
|
8064
8064
|
};
|
|
8065
|
+
const fnArgToSql = (ctx, data, arg, quotedAs) => {
|
|
8066
|
+
if (typeof arg === "string") {
|
|
8067
|
+
if (arg.endsWith(".*") || data.valuesJoinedAs?.[arg]) return columnToSql(ctx, data, data.shape, arg, quotedAs);
|
|
8068
|
+
return selectedColumnToSql(ctx, data, data.shape, arg, quotedAs);
|
|
8069
|
+
}
|
|
8070
|
+
return arg.toSQL(ctx, quotedAs);
|
|
8071
|
+
};
|
|
8065
8072
|
function makeFnExpression(self, type, fn, args, options) {
|
|
8066
8073
|
const q = extendQuery(self, type.operators);
|
|
8067
8074
|
q.baseQuery.type = ExpressionTypeMethod.prototype.type;
|
|
@@ -9858,6 +9865,34 @@ const getSqlText = (sql) => {
|
|
|
9858
9865
|
if ("text" in sql) return sql.text;
|
|
9859
9866
|
throw new Error(`Batch SQL is not supported in this query`);
|
|
9860
9867
|
};
|
|
9868
|
+
const queryToSql = (query) => {
|
|
9869
|
+
const sql = query.toSQL();
|
|
9870
|
+
if ("batch" in sql) throw new OrchidOrmInternalError(query, "Batch SQL is not supported in query definitions");
|
|
9871
|
+
return sql;
|
|
9872
|
+
};
|
|
9873
|
+
const rawSqlToSql = (sql) => {
|
|
9874
|
+
if (typeof sql === "string") return { text: sql };
|
|
9875
|
+
const values = [];
|
|
9876
|
+
return {
|
|
9877
|
+
text: sql.toSQL({ values }),
|
|
9878
|
+
values
|
|
9879
|
+
};
|
|
9880
|
+
};
|
|
9881
|
+
const sqlToRawSql = (sql) => {
|
|
9882
|
+
const { values } = sql;
|
|
9883
|
+
if (!values?.length) return raw({ raw: sql.text });
|
|
9884
|
+
const rawValues = {};
|
|
9885
|
+
for (let i = 0; i < values.length; i++) rawValues[`queryValue${i + 1}`] = values[i];
|
|
9886
|
+
return raw({ raw: replaceSqlPlaceholders(sql.text, values.length) }).values(rawValues);
|
|
9887
|
+
};
|
|
9888
|
+
const replaceSqlPlaceholders = (sql, valuesCount) => {
|
|
9889
|
+
const parts = sql.split("'");
|
|
9890
|
+
for (let i = 0; i < parts.length; i += 2) parts[i] = parts[i].replace(/\$(\d+)/g, (match, index) => {
|
|
9891
|
+
const number = Number(index);
|
|
9892
|
+
return number > 0 && number <= valuesCount ? `$queryValue${number}` : match;
|
|
9893
|
+
});
|
|
9894
|
+
return parts.join("'");
|
|
9895
|
+
};
|
|
9861
9896
|
var QuerySql = class {
|
|
9862
9897
|
sql(...args) {
|
|
9863
9898
|
const sql = raw(...args);
|
|
@@ -12566,6 +12601,25 @@ function getSupportedDefaultPrivileges(version) {
|
|
|
12566
12601
|
supportedPrivilegesCache.set(version, result);
|
|
12567
12602
|
return result;
|
|
12568
12603
|
}
|
|
12604
|
+
const makeRefreshMaterializedViewSql = (query, options) => {
|
|
12605
|
+
if (options?.concurrently && options.withData === false) throw new Error("Cannot refresh a materialized view concurrently with WITH NO DATA");
|
|
12606
|
+
const sql = ["REFRESH MATERIALIZED VIEW"];
|
|
12607
|
+
if (options?.concurrently) sql.push("CONCURRENTLY");
|
|
12608
|
+
sql.push(quoteTableWithSchema(query));
|
|
12609
|
+
if (options?.withData === true) sql.push("WITH DATA");
|
|
12610
|
+
else if (options?.withData === false) sql.push("WITH NO DATA");
|
|
12611
|
+
return {
|
|
12612
|
+
text: sql.join(" "),
|
|
12613
|
+
values: []
|
|
12614
|
+
};
|
|
12615
|
+
};
|
|
12616
|
+
/**
|
|
12617
|
+
* Refresh a materialized view.
|
|
12618
|
+
*/
|
|
12619
|
+
const refreshMaterializedView = async (query, options) => {
|
|
12620
|
+
const sql = makeRefreshMaterializedViewSql(query, options);
|
|
12621
|
+
await (query.internal.asyncStorage.getStore()?.transactionAdapter || query.q.adapter).query(sql.text, sql.values);
|
|
12622
|
+
};
|
|
12569
12623
|
var QueryJsonMethods = class {
|
|
12570
12624
|
/**
|
|
12571
12625
|
* Wraps the query in a way to select a single JSON string.
|
|
@@ -13824,7 +13878,7 @@ const performQuery = async (q, args, method) => {
|
|
|
13824
13878
|
}
|
|
13825
13879
|
};
|
|
13826
13880
|
var Db = class extends QueryMethods {
|
|
13827
|
-
constructor(adapterNotInTransaction, qb, table = void 0, shape, columnTypes, asyncStorage, options, tableData = {}) {
|
|
13881
|
+
constructor(adapterNotInTransaction, qb, table = void 0, shape, columnTypes, asyncStorage, options, tableData = {}, viewData) {
|
|
13828
13882
|
super();
|
|
13829
13883
|
this.adapterNotInTransaction = adapterNotInTransaction;
|
|
13830
13884
|
this.qb = qb;
|
|
@@ -13890,7 +13944,10 @@ var Db = class extends QueryMethods {
|
|
|
13890
13944
|
noPrimaryKey: options.noPrimaryKey === "ignore",
|
|
13891
13945
|
comment: options.comment,
|
|
13892
13946
|
readOnly: options.readOnly,
|
|
13947
|
+
materialized: options.materialized,
|
|
13948
|
+
generatorIgnored: options.generatorIgnore,
|
|
13893
13949
|
nowSQL: options.nowSQL,
|
|
13950
|
+
viewData,
|
|
13894
13951
|
tableData,
|
|
13895
13952
|
selectAllCount
|
|
13896
13953
|
};
|
|
@@ -14583,12 +14640,15 @@ exports.primaryKeyInnerToCode = primaryKeyInnerToCode;
|
|
|
14583
14640
|
exports.pushQueryOnForOuter = pushQueryOnForOuter;
|
|
14584
14641
|
exports.pushQueryValueImmutable = pushQueryValueImmutable;
|
|
14585
14642
|
exports.pushTableDataCode = pushTableDataCode;
|
|
14643
|
+
exports.queryToSql = queryToSql;
|
|
14586
14644
|
exports.quoteIdentifier = quoteIdentifier;
|
|
14587
14645
|
exports.quoteObjectKey = quoteObjectKey;
|
|
14588
14646
|
exports.quoteTableWithSchema = quoteTableWithSchema;
|
|
14589
14647
|
exports.raw = raw;
|
|
14590
14648
|
exports.rawSqlToCode = rawSqlToCode;
|
|
14649
|
+
exports.rawSqlToSql = rawSqlToSql;
|
|
14591
14650
|
exports.referencesArgsToCode = referencesArgsToCode;
|
|
14651
|
+
exports.refreshMaterializedView = refreshMaterializedView;
|
|
14592
14652
|
exports.returnArg = returnArg;
|
|
14593
14653
|
exports.setColumnData = setColumnData;
|
|
14594
14654
|
exports.setColumnEncode = setColumnEncode;
|
|
@@ -14600,6 +14660,7 @@ exports.setDefaultLanguage = setDefaultLanguage;
|
|
|
14600
14660
|
exports.setFreeAlias = setFreeAlias;
|
|
14601
14661
|
exports.setQueryObjectValueImmutable = setQueryObjectValueImmutable;
|
|
14602
14662
|
exports.singleQuote = singleQuote;
|
|
14663
|
+
exports.sqlToRawSql = sqlToRawSql;
|
|
14603
14664
|
exports.tableDataMethods = tableDataMethods;
|
|
14604
14665
|
exports.testTransaction = testTransaction;
|
|
14605
14666
|
exports.toArray = toArray;
|