pqb 0.67.4 → 0.67.5
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 +54 -18
- package/dist/index.js +32 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +32 -13
- 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,7 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
|
|
|
4822
4822
|
noPrimaryKey: boolean;
|
|
4823
4823
|
comment?: string;
|
|
4824
4824
|
readOnly?: boolean;
|
|
4825
|
+
materialized?: boolean;
|
|
4825
4826
|
primaryKeys?: string[];
|
|
4826
4827
|
singlePrimaryKey: SinglePrimaryKey;
|
|
4827
4828
|
uniqueColumns: UniqueColumns;
|
|
@@ -4835,6 +4836,14 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
|
|
|
4835
4836
|
rls?: Rls.Options;
|
|
4836
4837
|
tableRls?: Rls.TableConfig;
|
|
4837
4838
|
tableGrants?: Grant.TableClassGrant[];
|
|
4839
|
+
viewData?: {
|
|
4840
|
+
sql?: string | RawSqlBase;
|
|
4841
|
+
recursive?: boolean;
|
|
4842
|
+
checkOption?: 'LOCAL' | 'CASCADED';
|
|
4843
|
+
securityBarrier?: boolean;
|
|
4844
|
+
securityInvoker?: boolean;
|
|
4845
|
+
withData?: boolean;
|
|
4846
|
+
};
|
|
4838
4847
|
managedRolesSql?: string;
|
|
4839
4848
|
defaultGrantedBy?: string;
|
|
4840
4849
|
grants?: Grant.InternalPrivilege[];
|
|
@@ -4915,6 +4924,10 @@ interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape ex
|
|
|
4915
4924
|
* Disallow runtime create, update, and delete operations.
|
|
4916
4925
|
*/
|
|
4917
4926
|
readOnly?: true | undefined;
|
|
4927
|
+
/**
|
|
4928
|
+
* Mark query objects as backed by a materialized relation.
|
|
4929
|
+
*/
|
|
4930
|
+
materialized?: true | undefined;
|
|
4918
4931
|
/**
|
|
4919
4932
|
* Computed SQL or JS columns definitions
|
|
4920
4933
|
*/
|
|
@@ -4928,7 +4941,7 @@ type DbTableOptionScopes<Table extends string | undefined, Shape extends Column.
|
|
|
4928
4941
|
interface QueryBuilder extends Query.NotReadOnlyQuery {
|
|
4929
4942
|
returnType: undefined;
|
|
4930
4943
|
}
|
|
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 {
|
|
4944
|
+
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
4945
|
adapterNotInTransaction: Adapter;
|
|
4933
4946
|
qb: QueryBuilder;
|
|
4934
4947
|
table: Table;
|
|
@@ -4937,7 +4950,8 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
4937
4950
|
__isQuery: true;
|
|
4938
4951
|
__as: Table & string;
|
|
4939
4952
|
__selectable: SelectableFromShape<ShapeWithComputed, Table>;
|
|
4940
|
-
|
|
4953
|
+
__readOnly: ReadOnly;
|
|
4954
|
+
__materialized: Materialized;
|
|
4941
4955
|
__hasSelect: boolean;
|
|
4942
4956
|
__hasWhere: boolean;
|
|
4943
4957
|
__defaults: { [K in { [K in keyof Shape]: unknown extends Shape[K]['data']['default'] ? never : K }[keyof Shape]]: true };
|
|
@@ -4958,7 +4972,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
4958
4972
|
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
4973
|
catch: QueryCatch;
|
|
4960
4974
|
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);
|
|
4975
|
+
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
4976
|
/**
|
|
4963
4977
|
* When in transaction, returns a db adapter object for the transaction,
|
|
4964
4978
|
* returns a default adapter object otherwise.
|
|
@@ -5027,7 +5041,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
5027
5041
|
queryArrays<R extends any[] = any[]>(...args: SQLQueryArgs): Promise<QueryResult<R>>;
|
|
5028
5042
|
}
|
|
5029
5043
|
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>;
|
|
5044
|
+
<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
5045
|
}
|
|
5032
5046
|
interface DbSqlMethod<ColumnTypes> {
|
|
5033
5047
|
<T>(...args: StaticSQLArgs): RawSql<Column.Pick.QueryColumnOfType<T>, ColumnTypes>;
|
|
@@ -7511,8 +7525,8 @@ type CreateData<T extends CreateSelf> = EmptyObject extends T['relations'] ? Cre
|
|
|
7511
7525
|
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
7526
|
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
7527
|
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'] ?
|
|
7528
|
+
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['__defaults'], T['relations'][keyof T['relations']]['omitForeignKeyInCreate']> & CreateRelationsDataOmittingFKeys<T, T['relations'][keyof T['relations']]['dataForCreate']>;
|
|
7529
|
+
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
7530
|
type CreateResult<T extends CreateSelf, Data> = T extends {
|
|
7517
7531
|
isCount: true;
|
|
7518
7532
|
} ? 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 +10245,8 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
10231
10245
|
if<T extends PickQueryResultReturnType, R extends PickQueryResult>(this: T, condition: boolean | null | undefined, fn: (q: T) => R & {
|
|
10232
10246
|
returnType: T['returnType'];
|
|
10233
10247
|
}): 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]
|
|
10248
|
+
queryRelated<T extends PickQueryRelations, RelName extends keyof T['relations']>(this: T, relName: RelName, params: T['relations'][RelName]['params']): RelationQueryMaybeSingle<T['relations'][RelName]>;
|
|
10249
|
+
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
10250
|
}
|
|
10237
10251
|
interface DbExtension {
|
|
10238
10252
|
name: string;
|
|
@@ -10244,6 +10258,8 @@ interface GeneratorIgnore {
|
|
|
10244
10258
|
domains?: string[];
|
|
10245
10259
|
extensions?: string[];
|
|
10246
10260
|
tables?: string[];
|
|
10261
|
+
/** Regular views to ignore during migration generation. */
|
|
10262
|
+
views?: (string | RegExp)[];
|
|
10247
10263
|
grants?: Grant.Ignore;
|
|
10248
10264
|
}
|
|
10249
10265
|
interface DbDomainArg<ColumnTypes> {
|
|
@@ -10307,11 +10323,15 @@ interface Query extends IsQuery, PickQueryTable, PickQueryShape, PickQuerySelect
|
|
|
10307
10323
|
relations: RelationsBase;
|
|
10308
10324
|
relationQueries: IsQueries;
|
|
10309
10325
|
error: new (message: string, length: number, name: QueryErrorName) => QueryError;
|
|
10310
|
-
|
|
10326
|
+
__readOnly: true | undefined;
|
|
10327
|
+
__materialized: true | undefined;
|
|
10311
10328
|
}
|
|
10312
10329
|
declare namespace Query {
|
|
10313
10330
|
interface NotReadOnlyQuery extends Query {
|
|
10314
|
-
|
|
10331
|
+
__readOnly: undefined;
|
|
10332
|
+
}
|
|
10333
|
+
interface MaterializedQuery extends Query {
|
|
10334
|
+
__materialized: true;
|
|
10315
10335
|
}
|
|
10316
10336
|
namespace Order {
|
|
10317
10337
|
type Arg<T extends Order.ArgThis> = Order.Arg<T>;
|
|
@@ -10325,7 +10345,10 @@ declare namespace Query {
|
|
|
10325
10345
|
returnType: 'value' | 'valueOrThrow';
|
|
10326
10346
|
}
|
|
10327
10347
|
interface IsNotReadOnly {
|
|
10328
|
-
|
|
10348
|
+
__readOnly: undefined;
|
|
10349
|
+
}
|
|
10350
|
+
interface IsMaterialized {
|
|
10351
|
+
__materialized: true;
|
|
10329
10352
|
}
|
|
10330
10353
|
}
|
|
10331
10354
|
}
|
|
@@ -10386,19 +10409,18 @@ declare const isQueryReturnsAll: (q: Query) => boolean;
|
|
|
10386
10409
|
interface RelationJoinQuery {
|
|
10387
10410
|
(joiningQuery: IsQuery, baseQuery: IsQuery): IsQuery;
|
|
10388
10411
|
}
|
|
10389
|
-
interface RelationConfigQuery extends PickQueryResult, PickQuerySelectable, PickQueryShape, PickQueryTable, PickQueryAs, PickQueryRelations {}
|
|
10412
|
+
interface RelationConfigQuery extends PickQueryResult, PickQuerySelectable, PickQueryShape, PickQueryTable, PickQueryAs, PickQueryRelations, PickQueryReturnType {}
|
|
10390
10413
|
interface RelationConfigBase extends IsQuery {
|
|
10391
10414
|
returnsOne: boolean;
|
|
10415
|
+
required?: unknown;
|
|
10392
10416
|
query: RelationConfigQuery;
|
|
10393
10417
|
joinQuery: RelationJoinQuery;
|
|
10394
10418
|
reverseJoin: RelationJoinQuery;
|
|
10395
10419
|
params: unknown;
|
|
10396
10420
|
queryRelated(params: unknown): unknown;
|
|
10397
10421
|
modifyRelatedQuery?(relatedQuery: IsQuery): (query: IsQuery) => void;
|
|
10398
|
-
maybeSingle: PickQuerySelectableReturnType;
|
|
10399
10422
|
omitForeignKeyInCreate: PropertyKey;
|
|
10400
|
-
dataForCreate:
|
|
10401
|
-
optionalDataForCreate: unknown;
|
|
10423
|
+
dataForCreate: unknown;
|
|
10402
10424
|
dataForUpdate: unknown;
|
|
10403
10425
|
dataForUpdateOne: unknown;
|
|
10404
10426
|
primaryKeys: string[];
|
|
@@ -10410,6 +10432,7 @@ interface RelationConfigDataForCreate {
|
|
|
10410
10432
|
interface RelationsBase {
|
|
10411
10433
|
[K: string]: RelationConfigBase;
|
|
10412
10434
|
}
|
|
10435
|
+
type RelationQueryMaybeSingle<T extends RelationConfigBase> = T['returnsOne'] extends true ? T['required'] extends true ? QueryManyTake<T['query']> : QueryManyTakeOptional<T['query']> : T['query'];
|
|
10413
10436
|
interface PickQueryTable {
|
|
10414
10437
|
table?: string;
|
|
10415
10438
|
}
|
|
@@ -10457,7 +10480,6 @@ interface PickQuerySelectableResultRelationsWithDataReturnTypeShapeAs extends Pi
|
|
|
10457
10480
|
interface PickQuerySelectableShape extends PickQuerySelectable, PickQueryShape {}
|
|
10458
10481
|
interface PickQuerySelectableColumnTypes extends PickQuerySelectable, PickQueryColumTypes {}
|
|
10459
10482
|
interface PickQuerySelectableShapeRelationsReturnTypeIsSubQuery extends PickQueryIsSubQuery, PickQuerySelectable, PickQueryShape, PickQueryRelations, PickQueryReturnType {}
|
|
10460
|
-
interface PickQuerySelectableReturnType extends PickQuerySelectable, PickQueryReturnType {}
|
|
10461
10483
|
interface PickQuerySelectableResultInputTypeAs extends PickQuerySelectableResult, PickQueryInputType, PickQueryAs {}
|
|
10462
10484
|
interface PickQuerySelectableResultAs extends PickQuerySelectable, PickQueryResult, PickQueryAs {}
|
|
10463
10485
|
interface PickQueryIsSubQuery {
|
|
@@ -10561,6 +10583,20 @@ declare abstract class QueryAsMethods {
|
|
|
10561
10583
|
}
|
|
10562
10584
|
declare const _appendQuery: (main: Query, append: Query, asFn: (as: string) => void) => Query;
|
|
10563
10585
|
declare const _appendQueryOnUpsertCreate: (main: Query, append: Query, asFn: (as: string) => void) => Query;
|
|
10586
|
+
interface RefreshMaterializedViewOptions {
|
|
10587
|
+
/**
|
|
10588
|
+
* Refresh the materialized view without blocking concurrent selects.
|
|
10589
|
+
*/
|
|
10590
|
+
concurrently?: boolean;
|
|
10591
|
+
/**
|
|
10592
|
+
* Use `WITH DATA` or `WITH NO DATA` for the refreshed materialized view.
|
|
10593
|
+
*/
|
|
10594
|
+
withData?: boolean;
|
|
10595
|
+
}
|
|
10596
|
+
/**
|
|
10597
|
+
* Refresh a materialized view.
|
|
10598
|
+
*/
|
|
10599
|
+
declare const refreshMaterializedView: <T extends Query.MaterializedQuery>(query: T, options?: RefreshMaterializedViewOptions) => Promise<void>;
|
|
10564
10600
|
declare const getPrimaryKeys: (q: Query) => string[];
|
|
10565
10601
|
/**
|
|
10566
10602
|
* Set value into the object in query data, create the object if it doesn't yet exist.
|
|
@@ -10716,4 +10752,4 @@ declare const testTransaction: {
|
|
|
10716
10752
|
*/
|
|
10717
10753
|
close(arg: Arg$1): Promise<void>;
|
|
10718
10754
|
};
|
|
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 };
|
|
10755
|
+
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, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, refreshMaterializedView, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, 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;
|
|
@@ -12566,6 +12573,25 @@ function getSupportedDefaultPrivileges(version) {
|
|
|
12566
12573
|
supportedPrivilegesCache.set(version, result);
|
|
12567
12574
|
return result;
|
|
12568
12575
|
}
|
|
12576
|
+
const makeRefreshMaterializedViewSql = (query, options) => {
|
|
12577
|
+
if (options?.concurrently && options.withData === false) throw new Error("Cannot refresh a materialized view concurrently with WITH NO DATA");
|
|
12578
|
+
const sql = ["REFRESH MATERIALIZED VIEW"];
|
|
12579
|
+
if (options?.concurrently) sql.push("CONCURRENTLY");
|
|
12580
|
+
sql.push(quoteTableWithSchema(query));
|
|
12581
|
+
if (options?.withData === true) sql.push("WITH DATA");
|
|
12582
|
+
else if (options?.withData === false) sql.push("WITH NO DATA");
|
|
12583
|
+
return {
|
|
12584
|
+
text: sql.join(" "),
|
|
12585
|
+
values: []
|
|
12586
|
+
};
|
|
12587
|
+
};
|
|
12588
|
+
/**
|
|
12589
|
+
* Refresh a materialized view.
|
|
12590
|
+
*/
|
|
12591
|
+
const refreshMaterializedView = async (query, options) => {
|
|
12592
|
+
const sql = makeRefreshMaterializedViewSql(query, options);
|
|
12593
|
+
await (query.internal.asyncStorage.getStore()?.transactionAdapter || query.q.adapter).query(sql.text, sql.values);
|
|
12594
|
+
};
|
|
12569
12595
|
var QueryJsonMethods = class {
|
|
12570
12596
|
/**
|
|
12571
12597
|
* Wraps the query in a way to select a single JSON string.
|
|
@@ -13824,7 +13850,7 @@ const performQuery = async (q, args, method) => {
|
|
|
13824
13850
|
}
|
|
13825
13851
|
};
|
|
13826
13852
|
var Db = class extends QueryMethods {
|
|
13827
|
-
constructor(adapterNotInTransaction, qb, table = void 0, shape, columnTypes, asyncStorage, options, tableData = {}) {
|
|
13853
|
+
constructor(adapterNotInTransaction, qb, table = void 0, shape, columnTypes, asyncStorage, options, tableData = {}, viewData) {
|
|
13828
13854
|
super();
|
|
13829
13855
|
this.adapterNotInTransaction = adapterNotInTransaction;
|
|
13830
13856
|
this.qb = qb;
|
|
@@ -13890,7 +13916,9 @@ var Db = class extends QueryMethods {
|
|
|
13890
13916
|
noPrimaryKey: options.noPrimaryKey === "ignore",
|
|
13891
13917
|
comment: options.comment,
|
|
13892
13918
|
readOnly: options.readOnly,
|
|
13919
|
+
materialized: options.materialized,
|
|
13893
13920
|
nowSQL: options.nowSQL,
|
|
13921
|
+
viewData,
|
|
13894
13922
|
tableData,
|
|
13895
13923
|
selectAllCount
|
|
13896
13924
|
};
|
|
@@ -14589,6 +14617,7 @@ exports.quoteTableWithSchema = quoteTableWithSchema;
|
|
|
14589
14617
|
exports.raw = raw;
|
|
14590
14618
|
exports.rawSqlToCode = rawSqlToCode;
|
|
14591
14619
|
exports.referencesArgsToCode = referencesArgsToCode;
|
|
14620
|
+
exports.refreshMaterializedView = refreshMaterializedView;
|
|
14592
14621
|
exports.returnArg = returnArg;
|
|
14593
14622
|
exports.setColumnData = setColumnData;
|
|
14594
14623
|
exports.setColumnEncode = setColumnEncode;
|