orchid-orm 1.71.1 → 1.72.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,9 +1,10 @@
1
- import { DynamicRawSQL, QueryHooks, RawSql, VirtualColumn, _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, applyMixins, cloneQueryBaseUnscoped, defaultSchemaConfig, emptyArray, emptyObject, getCallerFilePath, getClonedQueryData, getColumnTypes, getFreeAlias, getPrimaryKeys, getQueryAs, getShapeFromSelect, getStackTrace, isExpression, isQueryReturnsAll, makeColumnTypes, noop, objectHasValues, parseTableData, pick, prepareSubQueryForSql, pushQueryOnForOuter, setQueryObjectValueImmutable, toArray, toSnakeCase } from "pqb/internal";
1
+ import { DynamicRawSQL, QueryHooks, RawSql, VirtualColumn, _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, applyMixins, cloneQueryBaseUnscoped, defaultSchemaConfig, emptyArray, emptyObject, getCallerFilePath, getClonedQueryData, getColumnTypes, getFreeAlias, getPrimaryKeys, getQueryAs, getShapeFromSelect, getStackTrace, internalSchemaConfig, isExpression, isQueryReturnsAll, makeColumnTypes, noop, objectHasValues, parseTableData, pick, prepareSubQueryForSql, pushQueryOnForOuter, setQueryObjectValueImmutable, toArray, toSnakeCase } from "pqb/internal";
2
2
  import { Db, NotFoundError, OrchidOrmInternalError } from "pqb";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  export * from "pqb";
5
5
  function createBaseTable({ schemaConfig = defaultSchemaConfig, columnTypes: columnTypesArg, snakeCase, filePath: filePathArg, nowSQL, exportAs = "BaseTable", language, autoForeignKeys } = {}) {
6
- const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(makeColumnTypes(schemaConfig)) : columnTypesArg || makeColumnTypes(schemaConfig);
6
+ const schema = schemaConfig();
7
+ const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(makeColumnTypes(schema)) : columnTypesArg || makeColumnTypes(schema);
7
8
  const filePathOrStack = filePathArg || getStackTrace();
8
9
  let filePath;
9
10
  const defaultColumns = {
@@ -33,27 +34,27 @@ function createBaseTable({ schemaConfig = defaultSchemaConfig, columnTypes: colu
33
34
  }
34
35
  static inputSchema() {
35
36
  this.instance();
36
- return this._inputSchema === void 0 ? this._inputSchema = schemaConfig.inputSchema.call(this) : this._inputSchema;
37
+ return this._inputSchema === void 0 ? this._inputSchema = schema.inputSchema.call(this) : this._inputSchema;
37
38
  }
38
39
  static outputSchema() {
39
40
  this.instance();
40
- return this._outputSchema === void 0 ? this._outputSchema = schemaConfig.outputSchema.call(this) : this._outputSchema;
41
+ return this._outputSchema === void 0 ? this._outputSchema = schema.outputSchema.call(this) : this._outputSchema;
41
42
  }
42
43
  static querySchema() {
43
44
  this.instance();
44
- return this._querySchema === void 0 ? this._querySchema = schemaConfig.querySchema.call(this) : this._querySchema;
45
+ return this._querySchema === void 0 ? this._querySchema = schema.querySchema.call(this) : this._querySchema;
45
46
  }
46
47
  static createSchema() {
47
48
  this.instance();
48
- return this._createSchema === void 0 ? this._createSchema = schemaConfig.createSchema.call(this) : this._createSchema;
49
+ return this._createSchema === void 0 ? this._createSchema = schema.createSchema.call(this) : this._createSchema;
49
50
  }
50
51
  static updateSchema() {
51
52
  this.instance();
52
- return this._updateSchema === void 0 ? this._updateSchema = schemaConfig.updateSchema.call(this) : this._updateSchema;
53
+ return this._updateSchema === void 0 ? this._updateSchema = schema.updateSchema.call(this) : this._updateSchema;
53
54
  }
54
55
  static pkeySchema() {
55
56
  this.instance();
56
- return this._pkeySchema === void 0 ? this._pkeySchema = schemaConfig.pkeySchema.call(this) : this._pkeySchema;
57
+ return this._pkeySchema === void 0 ? this._pkeySchema = schema.pkeySchema.call(this) : this._pkeySchema;
57
58
  }
58
59
  static getFilePath() {
59
60
  if (filePath) return filePath;
@@ -390,7 +391,7 @@ const makeBelongsToMethod = (tableConfig, table, relation, relationName, query)
390
391
  for (let i = 0; i < len; i++) obj[primaryKeys[i]] = params[foreignKeys[i]];
391
392
  return query.where(obj);
392
393
  },
393
- virtualColumn: new BelongsToVirtualColumn(defaultSchemaConfig, relationName, state),
394
+ virtualColumn: new BelongsToVirtualColumn(internalSchemaConfig, relationName, state),
394
395
  joinQuery: joinQueryChainHOF(getPrimaryKeys(query), reverseJoin, (joiningQuery, baseQuery) => join(baseQuery, joiningQuery, primaryKeys, foreignKeys)),
395
396
  reverseJoin
396
397
  };
@@ -632,7 +633,7 @@ const makeHasOneMethod = (tableConfig, table, relation, relationName, query) =>
632
633
  ...values
633
634
  });
