orchid-orm 1.55.1 → 1.56.3

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,6 +1,6 @@
1
- import { TableData, Query, SelectableFromShape, CreateMethodsNames, CreateData, CreateBelongsToData, AddQueryDefaults, QueryTake, QueryTakeOptional, UpdateData, WhereArg, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, Adapter, FromArg, FromResult, AdapterOptions, DbSharedOptions, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, ComputedOptionsConfig, QueryData, TableDataFn, DbTableOptionScopes, RawSQL, DynamicRawSQL, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHookInternal, QueryAfterHook, AfterHook, WhereResult, MergeQuery } from 'pqb';
1
+ import { TableData, Query, SelectableFromShape, CreateMethodsNames, CreateData, CreateBelongsToData, AddQueryDefaults, QueryTake, QueryTakeOptional, UpdateData, WhereArg, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, FromArg, FromResult, DbSharedOptions, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, ComputedOptionsConfig, QueryData, TableDataFn, DbTableOptionScopes, RawSQL, DynamicRawSQL, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHookInternal, QueryAfterHook, AfterHook, WhereResult, MergeQuery } from 'pqb';
2
2
  export * from 'pqb';
3
- import { ColumnsShapeBase, ColumnShapeInputPartial, RelationConfigBase, EmptyObject, MaybeArray, AfterCommitStandaloneHook, RelationsBase, RecordUnknown, ShallowSimplify, ColumnShapeOutput, DefaultSelectColumns, QueryOrExpression, QueryColumn, ColumnShapeInput, IsQuery, CoreQueryScopes, ColumnSchemaConfig, StaticSQLArgs, DynamicSQLArg, QueryColumns, QueryReturnType } from 'orchid-core';
3
+ import { ColumnsShapeBase, ColumnShapeInputPartial, RelationConfigBase, EmptyObject, MaybeArray, AfterCommitStandaloneHook, AdapterBase, RelationsBase, RecordUnknown, ShallowSimplify, ColumnShapeOutput, DefaultSelectColumns, QueryOrExpression, QueryColumn, ColumnShapeInput, IsQuery, CoreQueryScopes, ColumnSchemaConfig, StaticSQLArgs, DynamicSQLArg, QueryColumns, QueryReturnType } from 'orchid-core';
4
4
  export * from 'orchid-core';
5
5
 
