orchid-orm 1.65.1 → 1.66.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 CHANGED
@@ -1,4 +1,5 @@
1
- import { Column, TableData, ColumnsShape, Query, RelationConfigBase, QueryManyTake, QueryManyTakeOptional, EmptyObject, CreateData, UpdateData, WhereArg, SelectableFromShape, CreateManyMethodsNames, QueryHasWhere, CreateMethodsNames, MaybeArray, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, AfterCommitStandaloneHook, AdapterBase, FromArg, FromResult, StorageOptions, DbSharedOptions, QuerySchema, ColumnSchemaConfig, DbSqlMethod, TableDataItem, QueryData, IsQuery, TableDataFn, ComputedOptionsFactory, DbTableOptionScopes, QueryScopes, RecordUnknown, QueryBeforeHook, QueryAfterHook, QueryBeforeActionHook, AfterHook, ShallowSimplify, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, ComputedOptionsConfig, QueryOrExpression, DefaultSchemaConfig, DefaultColumnTypes, QueryReturnType, MergeQuery } from 'pqb/internal';
1
+ import { Column, TableData, ColumnsShape, Query, RelationConfigBase, QueryManyTake, QueryManyTakeOptional, EmptyObject, CreateData, UpdateData, WhereArg, SelectableFromShape, CreateManyMethodsNames, QueryHasWhere, CreateMethodsNames, MaybeArray, JoinQueryMethod, DeleteMethodsNames, IsolationLevel, TransactionOptions, AfterCommitStandaloneHook, AdapterBase, FromArg, FromResult, StorageOptions, DbSharedOptions, ColumnSchemaConfig, DbSqlMethod, TableDataItem, QueryData, IsQuery, TableDataFn, ComputedOptionsFactory, DbTableOptionScopes, QueryScopes, RecordUnknown, QueryBeforeHook, QueryAfterHook, QueryBeforeActionHook, AfterHook, ShallowSimplify, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, ComputedOptionsConfig, QueryOrExpression, DefaultSchemaConfig, DefaultColumnTypes, QueryReturnType, MergeQuery } from 'pqb/internal';
2
+ import { Db, QuerySchema } from 'pqb';
2
3
  export * from 'pqb';
3
4
 
4
5
  interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends Column.Shape.QueryInit = Column.Shape.QueryInit> {
@@ -299,11 +300,45 @@ interface OrchidORMMethods {
299
300
  */
300
301
  $from<Arg extends MaybeArray<FromArg<Query>>>(arg: Arg): FromResult<FromQuery, Arg>;
301
302
  /**
302
- * `$withOptions` supports overriding `log` and `schema`.
303
+ * `$withOptions` supports overriding `log`, `schema`, `role`, and `setConfig`.
303
304
  *
304
305
  * - `log`: boolean, enables or disables logging in the scope of the callback.
305
306
  * - `schema`: set a **default** schema, note that it does not override
306
307
  * if you already have a schema set in the ORM config or for a specific table.
308
+ * - `role`: string, switches the Postgres role for the duration of the callback.
309
+ * Used for row-level security policies.
310
+ * - `setConfig`: object with string, number, or boolean values, sets Postgres custom
311
+ * settings for the duration of the callback. Use dotted names like `app.tenant_id`.
312
+ * Values are normalized to strings internally.
313
+ *
314
+ * SQL session options (`role` and `setConfig`) cannot be nested.
315
+ * If an outer scope already has `role` or `setConfig`, attempting to set them again
316
+ * in a nested `$withOptions` call will throw an error.
317
+ * Nested scopes that only change `log` or `schema` will inherit the outer SQL session context.
318
+ *
319
+ * Explicit transactions inside the callback inherit the same SQL session context:
320
+ *
321
+ * ```ts
322
+ * await db.$withOptions(
323
+ * {
324
+ * role: 'app_user',
325
+ * setConfig: {
326
+ * 'app.tenant_id': tenantId,
327
+ * 'app.user_id': userId,
328
+ * },
329
+ * },
330
+ * async () => {
331
+ * const project = await db.project.find(projectId);
332
+ *
333
+ * await db.$transaction(async () => {
334
+ * // This query runs in the transaction with the same role and config
335
+ * await db.project.find(projectId).update({ lastViewedAt: new Date() });
336
+ * });
337
+ * },
338
+ * );
339
+ * ```
340
+ *
341
+ * Basic usage with `log` and `schema`:
307
342
  *
308
343
  * ```ts
309
344
  * await db.$withOptions({ log: true, schema: 'custom' }, async () => {
package/dist/index.js CHANGED
@@ -144,6 +144,7 @@ function createBaseTable({
144
144
  internal.applyMixins(base, [internal.QueryHooks]);
145
145
  base.prototype.types = columnTypes;
146
146
  base.prototype.snakeCase = snakeCase;
147
+ base.prototype.language = language;
147
148
  base.prototype.autoForeignKeys = autoForeignKeys === true ? {} : autoForeignKeys || void 0;
148
149
  return base;
149
150
  }
@@ -2319,7 +2320,7 @@ const orchidORMWithAdapter = ({
2319
2320
  computed: table.computed,
2320
2321
  nowSQL: tableClass.nowSQL
2321
2322
  };
2322
- const dbTable = new internal.Db(
2323
+ const dbTable = new pqb.Db(
2323
2324
  adapter,
2324
2325
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2325
2326
  qb,