orchid-orm 1.56.4 → 1.57.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, QueryHooks, defaultSchemaConfig, raw, getColumnTypes, parseTableData, _queryHookAfterCreate, _queryHookAfterUpdate, getQueryAs, setQueryObjectValueImmutable, pushQueryOnForOuter, cloneQueryBaseUnscoped, DynamicRawSQL, RawSQL, getShapeFromSelect, _queryWhere, _queryDefaults, VirtualColumn, _queryCreateMany, isQueryReturnsAll, _queryHookBeforeUpdate, _queryFindBy, _queryCreate, _queryRows, _queryUpdate, _queryDelete, _queryUpdateOrThrow, _queryJoinOn, _queryCreateFrom, _queryFindByOptional, _querySelect, _queryWhereExists, _queryTake, _queryTakeOptional, _initQueryBuilder, Db, getClonedQueryData } from 'pqb';
1
+ import { makeColumnTypes, QueryHooks, defaultSchemaConfig, raw, getColumnTypes, parseTableData, _queryHookAfterCreate, _queryHookAfterUpdate, getQueryAs, setQueryObjectValueImmutable, pushQueryOnForOuter, cloneQueryBaseUnscoped, DynamicRawSQL, RawSQL, getShapeFromSelect, _queryWhere, _queryDefaults, VirtualColumn, _queryCreateMany, isQueryReturnsAll, _queryHookBeforeUpdate, _queryFindBy, _queryCreate, _queryRows, _queryUpdate, _queryDelete, _queryUpdateOrThrow, _queryJoinOn, _queryCreateManyFrom, _queryFindByOptional, _querySelect, _queryWhereExists, _queryTake, _queryTakeOptional, _initQueryBuilder, Db, getClonedQueryData } from 'pqb';
2
2
  export * from 'pqb';
3
3
  import { getStackTrace, applyMixins, getCallerFilePath, snakeCaseKey, toSnakeCase, emptyObject, emptyArray, isExpression, getPrimaryKeys, pushQueryValueImmutable, OrchidOrmInternalError, toArray, objectHasValues, NotFoundError, pick } from 'orchid-core';
4
4
  export * from 'orchid-core';
@@ -858,7 +858,8 @@ const makeHasOneMethod = (tableConfig, table, relation, relationName, query) =>
858
858
  const baseQuery = query2.clone();
859
859
  baseQuery.q.select = fromQuerySelect;
860
860
  const q = relationQuery.q;
861
- q.values = { from: baseQuery };
861
+ q.insertFrom = baseQuery;
862
+ q.values = [];
862
863
  };
863
864
  }
864
865
  };
@@ -1135,7 +1136,8 @@ const makeHasManyMethod = (tableConfig, table, relation, relationName, query) =>
1135
1136
  const baseQuery = query2.clone();
1136
1137
  baseQuery.q.select = fromQuerySelect;
1137
1138
  const q = relationQuery.q;
1138
- q.values = { from: baseQuery };
1139
+ q.insertFrom = baseQuery;
1140
+ q.values = [];
1139
1141
  };
1140
1142
  }
1141
1143
  };
@@ -1531,19 +1533,16 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
1531
1533
  relationQuery,
1532
1534
  [],
1533
1535
  async (result) => {
1534
- if (result.length > 1) {
1535
- throw new OrchidOrmInternalError(
1536
- relationQuery,
1537
- "Creating multiple `hasAndBelongsToMany` records is not yet supported"
1538
- );
1539
- }
1540
1536
  const baseQuery2 = ref.q.clone();
1541
1537
  baseQuery2.q.select = selectPrimaryKeysAsForeignKeys;
1542
- const data = {};
1543
- for (let i = 0; i < throughLen; i++) {
1544
- data[throughForeignKeys[i]] = result[0][throughPrimaryKeys[i]];
1545
- }
1546
- const createdCount = await _queryCreateFrom(
1538
+ const data = result.map((resultRow) => {
1539
+ const dataRow = {};
1540
+ for (let i = 0; i < throughLen; i++) {
1541
+ dataRow[throughForeignKeys[i]] = resultRow[throughPrimaryKeys[i]];
1542
+ }
1543
+ return dataRow;
1544
+ });
1545
+ const createdCount = await _queryCreateManyFrom(
1547
1546
  subQuery.count(),
1548
1547
  baseQuery2,
1549
1548
  data
@@ -1819,7 +1818,7 @@ const nestedUpdate = (state) => {
1819
1818
  ...state.throughForeignKeys
1820
1819
  ];
1821
1820
  try {
1822
- const count = await state.joinTableQuery.insertManyFrom(
1821
+ const count = await state.joinTableQuery.insertForEachFrom(
1823
1822
  _querySelect(
1824
1823
  state.relatedTableQuery.whereOneOf(...relatedWheres),
1825
1824
  [