634
635
  },
635
- virtualColumn: new HasOneVirtualColumn(defaultSchemaConfig, relationName, state),
636
+ virtualColumn: new HasOneVirtualColumn(internalSchemaConfig, relationName, state),
636
637
  joinQuery: joinQueryChainHOF(relPKeys, reverseJoin, (joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)),
637
638
  reverseJoin,
638
639
  modifyRelatedQuery(relationQuery) {
@@ -817,7 +818,7 @@ const makeHasManyMethod = (tableConfig, table, relation, relationName, query) =>
817
818
  ...values
818
819
  });
819
820
  },
820
- virtualColumn: new HasManyVirtualColumn(defaultSchemaConfig, relationName, state),
821
+ virtualColumn: new HasManyVirtualColumn(internalSchemaConfig, relationName, state),
821
822
  joinQuery: joinQueryChainHOF(relPKeys, reverseJoin, (joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)),
822
823
  reverseJoin,
823
824
  modifyRelatedQuery(relationQuery) {
@@ -1057,7 +1058,7 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
1057
1058
  });
1058
1059
  return on ? _queryDefaults(q, on) : q;
1059
1060
  },
1060
- virtualColumn: new HasAndBelongsToManyVirtualColumn(subQuery, defaultSchemaConfig, relationName, state),
1061
+ virtualColumn: new HasAndBelongsToManyVirtualColumn(subQuery, internalSchemaConfig, relationName, state),
1061
1062
  joinQuery: joinQueryChainHOF(getPrimaryKeys(query), reverseJoin, (joiningQuery, baseQuery) => joinQuery(joiningQuery, getQueryAs(baseQuery), getQueryAs(joiningQuery), {
1062
1063
  ...joiningQuery.q.joinedShapes,
1063
1064
  [baseQuery.q.as || baseQuery.table]: baseQuery.q.shape
@@ -1463,7 +1464,7 @@ const privateOrchidORMWithAdapter = ({ log, logger, autoPreparedStatements, noPr
1463
1464
  } else {
1464
1465
  adapter = options.adapter;
1465
1466
  asyncStorage = new AsyncLocalStorage();
1466
- qb = _initQueryBuilder(adapter, makeColumnTypes(defaultSchemaConfig), asyncStorage, commonOptions, options);
1467
+ qb = _initQueryBuilder(adapter, makeColumnTypes(defaultSchemaConfig(adapter.driverAdapter.schemaConfig)), asyncStorage, commonOptions, options);
1467
1468
  }
1468
1469
  qb.internal.rls = options.rls;
1469
1470
  const result = {