6
6
  interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends ColumnsShapeBase = ColumnsShapeBase> {
@@ -231,7 +231,7 @@ type OrchidORM<T extends TableClasses = TableClasses> = {
231
231
  * @see import('pqb').Transaction.prototype.afterCommit
232
232
  */
233
233
  $afterCommit: typeof afterCommit;
234
- $adapter: Adapter;
234
+ $adapter: AdapterBase;
235
235
  $qb: Db;
236
236
  /**
237
237
  * Use `$query` to perform raw SQL queries.
@@ -296,12 +296,12 @@ type OrchidORM<T extends TableClasses = TableClasses> = {
296
296
  $from<Arg extends MaybeArray<FromArg<Query>>>(arg: Arg): FromResult<FromQuery, Arg>;
297
297
  $close(): Promise<void>;
298
298
  };
299
- type OrchidOrmArg = true | null extends true ? 'Set strict: true to tsconfig' : ({
299
+ type OrchidOrmParam<Options> = true | null extends true ? 'Set strict: true to tsconfig' : Options;
300
+ declare const orchidORMWithAdapter: <T extends TableClasses>({ log, logger, autoPreparedStatements, noPrimaryKey, ...options }: OrchidOrmParam<({
300
301
  db: Query;
301
302
  } | {
302
- adapter: Adapter;
303
- } | Omit<AdapterOptions, 'log'>) & DbSharedOptions;
304
- declare const orchidORM: <T extends TableClasses>({ log, logger, autoPreparedStatements, noPrimaryKey, ...options }: OrchidOrmArg, tables: T) => OrchidORM<T>;
303
+ adapter: AdapterBase;
304
+ }) & DbSharedOptions>, tables: T) => OrchidORM<T>;
305
305
 
306
306
  interface HasAndBelongsToMany extends RelationThunkBase {
307
307
  type: 'hasAndBelongsToMany';
@@ -729,4 +729,4 @@ declare const createRepo: <T extends Query, Methods extends MethodsBase<T>>(tabl
729
729
  shape: T['shape'];
730
730
  }>(q: Q) => Query & Q & MapMethods<T, Methods>) & T, Methods>;
731
731
 
732
- export { type BaseTableClass, type BaseTableInstance, type DefaultSelect, type Insertable, type MapMethods, type MapQueryMethods, type MethodsBase, type ORMTableInput, type ORMTableInputToQueryBuilder, type OrchidORM, type Queryable, type Repo, type Selectable, type SetColumnsResult, type Table, type TableClass, type TableClasses, type TableInfo, type TableToDb, type Updatable, createBaseTable, createRepo, orchidORM };
732
+ export { type BaseTableClass, type BaseTableInstance, type DefaultSelect, type Insertable, type MapMethods, type MapQueryMethods, type MethodsBase, type ORMTableInput, type ORMTableInputToQueryBuilder, type OrchidORM, type OrchidOrmParam, type Queryable, type Repo, type Selectable, type SetColumnsResult, type Table, type TableClass, type TableClasses, type TableInfo, type TableToDb, type Updatable, createBaseTable, createRepo, orchidORMWithAdapter };
package/dist/index.js CHANGED
@@ -615,9 +615,10 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
615
615
  }
616
616
  }
617
617
  if (loadPrimaryKeys) {
618
- const record = await pqb._queryFindBy(query.select(...loadPrimaryKeys), [
618
+ const record = await pqb._queryFindBy(
619
+ query.select(...loadPrimaryKeys),
619
620
  params.set
620
- ]);
621
+ );
621
622
  for (let i = 0, len2 = loadPrimaryKeys.length; i < len2; i++) {
622
623
  update[loadForeignKeys[i]] = record[loadPrimaryKeys[i]];
623
624
  }
@@ -644,7 +645,9 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
644
645
  }
645
646
  });
646
647
  const { upsert } = params;
647
- if (upsert || params.update || params.delete) ;
648
+ if (upsert || params.update || params.delete) {
649
+ selectIfNotSelected(q, foreignKeys);
650
+ }
648
651
  if (upsert) {
649
652
  (state.queries ?? (state.queries = [])).push(async (queryResult) => {
650
653
  const row = queryResult.rows[0];
@@ -1635,9 +1638,10 @@ const nestedInsert = ({
1635
1638
  for (const [, { connect }] of items) {
1636
1639
  for (const item of connect) {
1637
1640
  queries.push(
1638
- pqb._queryFindBy(t.select(...throughPrimaryKeys), [
1641
+ pqb._queryFindBy(
1642
+ t.select(...throughPrimaryKeys),
1639
1643
  item
1640
- ])
1644
+ )
1641
1645
  );
1642
1646
  }
1643
1647
  }
@@ -1657,9 +1661,10 @@ const nestedInsert = ({
1657
1661
  for (const [, { connectOrCreate }] of items) {
1658
1662
  for (const item of connectOrCreate) {
1659
1663
  queries.push(
1660
- pqb._queryFindByOptional(t.select(...throughPrimaryKeys), [
1664
+ pqb._queryFindByOptional(
1665
+ t.select(...throughPrimaryKeys),
1661
1666
  item.where
1662
- ])
1667
+ )
1663
1668
  );
1664
1669
  }
1665
1670
  }
@@ -2065,7 +2070,7 @@ function afterCommit(hook) {
2065
2070
  this.$qb.afterCommit(hook);
2066
2071
  }
2067
2072
 
2068
- const orchidORM = ({
2073
+ const orchidORMWithAdapter = ({
2069
2074
  log,
2070
2075
  logger,
2071
2076
  autoPreparedStatements,
@@ -2086,7 +2091,7 @@ const orchidORM = ({
2086
2091
  transactionStorage = options.db.internal.transactionStorage;
2087
2092
  qb = options.db.qb;
2088
2093
  } else {
2089
- adapter = "adapter" in options ? options.adapter : new pqb.Adapter(options);
2094
+ adapter = options.adapter;
2090
2095
  transactionStorage = new node_async_hooks.AsyncLocalStorage();
2091
2096
  qb = pqb._initQueryBuilder(
2092
2097
  adapter,
@@ -2197,7 +2202,7 @@ const createRepo = (table, methods) => {
2197
2202
 
2198
2203
  exports.createBaseTable = createBaseTable;
2199
2204
  exports.createRepo = createRepo;
2200
- exports.orchidORM = orchidORM;
2205
+ exports.orchidORMWithAdapter = orchidORMWithAdapter;
2201
2206
  Object.keys(pqb).forEach(function (k) {
2202
2207
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2203
2208
  enumerable: true,