orchid-orm 1.24.6 → 1.25.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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { makeColumnTypes, defaultSchemaConfig, QueryHooks, getColumnTypes, _queryHookAfterCreate, _queryHookAfterUpdate, getQueryAs, setQueryObjectValue, pushQueryOn, VirtualColumn, pushQueryValue, _queryCreateMany, isQueryReturnsAll, _queryHookBeforeUpdate, _queryFindBy, _queryCreate, _queryRows, _queryUpdate, _queryDelete, _queryDefaults, _queryUpdateOrThrow, _queryWhere, toSQLCacheKey, _queryJoinOn, OrchidOrmInternalError, _queryCreateFrom, NotFoundError, _queryFindByOptional, _querySelect, _queryWhereExists, _queryTake, _queryTakeOptional, _queryAll, Adapter, Db, anyShape, addComputedColumns, getClonedQueryData } from 'pqb';
1
+ import { makeColumnTypes, defaultSchemaConfig, QueryHooks, getColumnTypes, getTableData, _queryHookAfterCreate, _queryHookAfterUpdate, getQueryAs, setQueryObjectValue, pushQueryOn, VirtualColumn, pushQueryValue, _queryCreateMany, isQueryReturnsAll, _queryHookBeforeUpdate, _queryFindBy, _queryCreate, _queryRows, _queryUpdate, _queryDelete, _queryDefaults, _queryUpdateOrThrow, _queryWhere, toSQLCacheKey, _queryJoinOn, OrchidOrmInternalError, _queryCreateFrom, NotFoundError, _queryFindByOptional, _querySelect, _queryWhereExists, _queryTake, _queryTakeOptional, _queryAll, Adapter, _initQueryBuilder, Db, addComputedColumns, getClonedQueryData } from 'pqb';
2
2
  export * from 'pqb';
3
3
  import { getStackTrace, applyMixins, getCallerFilePath, snakeCaseKey, toSnakeCase, emptyArray, objectHasValues, toArray } from 'orchid-core';
4
4
  export * from 'orchid-core';
@@ -74,6 +74,7 @@ function createBaseTable({
74
74
  setColumns(fn) {
75
75
  columnTypes[snakeCaseKey] = this.snakeCase;
76
76
  const shape = getColumnTypes(columnTypes, fn, nowSQL, this.language);
77
+ this.constructor.prototype.tableData = getTableData();
77
78
  if (this.snakeCase) {
78
79
  for (const key in shape) {
79
80
  const column = shape[key];
@@ -1085,8 +1086,9 @@ var __spreadValues$3 = (a, b) => {
1085
1086
  };
1086
1087
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1087
1088
  class HasAndBelongsToManyVirtualColumn extends VirtualColumn {
1088
- constructor(schema, key, state) {
1089
+ constructor(joinTable, schema, key, state) {
1089
1090
  super(schema);
1091
+ this.joinTable = joinTable;
1090
1092
  this.key = key;
1091
1093
  this.state = state;
1092
1094
  this.nestedInsert = nestedInsert(state);
@@ -1235,6 +1237,7 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
1235
1237
  });
1236
1238
  },
1237
1239
  virtualColumn: new HasAndBelongsToManyVirtualColumn(
1240
+ subQuery,
1238
1241
  defaultSchemaConfig,
1239
1242
  relationName,
1240
1243
  state
@@ -1813,6 +1816,7 @@ const orchidORM = (_a, tables) => {
1813
1816
  "autoPreparedStatements",
1814
1817
  "noPrimaryKey"
1815
1818
  ]);
1819
+ var _a2;
1816
1820
  const commonOptions = {
1817
1821
  log,
1818
1822
  logger,
@@ -1829,16 +1833,13 @@ const orchidORM = (_a, tables) => {
1829
1833
  } else {
1830
1834
  adapter = "adapter" in options ? options.adapter : new Adapter(options);
1831
1835
  transactionStorage = new AsyncLocalStorage();
1832
- qb = new Db(
1836
+ qb = _initQueryBuilder(
1833
1837
  adapter,
1834
- void 0,
1835
- void 0,
1836
- anyShape,
1837
1838
  makeColumnTypes(defaultSchemaConfig),
1838
1839
  transactionStorage,
1839
- commonOptions
1840
+ commonOptions,
1841
+ options
1840
1842
  );
1841
- qb.queryBuilder = qb;
1842
1843
  }
1843
1844
  const result = {
1844
1845
  $transaction: transaction,
@@ -1861,10 +1862,10 @@ const orchidORM = (_a, tables) => {
1861
1862
  language: table.language,
1862
1863
  scopes: table.scopes,
1863
1864
  softDelete: table.softDelete,
1864
- snakeCase: table.snakeCase
1865
+ snakeCase: table.snakeCase,
1866
+ comment: table.comment,
1867
+ noPrimaryKey: table.noPrimaryKey ? "ignore" : void 0
1865
1868
  });
1866
- if (table.noPrimaryKey)
1867
- options2.noPrimaryKey = "ignore";
1868
1869
  const dbTable = new Db(
1869
1870
  adapter,
1870
1871
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1873,7 +1874,8 @@ const orchidORM = (_a, tables) => {
1873
1874
  table.columns,
1874
1875
  table.types,
1875
1876
  transactionStorage,
1876
- options2
1877
+ options2,
1878
+ (_a2 = table.constructor.prototype.tableData) != null ? _a2 : {}
1877
1879
  );
1878
1880
  dbTable.definedAs = key;
1879
1881
  dbTable.db = result;