orchid-orm 1.50.4 → 1.51.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
@@ -89,7 +89,7 @@ function createBaseTable({
89
89
  setColumns(fn, dataFn) {
90
90
  columnTypes[snakeCaseKey] = this.snakeCase;
91
91
  const shape = getColumnTypes(columnTypes, fn, nowSQL, this.language);
92
- const tableData = this.constructor.prototype.tableData = parseTableData(dataFn);
92
+ const tableData = parseTableData(dataFn);
93
93
  if (this.snakeCase) {
94
94
  for (const key in shape) {
95
95
  const column = shape[key];
@@ -148,10 +148,10 @@ function createBaseTable({
148
148
  }
149
149
 
150
150
  const getThroughRelation = (table, through) => {
151
- return table.relations[through]?.relationConfig;
151
+ return table.relations[through];
152
152
  };
153
153
  const getSourceRelation = (throughRelation, source) => {
154
- return throughRelation.query.relations[source]?.relationConfig;
154
+ return throughRelation.query.relations[source];
155
155
  };
156
156
  const hasRelationHandleCreate = (q, ctx, item, rowIndex, key, primaryKeys, nestedInsert) => {
157
157
  const value = item[key];
@@ -297,7 +297,8 @@ const joinQueryChainHOF = (relPKeys, reverseJoin, joinQuery) => (joiningQuery, b
297
297
  return joinQuery(jq, baseQuery);
298
298
  }
299
299
  const last = chain[chain.length - 1];
300
- const query = "relationConfig" in last ? last.relationConfig.joinQuery(last, baseQuery) : last;
300
+ const prev = chain[chain.length - 2];
301
+ const query = prev.rel.joinQuery(last.query, baseQuery);
301
302
  let useWhereExist = true;
302
303
  if (jq.q.returnType !== "value" && jq.q.returnType !== "valueOrThrow") {
303
304
  let tablePrefix;
@@ -1958,7 +1959,7 @@ const applyRelations = (qb, tables, result) => {
1958
1959
  let message = `Cannot define a \`${item.relationName}\` relation on \`${as}\``;
1959
1960
  const table = result[as];
1960
1961
  const { through, source } = relation.options;
1961
- const throughRel = table.relations[through]?.relationConfig;
1962
+ const throughRel = table.relations[through];
1962
1963
  if (through && !throughRel) {
1963
1964
  message += `: cannot find \`${through}\` relation required by the \`through\` option`;
1964
1965
  } else if (source && throughRel && !throughRel.table.relations[source]) {
@@ -2033,7 +2034,7 @@ const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTabl
2033
2034
  return q;
2034
2035
  }
2035
2036
  };
2036
- baseQuery.relationConfig = {
2037
+ dbTable.relations[relationName] = {
2037
2038
  table: otherDbTable,
2038
2039
  query,
2039
2040
  queryRelated: data.queryRelated,
@@ -2041,7 +2042,7 @@ const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTabl
2041
2042
  reverseJoin: data.reverseJoin,
2042
2043
  modifyRelatedQuery: data.modifyRelatedQuery
2043
2044
  };
2044
- dbTable.relations[relationName] = query;
2045
+ (dbTable.relationQueries ?? (dbTable.relationQueries = {}))[relationName] = query;
2045
2046
  const tableRelations = delayedRelations.get(dbTable);
2046
2047
  if (!tableRelations) return;
2047
2048
  tableRelations[relationName]?.forEach((data2) => {
@@ -2050,19 +2051,19 @@ const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTabl
2050
2051
  };
2051
2052
 
2052
2053
  function transaction(fnOrOptions, fn) {
2053
- return this.$queryBuilder.transaction(
2054
+ return this.$qb.transaction(
2054
2055
  fnOrOptions,
2055
2056
  fn
2056
2057
  );
2057
2058
  }
2058
2059
  function ensureTransaction(cb) {
2059
- return this.$queryBuilder.ensureTransaction(cb);
2060
+ return this.$qb.ensureTransaction(cb);
2060
2061
  }
2061
2062
  function isInTransaction() {
2062
- return this.$queryBuilder.isInTransaction();
2063
+ return this.$qb.isInTransaction();
2063
2064
  }
2064
2065
  function afterCommit(hook) {
2065
- this.$queryBuilder.afterCommit(hook);
2066
+ this.$qb.afterCommit(hook);
2066
2067
  }
2067
2068
 
2068
2069
  const orchidORM = ({
@@ -2084,7 +2085,7 @@ const orchidORM = ({
2084
2085
  if ("db" in options) {
2085
2086
  adapter = options.db.q.adapter;
2086
2087
  transactionStorage = options.db.internal.transactionStorage;
2087
- qb = options.db.queryBuilder;
2088
+ qb = options.db.qb;
2088
2089
  } else {
2089
2090
  adapter = "adapter" in options ? options.adapter : new Adapter(options);
2090
2091
  transactionStorage = new AsyncLocalStorage();
@@ -2102,8 +2103,10 @@ const orchidORM = ({
2102
2103
  $isInTransaction: isInTransaction,
2103
2104
  $afterCommit: afterCommit,
2104
2105
  $adapter: adapter,
2105
- $queryBuilder: qb,
2106
- $query: (...args) => qb.query(...args),
2106
+ $qb: qb,
2107
+ get $query() {
2108
+ return qb.query;
2109
+ },
2107
2110
  $queryArrays: (...args) => qb.queryArrays(...args),
2108
2111
  $with: qb.with.bind(qb),
2109
2112
  $withRecursive: qb.withRecursive.bind(qb),
@@ -2140,7 +2143,7 @@ const orchidORM = ({
2140
2143
  table.types,
2141
2144
  transactionStorage,
2142
2145
  options2,
2143
- table.constructor.prototype.tableData ?? {}
2146
+ table.constructor.prototype.columns?.data ?? {}
2144
2147
  );
2145
2148
  dbTable.definedAs = key;
2146
2149
  dbTable.db = result;