orchid-orm 1.62.5 → 1.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 +31 -6
- package/dist/index.js +12 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Column, TableData, ColumnsShape, Query, SelectableFromShape, CreateManyMethodsNames, QueryHasWhere, RelationConfigBase, QueryManyTake, QueryManyTakeOptional, EmptyObject, CreateData, UpdateData, WhereArg, CreateMethodsNames, MaybeArray, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, AfterCommitStandaloneHook, AdapterBase, FromArg, FromResult, DbSharedOptions, QuerySchema, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, RecordUnknown, ShallowSimplify, ComputedOptionsConfig, QueryOrExpression, QueryData, IsQuery, TableDataFn, DbTableOptionScopes, QueryScopes, ColumnSchemaConfig, DbSqlMethod, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHook, QueryBeforeActionHook, QueryAfterHook, AfterHook, MergeQuery, QueryReturnType } from 'pqb';
|
|
1
|
+
import { Column, TableData, ColumnsShape, Query, SelectableFromShape, CreateManyMethodsNames, QueryHasWhere, RelationConfigBase, QueryManyTake, QueryManyTakeOptional, EmptyObject, CreateData, UpdateData, WhereArg, CreateMethodsNames, MaybeArray, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, AfterCommitStandaloneHook, AdapterBase, FromArg, FromResult, StorageOptions, DbSharedOptions, QuerySchema, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, RecordUnknown, ShallowSimplify, ComputedOptionsConfig, QueryOrExpression, QueryData, IsQuery, TableDataFn, DbTableOptionScopes, QueryScopes, ColumnSchemaConfig, DbSqlMethod, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHook, QueryBeforeActionHook, QueryAfterHook, AfterHook, MergeQuery, QueryReturnType } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
3
|
|
|
4
4
|
interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends Column.Shape.QueryInit = Column.Shape.QueryInit> {
|
|
@@ -211,23 +211,32 @@ type OrchidORM<T extends TableClasses = TableClasses> = {
|
|
|
211
211
|
} & OrchidORMMethods;
|
|
212
212
|
interface OrchidORMMethods {
|
|
213
213
|
/**
|
|
214
|
-
* @see import('pqb').
|
|
214
|
+
* @see import('pqb').QueryTransaction.prototype.transaction
|
|
215
215
|
*/
|
|
216
216
|
$transaction: typeof transaction;
|
|
217
217
|
/**
|
|
218
|
-
* @see import('pqb').
|
|
218
|
+
* @see import('pqb').QueryTransaction.prototype.ensureTransaction
|
|
219
219
|
*/
|
|
220
220
|
$ensureTransaction: typeof ensureTransaction;
|
|
221
221
|
/**
|
|
222
|
-
* @see import('pqb').
|
|
222
|
+
* @see import('pqb').QueryTransaction.prototype.isInTransaction
|
|
223
223
|
*/
|
|
224
224
|
$isInTransaction: typeof isInTransaction;
|
|
225
225
|
/**
|
|
226
|
-
* @see import('pqb').
|
|
226
|
+
* @see import('pqb').QueryTransaction.prototype.afterCommit
|
|
227
227
|
*/
|
|
228
228
|
$afterCommit: typeof afterCommit;
|
|
229
|
-
$adapter: AdapterBase;
|
|
230
229
|
$qb: Db;
|
|
230
|
+
$adapterNotInTransaction: AdapterBase;
|
|
231
|
+
/**
|
|
232
|
+
* Adapter is a wrapper on top of `postgres-js`, `node-postgres`, or other db driver.
|
|
233
|
+
*
|
|
234
|
+
* When in transaction, returns a db adapter object for the transaction,
|
|
235
|
+
* returns a default adapter object otherwise.
|
|
236
|
+
*
|
|
237
|
+
* Treat the adapter as implementation detail and avoid accessing it directly.
|
|
238
|
+
*/
|
|
239
|
+
$getAdapter(): AdapterBase;
|
|
231
240
|
/**
|
|
232
241
|
* Use `$query` to perform raw SQL queries.
|
|
233
242
|
*
|
|
@@ -289,6 +298,22 @@ interface OrchidORMMethods {
|
|
|
289
298
|
* See {@link FromMethods.from}
|
|
290
299
|
*/
|
|
291
300
|
$from<Arg extends MaybeArray<FromArg<Query>>>(arg: Arg): FromResult<FromQuery, Arg>;
|
|
301
|
+
/**
|
|
302
|
+
* `$withOptions` supports overriding `log` and `schema`.
|
|
303
|
+
*
|
|
304
|
+
* - `log`: boolean, enables or disables logging in the scope of the callback.
|
|
305
|
+
* - `schema`: set a **default** schema, note that it does not override
|
|
306
|
+
* if you already have a schema set in the ORM config or for a specific table.
|
|
307
|
+
*
|
|
308
|
+
* ```ts
|
|
309
|
+
* await db.$withOptions({ log: true, schema: 'custom' }, async () => {
|
|
310
|
+
* // will log this query, and will use the custom schema for this table,
|
|
311
|
+
* // unless this table already has a configured schema.
|
|
312
|
+
* await db.table.find(123);
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
$withOptions<Result>(options: StorageOptions, cb: () => Promise<Result>): Promise<Result>;
|
|
292
317
|
$close(): Promise<void>;
|
|
293
318
|
}
|
|
294
319
|
type OrchidOrmParam<Options> = true | null extends true ? 'Set strict: true to tsconfig' : Options;
|
package/dist/index.js
CHANGED
|
@@ -2258,19 +2258,19 @@ const orchidORMWithAdapter = ({
|
|
|
2258
2258
|
noPrimaryKey
|
|
2259
2259
|
};
|
|
2260
2260
|
let adapter;
|
|
2261
|
-
let
|
|
2261
|
+
let asyncStorage;
|
|
2262
2262
|
let qb;
|
|
2263
2263
|
if ("db" in options) {
|
|
2264
2264
|
adapter = options.db.q.adapter;
|
|
2265
|
-
|
|
2265
|
+
asyncStorage = options.db.internal.asyncStorage;
|
|
2266
2266
|
qb = options.db.qb;
|
|
2267
2267
|
} else {
|
|
2268
2268
|
adapter = options.adapter;
|
|
2269
|
-
|
|
2269
|
+
asyncStorage = new node_async_hooks.AsyncLocalStorage();
|
|
2270
2270
|
qb = pqb._initQueryBuilder(
|
|
2271
2271
|
adapter,
|
|
2272
2272
|
pqb.makeColumnTypes(pqb.defaultSchemaConfig),
|
|
2273
|
-
|
|
2273
|
+
asyncStorage,
|
|
2274
2274
|
commonOptions,
|
|
2275
2275
|
options
|
|
2276
2276
|
);
|
|
@@ -2280,7 +2280,8 @@ const orchidORMWithAdapter = ({
|
|
|
2280
2280
|
$ensureTransaction: ensureTransaction,
|
|
2281
2281
|
$isInTransaction: isInTransaction,
|
|
2282
2282
|
$afterCommit: afterCommit,
|
|
2283
|
-
$
|
|
2283
|
+
$adapterNotInTransaction: adapter,
|
|
2284
|
+
$getAdapter,
|
|
2284
2285
|
$qb: qb,
|
|
2285
2286
|
get $query() {
|
|
2286
2287
|
return qb.query;
|
|
@@ -2290,7 +2291,8 @@ const orchidORMWithAdapter = ({
|
|
|
2290
2291
|
$withRecursive: qb.withRecursive.bind(qb),
|
|
2291
2292
|
$withSql: qb.withSql.bind(qb),
|
|
2292
2293
|
$from: qb.from.bind(qb),
|
|
2293
|
-
$close: adapter.close.bind(adapter)
|
|
2294
|
+
$close: adapter.close.bind(adapter),
|
|
2295
|
+
$withOptions: qb.withOptions.bind(qb)
|
|
2294
2296
|
};
|
|
2295
2297
|
const tableInstances = {};
|
|
2296
2298
|
for (const key in tables) {
|
|
@@ -2319,7 +2321,7 @@ const orchidORMWithAdapter = ({
|
|
|
2319
2321
|
table.table,
|
|
2320
2322
|
table.columns.shape,
|
|
2321
2323
|
table.types,
|
|
2322
|
-
|
|
2324
|
+
asyncStorage,
|
|
2323
2325
|
options2,
|
|
2324
2326
|
table.constructor.prototype.columns?.data ?? {}
|
|
2325
2327
|
);
|
|
@@ -2337,10 +2339,11 @@ const orchidORMWithAdapter = ({
|
|
|
2337
2339
|
Object.assign(result[key].baseQuery.q, table.q);
|
|
2338
2340
|
}
|
|
2339
2341
|
}
|
|
2340
|
-
const db = result;
|
|
2341
|
-
db.$adapter;
|
|
2342
2342
|
return result;
|
|
2343
2343
|
};
|
|
2344
|
+
function $getAdapter() {
|
|
2345
|
+
return this.$qb.$getAdapter();
|
|
2346
|
+
}
|
|
2344
2347
|
|
|
2345
2348
|
const createRepo = (table, methods) => {
|
|
2346
2349
|
const queryMethods = {
|