pqb 0.66.5 → 0.66.7

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
@@ -6483,7 +6483,7 @@ const setMutativeQueriesSelectRelationsSqlState = (d, as, rel) => {
6483
6483
  const handleInsertAndUpdateSelectRelationsSqlState = (ctx, state) => {
6484
6484
  if (state) ctx.topCtx.mutativeQueriesSelectRelationsSqlState = state;
6485
6485
  };
6486
- const handleDeleteSelectRelationsSqlState = (ctx, query, relationSelectState, returning) => {
6486
+ const handleDeleteSelectRelationsSqlState = (ctx, query, relationSelectState) => {
6487
6487
  const selectRelations = relationSelectState?.value;
6488
6488
  if (!selectRelations) return;
6489
6489
  const selectPrimaryKeysQuery = prepareSubQueryForSql(query, _clone(query));
@@ -6491,7 +6491,6 @@ const handleDeleteSelectRelationsSqlState = (ctx, query, relationSelectState, re
6491
6491
  _addToHookSelect(selectPrimaryKeysQuery, primaryKeys, true);
6492
6492
  const { as: cteAs } = moveQueryToCte(ctx, selectPrimaryKeysQuery, void 0, true);
6493
6493
  const relKeys = Object.keys(selectRelations);
6494
- ctx.selectedCount = (returning ? ctx.selectedCount : 0) + relKeys.length;
6495
6494
  const hookSelect = selectPrimaryKeysQuery.q.hookSelect;
6496
6495
  const join = {
6497
6496
  type: "JOIN",
@@ -6817,7 +6816,10 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
6817
6816
  q.q.select = [query.q.expr];
6818
6817
  ands.push(`(${moveMutativeQueryToCte(ctx, q)})`);
6819
6818
  }
6820
- else pushWhereToSql(ands, ctx, query, query.q, query.table && `"${query.table}"`, true);
6819
+ else {
6820
+ const as = getQueryAs(query);
6821
+ pushWhereToSql(ands, ctx, query, query.q, as && `"${as}"`, true);
6822
+ }
6821
6823
  return;
6822
6824
  }
6823
6825
  if (isExpression(data)) {
@@ -7381,7 +7383,7 @@ const pushDeleteSql = (ctx, query, q, quotedAs, isSubSql) => {
7381
7383
  if (q.as && query.table !== q.as) ctx.sql.push(quotedAs);
7382
7384
  const relationSelectState = newMutativeQueriesSelectRelationsSqlState(query);
7383
7385
  let returning = makeReturningSql(ctx, query, q, quotedAs, relationSelectState, "Delete", void 0, isSubSql);
7384
- const selectRelations = handleDeleteSelectRelationsSqlState(ctx, query, relationSelectState, returning);
7386
+ const selectRelations = handleDeleteSelectRelationsSqlState(ctx, query, relationSelectState);
7385
7387
  let join = q.join;
7386
7388
  if (selectRelations) {
7387
7389
  returning = (returning ? returning + ", " : "") + selectRelations.addReturning;
@@ -13028,12 +13030,14 @@ var QueryMethods = class {
13028
13030
  */
13029
13031
  makeHelper(fn) {
13030
13032
  const helperAs = this.q.as || this.table;
13031
- return ((query, ...args) => {
13033
+ const helper = ((query, ...args) => {
13032
13034
  const q = _clone(query);
13033
13035
  const as = _getQueryAs(q);
13034
13036
  if (as) _setQueryAlias(q, as, helperAs);
13035
13037
  return fn(q, ...args);
13036
13038
  });
13039
+ helper.table = this.table;
13040
+ return helper;
13037
13041
  }
13038
13042
  /**
13039
13043
  * `useHelper` allows to use {@link makeHelper} in different queries:
@@ -13624,6 +13628,12 @@ const _initQueryBuilder = (adapter, columnTypes, asyncStorage, commonOptions, op
13624
13628
  qb.internal.generatorIgnore = options.generatorIgnore;
13625
13629
  qb.internal.roles = options.roles;
13626
13630
  qb.internal.managedRolesSql = options.managedRolesSql;
13631
+ qb.internal.defaultGrantedBy = options.defaultGrantedBy;
13632
+ if (options.grants) qb.internal.grants = options.grants.map((grant) => ({
13633
+ ...grant,
13634
+ to: toArray(grant.to)
13635
+ }));
13636
+ qb.internal.rls = options.rls;
13627
13637
  return qb.qb = qb;
13628
13638
  };
13629
13639
  const getSetRoleSql = (parentRole, options) => {
@@ -13715,7 +13725,7 @@ var AdapterClass = class AdapterClass {
13715
13725
  }
13716
13726
  assignError(to, from) {
13717
13727
  const { errorFields } = this.driverAdapter;
13718
- for (const key in errorFields) to[key] = from[key];
13728
+ for (const key in errorFields) to[key] = from[errorFields[key]];
13719
13729
  }
13720
13730
  };
13721
13731
  /**
@@ -14221,6 +14231,6 @@ const testTransaction = {
14221
14231
  if (db.internal[trxForTest]?.length === 0) return db.q.adapter.close();
14222
14232
  }
14223
14233
  };
14224
- export { AdapterClass, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Column, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, Expression, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MoneyColumn, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, Operators, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryError, QueryHookUtils, QueryHooks, RawSql, RealColumn, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, TransactionAdapterClass, TsQueryColumn, TsVectorColumn, UUIDColumn, UnknownColumn, VarCharColumn, VirtualColumn, XMLColumn, _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, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
14234
+ export { AdapterClass, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Column, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, Expression, Grant, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MoneyColumn, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, Operators, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryError, QueryHookUtils, QueryHooks, RawSql, RealColumn, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, TransactionAdapterClass, TsQueryColumn, TsVectorColumn, UUIDColumn, UnknownColumn, VarCharColumn, VirtualColumn, XMLColumn, _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, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
14225
14235
 
14226
14236
  //# sourceMappingURL=index.mjs.map