pqb 0.62.1 → 0.63.0
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 +15 -6
- package/dist/index.js +76 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -19
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +0 -4
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +1 -1
- package/dist/node-postgres.d.ts +9728 -17
- package/dist/node-postgres.js +255 -32
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +255 -32
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.d.ts +9731 -20
- package/dist/postgres-js.js +229 -19
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +229 -19
- package/dist/postgres-js.mjs.map +1 -1
- package/dist/public.d.ts +1 -1
- package/dist/public.js +8 -0
- package/dist/public.js.map +1 -1
- package/dist/public.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -252,6 +252,11 @@ declare abstract class QueryError<T extends PickQueryShape = PickQueryShape> ext
|
|
|
252
252
|
get columns(): { [K in keyof T["shape"]]?: true | undefined; };
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
interface SqlSessionState {
|
|
256
|
+
role?: string;
|
|
257
|
+
setConfig?: Record<string, string | number | boolean>;
|
|
258
|
+
}
|
|
259
|
+
|
|
255
260
|
/**
|
|
256
261
|
* Generic result returning from query methods.
|
|
257
262
|
*/
|
|
@@ -342,6 +347,7 @@ interface AdapterTransactionOptions {
|
|
|
342
347
|
locals?: {
|
|
343
348
|
[ConfigName: string]: string | number;
|
|
344
349
|
};
|
|
350
|
+
sqlSessionState?: SqlSessionState;
|
|
345
351
|
}
|
|
346
352
|
type TransactionArgs<Result> = [
|
|
347
353
|
cbOrOptions: undefined | AdapterTransactionOptions | ((adapter: TransactionAdapterBase) => Promise<Result>),
|
|
@@ -366,8 +372,8 @@ interface AdapterBase {
|
|
|
366
372
|
getHost(): string;
|
|
367
373
|
getSchema(): QuerySchema | undefined;
|
|
368
374
|
connect?(): Promise<unknown>;
|
|
369
|
-
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[], startingSavepoint?: string, releasingSavepoint?: string): Promise<QueryResult<T>>;
|
|
370
|
-
arrays<R extends any[] = any[]>(text: string, values?: unknown[], startingSavepoint?: string, releasingSavepoint?: string): Promise<QueryArraysResult<R>>;
|
|
375
|
+
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[], startingSavepoint?: string, releasingSavepoint?: string, sqlSessionState?: SqlSessionState): Promise<QueryResult<T>>;
|
|
376
|
+
arrays<R extends any[] = any[]>(text: string, values?: unknown[], startingSavepoint?: string, releasingSavepoint?: string, sqlSessionState?: SqlSessionState): Promise<QueryArraysResult<R>>;
|
|
371
377
|
/**
|
|
372
378
|
* Run a transaction
|
|
373
379
|
*
|
|
@@ -4149,7 +4155,7 @@ declare class QueryWithSchema {
|
|
|
4149
4155
|
withSchema<T>(this: T, schema: QuerySchema | undefined): T;
|
|
4150
4156
|
}
|
|
4151
4157
|
|
|
4152
|
-
interface AsyncState {
|
|
4158
|
+
interface AsyncState extends SqlSessionState {
|
|
4153
4159
|
transactionAdapter?: TransactionAdapterBase;
|
|
4154
4160
|
transactionId?: number;
|
|
4155
4161
|
afterCommit?: TransactionAfterCommitHook[];
|
|
@@ -4158,7 +4164,7 @@ interface AsyncState {
|
|
|
4158
4164
|
catchI?: number;
|
|
4159
4165
|
schema?: QuerySchema;
|
|
4160
4166
|
}
|
|
4161
|
-
interface StorageOptions {
|
|
4167
|
+
interface StorageOptions extends SqlSessionState {
|
|
4162
4168
|
log?: boolean;
|
|
4163
4169
|
schema?: QuerySchema;
|
|
4164
4170
|
}
|
|
@@ -5161,7 +5167,9 @@ declare abstract class ExpressionTypeMethod {
|
|
|
5161
5167
|
}
|
|
5162
5168
|
|
|
5163
5169
|
type IsolationLevel = 'SERIALIZABLE' | 'REPEATABLE READ' | 'READ COMMITTED' | 'READ UNCOMMITTED';
|
|
5164
|
-
interface TransactionOptions
|
|
5170
|
+
interface TransactionOptions {
|
|
5171
|
+
log?: boolean;
|
|
5172
|
+
schema?: QuerySchema;
|
|
5165
5173
|
level?: IsolationLevel;
|
|
5166
5174
|
readOnly?: boolean;
|
|
5167
5175
|
deferrable?: boolean;
|
|
@@ -9768,6 +9776,7 @@ interface QueryHelper<T extends PickQueryTableMetaShapeTableAs, Args extends any
|
|
|
9768
9776
|
args: Args;
|
|
9769
9777
|
result: Result;
|
|
9770
9778
|
}
|
|
9779
|
+
type QueryHelperResult<T extends QueryHelper<PickQueryTableMetaShapeTableAs, any[], MergeQueryArg>> = T['result'];
|
|
9771
9780
|
interface NarrowTypeSelf extends PickQueryResultReturnType {
|
|
9772
9781
|
returnType: undefined | 'all' | 'one' | 'oneOrThrow' | 'value' | 'valueOrThrow' | 'pluck';
|
|
9773
9782
|
}
|
|
@@ -10900,4 +10909,4 @@ declare const testTransaction: {
|
|
|
10900
10909
|
};
|
|
10901
10910
|
|
|
10902
10911
|
export { ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Column, ColumnsShape, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, DefaultPrivileges, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, Expression, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MoneyColumn, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, Operators, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryError, QueryHookUtils, QueryHooks, RawSql, RealColumn, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn$1 as StringColumn, TableData, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, TsQueryColumn, TsVectorColumn, UUIDColumn, UnknownColumn, VarCharColumn, VirtualColumn, XMLColumn, _appendQuery, _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, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setConnectRetryConfig, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, snakeCaseKey, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
|
10903
|
-
export type { AdapterBase, AdapterConfigBase, AfterCommitStandaloneHook, AfterHook, ArrayColumnValue, ArrayData, AsyncState, BaseNumberData, Code, Codes, ColumnFromDbParams, ColumnSchemaConfig, ColumnSchemaGetterColumns, ColumnSchemaGetterTableClass, ColumnToCodeCtx, ColumnTypeSchemaArg, ColumnsByType, ComputedColumnsFromOptions, ComputedOptionsConfig, ComputedOptionsFactory, CreateCtx, CreateData, CreateManyMethodsNames, CreateMethodsNames, CreateSelf, DateColumnData, DbDomainArg, DbExtension, DbOptions, DbResult, DbSharedOptions, DbSqlMethod, DbStructureDomainsMap, DbTableOptionScopes, DbTableOptions, DecimalColumnData, DefaultColumnTypes, DefaultSchemaConfig, DeleteMethodsNames, EmptyObject, EmptyTuple, FromArg, FromResult, GeneratorIgnore, HookSelectValue, IsQuery, IsolationLevel, JoinQueryMethod, JoinedShapes, MapTableScopesOption, MaybeArray, MaybePromise, MergeQuery, NoPrimaryKeyOption, NonUniqDataItem, NumberColumnData, OperatorsArray, OperatorsJson, OperatorsOrdinalText, Ord, PickQueryInputType, PickQueryInternal, PickQueryQ, PickQueryRelations, PickQuerySelectableRelations, PickQueryShape, Query, QueryAfterHook, QueryArraysResult, QueryBeforeActionHook, QueryBeforeHook, QueryData, QueryHasWhere, QueryInternal, QueryLogObject, QueryLogOptions, QueryLogger, QueryManyTake, QueryManyTakeOptional, QueryOrExpression, QueryResult, QueryResultRow, QueryReturnType, QuerySchema, QueryScopes, RawSqlBase, RecordKeyTrue, RecordOptionalString, RecordString, RecordStringOrNumber, RecordUnknown, RelationConfigBase, RelationJoinQuery, RelationsBase, SearchWeight, SelectableFromShape, SerialColumnData, ShallowSimplify, ShapeColumnPrimaryKeys, ShapeUniqueColumns, SingleSql, SingleSqlItem, Sql, SqlFn, StorageOptions, StringData, TableDataFn, TableDataInput, TableDataItem, TableDataItemsUniqueColumnTuples, TableDataItemsUniqueColumns, TableDataItemsUniqueConstraints, TableDataMethods, TemplateLiteralArgs, Timestamps, TransactionAdapterBase, TransactionArgs, TransactionOptions, UniqueConstraints, UniqueTableDataItem, UpdateData, UpsertData, UpsertThis, WhereArg };
|
|
10912
|
+
export type { AdapterBase, AdapterConfigBase, AfterCommitStandaloneHook, AfterHook, ArrayColumnValue, ArrayData, AsyncState, BaseNumberData, Code, Codes, ColumnFromDbParams, ColumnSchemaConfig, ColumnSchemaGetterColumns, ColumnSchemaGetterTableClass, ColumnToCodeCtx, ColumnTypeSchemaArg, ColumnsByType, ComputedColumnsFromOptions, ComputedOptionsConfig, ComputedOptionsFactory, CreateCtx, CreateData, CreateManyMethodsNames, CreateMethodsNames, CreateSelf, DateColumnData, DbDomainArg, DbExtension, DbOptions, DbResult, DbSharedOptions, DbSqlMethod, DbStructureDomainsMap, DbTableOptionScopes, DbTableOptions, DecimalColumnData, DefaultColumnTypes, DefaultSchemaConfig, DeleteMethodsNames, EmptyObject, EmptyTuple, FromArg, FromResult, GeneratorIgnore, HookSelectValue, IsQuery, IsolationLevel, JoinQueryMethod, JoinedShapes, MapTableScopesOption, MaybeArray, MaybePromise, MergeQuery, NoPrimaryKeyOption, NonUniqDataItem, NumberColumnData, OperatorsArray, OperatorsJson, OperatorsOrdinalText, Ord, PickQueryInputType, PickQueryInternal, PickQueryQ, PickQueryRelations, PickQuerySelectableRelations, PickQueryShape, Query, QueryAfterHook, QueryArraysResult, QueryBeforeActionHook, QueryBeforeHook, QueryData, QueryHasWhere, QueryHelperResult, QueryInternal, QueryLogObject, QueryLogOptions, QueryLogger, QueryManyTake, QueryManyTakeOptional, QueryOrExpression, QueryResult, QueryResultRow, QueryReturnType, QuerySchema, QueryScopes, RawSqlBase, RecordKeyTrue, RecordOptionalString, RecordString, RecordStringOrNumber, RecordUnknown, RelationConfigBase, RelationJoinQuery, RelationsBase, SearchWeight, SelectableFromShape, SerialColumnData, ShallowSimplify, ShapeColumnPrimaryKeys, ShapeUniqueColumns, SingleSql, SingleSqlItem, Sql, SqlFn, SqlSessionState, StorageOptions, StringData, TableDataFn, TableDataInput, TableDataItem, TableDataItemsUniqueColumnTuples, TableDataItemsUniqueColumns, TableDataItemsUniqueConstraints, TableDataMethods, TemplateLiteralArgs, Timestamps, TransactionAdapterBase, TransactionArgs, TransactionOptions, UniqueConstraints, UniqueTableDataItem, UpdateData, UpsertData, UpsertThis, WhereArg };
|
package/dist/index.js
CHANGED
|
@@ -3975,6 +3975,14 @@ class UnhandledTypeError extends OrchidOrmInternalError {
|
|
|
3975
3975
|
super(query, `Unhandled type: ${JSON.stringify(value)} received`);
|
|
3976
3976
|
}
|
|
3977
3977
|
}
|
|
3978
|
+
class NestedSqlSessionError extends OrchidOrmInternalError {
|
|
3979
|
+
constructor(query) {
|
|
3980
|
+
super(
|
|
3981
|
+
query,
|
|
3982
|
+
"Cannot nest SQL session scopes. Outer scope already has role or setConfig defined."
|
|
3983
|
+
);
|
|
3984
|
+
}
|
|
3985
|
+
}
|
|
3978
3986
|
|
|
3979
3987
|
const escape = (value, migration, nested) => {
|
|
3980
3988
|
const type = typeof value;
|
|
@@ -4071,15 +4079,53 @@ class QueryLog {
|
|
|
4071
4079
|
}
|
|
4072
4080
|
}
|
|
4073
4081
|
|
|
4074
|
-
const
|
|
4082
|
+
const hasSqlSessionContextOptions = (options) => {
|
|
4083
|
+
return options.role !== void 0 || options.setConfig !== void 0;
|
|
4084
|
+
};
|
|
4085
|
+
const hasActiveSqlSessionContext = (state) => {
|
|
4086
|
+
if (!state) return false;
|
|
4087
|
+
return state.role !== void 0 || state.setConfig !== void 0;
|
|
4088
|
+
};
|
|
4089
|
+
const sqlSessionContextNormalizeSetConfig = (setConfig) => {
|
|
4090
|
+
return Object.fromEntries(
|
|
4091
|
+
Object.entries(setConfig).map(([key, value]) => [key, String(value)])
|
|
4092
|
+
);
|
|
4093
|
+
};
|
|
4094
|
+
const sqlSessionContextSetStorageOptions = (query, state, options, result) => {
|
|
4095
|
+
if (hasSqlSessionContextOptions(options) && hasActiveSqlSessionContext(state)) {
|
|
4096
|
+
throw new NestedSqlSessionError(query);
|
|
4097
|
+
}
|
|
4098
|
+
if (options.role !== void 0) {
|
|
4099
|
+
result.role = options.role;
|
|
4100
|
+
}
|
|
4101
|
+
if (options.setConfig) {
|
|
4102
|
+
result.setConfig = sqlSessionContextNormalizeSetConfig(options.setConfig);
|
|
4103
|
+
}
|
|
4104
|
+
};
|
|
4105
|
+
const sqlSessionContextMergeStorageState = (state, options) => {
|
|
4106
|
+
if (!options) return state;
|
|
4107
|
+
return {
|
|
4108
|
+
role: options.role ?? state?.role,
|
|
4109
|
+
setConfig: options.setConfig ?? state?.setConfig
|
|
4110
|
+
};
|
|
4111
|
+
};
|
|
4112
|
+
const sqlSessionContextGetStateFromAsyncState = (state) => {
|
|
4113
|
+
return state?.role || state?.setConfig ? state : void 0;
|
|
4114
|
+
};
|
|
4115
|
+
|
|
4116
|
+
const processStorageOptions = (query, state, options) => {
|
|
4075
4117
|
let log;
|
|
4076
4118
|
if (options.log !== void 0 && !query.q.log) {
|
|
4077
4119
|
log = logParamToLogObject(query.q.logger, options.log);
|
|
4078
4120
|
}
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4121
|
+
const result = {};
|
|
4122
|
+
if (log) result.log = log;
|
|
4123
|
+
if ("schema" in options) result.schema = options.schema;
|
|
4124
|
+
sqlSessionContextSetStorageOptions(query, state, options, result);
|
|
4125
|
+
if (result.log === void 0 && result.schema === void 0 && result.role === void 0 && result.setConfig === void 0) {
|
|
4126
|
+
return void 0;
|
|
4127
|
+
}
|
|
4128
|
+
return result;
|
|
4083
4129
|
};
|
|
4084
4130
|
let currentDefaultSchema;
|
|
4085
4131
|
const setCurrentDefaultSchema = (schema) => {
|
|
@@ -4089,14 +4135,15 @@ const getQuerySchema$1 = (query) => query.q.schema || currentDefaultSchema;
|
|
|
4089
4135
|
class QueryStorage {
|
|
4090
4136
|
async withOptions(options, cb) {
|
|
4091
4137
|
const state = this.internal.asyncStorage.getStore();
|
|
4092
|
-
const opts = processStorageOptions(this, options);
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4138
|
+
const opts = processStorageOptions(this, state, options);
|
|
4139
|
+
const sqlSessionState = sqlSessionContextMergeStorageState(state, opts);
|
|
4140
|
+
const newState = opts ? {
|
|
4141
|
+
...state,
|
|
4142
|
+
log: opts.log ?? state?.log,
|
|
4143
|
+
schema: opts.schema ?? state?.schema,
|
|
4144
|
+
...sqlSessionState
|
|
4145
|
+
} : void 0;
|
|
4146
|
+
return !opts ? state ? this.internal.asyncStorage.run(state, cb) : cb() : this.internal.asyncStorage.run(newState, cb);
|
|
4100
4147
|
}
|
|
4101
4148
|
}
|
|
4102
4149
|
|
|
@@ -4146,7 +4193,7 @@ class QueryTransaction {
|
|
|
4146
4193
|
const sql = {
|
|
4147
4194
|
values: emptyArray
|
|
4148
4195
|
};
|
|
4149
|
-
const opts = processStorageOptions(this, options);
|
|
4196
|
+
const opts = processStorageOptions(this, void 0, options);
|
|
4150
4197
|
const log = opts?.log || this.q.log;
|
|
4151
4198
|
let logData;
|
|
4152
4199
|
let state = this.internal.asyncStorage.getStore();
|
|
@@ -4948,7 +4995,8 @@ const then = async (q, adapter, state, beforeHooks, afterHooks, afterSaveHooks,
|
|
|
4948
4995
|
method,
|
|
4949
4996
|
sql,
|
|
4950
4997
|
startingSavepoint,
|
|
4951
|
-
releasingSavepoint
|
|
4998
|
+
releasingSavepoint,
|
|
4999
|
+
sqlSessionContextGetStateFromAsyncState(state)
|
|
4952
5000
|
);
|
|
4953
5001
|
const { runAfterQuery } = sql;
|
|
4954
5002
|
if (log) {
|
|
@@ -4994,7 +5042,8 @@ const then = async (q, adapter, state, beforeHooks, afterHooks, afterSaveHooks,
|
|
|
4994
5042
|
queryMethod,
|
|
4995
5043
|
sql,
|
|
4996
5044
|
i === 0 ? startingSavepoint : void 0,
|
|
4997
|
-
i === last ? releasingSavepoint : void 0
|
|
5045
|
+
i === last ? releasingSavepoint : void 0,
|
|
5046
|
+
sqlSessionContextGetStateFromAsyncState(state)
|
|
4998
5047
|
);
|
|
4999
5048
|
if (queryResult) {
|
|
5000
5049
|
queryResult.rowCount += result2.rowCount;
|
|
@@ -5286,12 +5335,13 @@ const then = async (q, adapter, state, beforeHooks, afterHooks, afterSaveHooks,
|
|
|
5286
5335
|
const setCatchingSavepoint = (catchTrx) => {
|
|
5287
5336
|
return catchTrx ? `s${catchTrx.catchI = (catchTrx.catchI || 0) + 1}` : void 0;
|
|
5288
5337
|
};
|
|
5289
|
-
const execQuery = (adapter, method, sql, startingSavepoint, releasingSavepoint) => {
|
|
5338
|
+
const execQuery = (adapter, method, sql, startingSavepoint, releasingSavepoint, sqlSessionState) => {
|
|
5290
5339
|
return adapter[method](
|
|
5291
5340
|
sql.text,
|
|
5292
5341
|
sql.values,
|
|
5293
5342
|
startingSavepoint,
|
|
5294
|
-
releasingSavepoint
|
|
5343
|
+
releasingSavepoint,
|
|
5344
|
+
sqlSessionState
|
|
5295
5345
|
).then((result) => {
|
|
5296
5346
|
if (result.rowCount && !result.rows.length) {
|
|
5297
5347
|
result.rows.length = result.rowCount;
|
|
@@ -15801,7 +15851,14 @@ const performQuery = async (q, args, method) => {
|
|
|
15801
15851
|
let logData;
|
|
15802
15852
|
if (log) logData = log.beforeQuery(sql);
|
|
15803
15853
|
try {
|
|
15804
|
-
const
|
|
15854
|
+
const adapter = trx?.transactionAdapter || q.adapterNotInTransaction;
|
|
15855
|
+
const result = await adapter[method](
|
|
15856
|
+
sql.text,
|
|
15857
|
+
sql.values,
|
|
15858
|
+
void 0,
|
|
15859
|
+
void 0,
|
|
15860
|
+
sqlSessionContextGetStateFromAsyncState(trx)
|
|
15861
|
+
);
|
|
15805
15862
|
if (log) log.afterQuery(sql, logData);
|
|
15806
15863
|
return result;
|
|
15807
15864
|
} catch (err) {
|