pqb 0.40.1 → 0.40.2

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
@@ -919,7 +919,7 @@ const makeVarArg = (_op) => {
919
919
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
920
920
  );
921
921
  };
922
- const quoteValue$1 = (arg, ctx, quotedAs, jsonArray) => {
922
+ const quoteValue = (arg, ctx, quotedAs, jsonArray) => {
923
923
  if (arg && typeof arg === "object") {
924
924
  if (!jsonArray && Array.isArray(arg)) {
925
925
  return `(${arg.map((value) => addValue(ctx.values, value)).join(", ")})`;
@@ -951,16 +951,16 @@ const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
951
951
  };
952
952
  const base = {
953
953
  equals: make(
954
- (key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue$1(value, ctx, quotedAs)}`
954
+ (key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue(value, ctx, quotedAs)}`
955
955
  ),
956
956
  not: make(
957
- (key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue$1(value, ctx, quotedAs)}`
957
+ (key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue(value, ctx, quotedAs)}`
958
958
  ),
959
959
  in: make(
960
- (key, value, ctx, quotedAs) => `${key} IN ${quoteValue$1(value, ctx, quotedAs)}`
960
+ (key, value, ctx, quotedAs) => `${key} IN ${quoteValue(value, ctx, quotedAs)}`
961
961
  ),
962
962
  notIn: make(
963
- (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue$1(value, ctx, quotedAs)}`
963
+ (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
964
964
  )
965
965
  };
966
966
  const boolean = __spreadProps$b(__spreadValues$k({}, base), {
@@ -973,19 +973,19 @@ const boolean = __spreadProps$b(__spreadValues$k({}, base), {
973
973
  });
974
974
  const numeric = __spreadProps$b(__spreadValues$k({}, base), {
975
975
  lt: make(
976
- (key, value, ctx, quotedAs) => `${key} < ${quoteValue$1(value, ctx, quotedAs)}`
976
+ (key, value, ctx, quotedAs) => `${key} < ${quoteValue(value, ctx, quotedAs)}`
977
977
  ),
978
978
  lte: make(
979
- (key, value, ctx, quotedAs) => `${key} <= ${quoteValue$1(value, ctx, quotedAs)}`
979
+ (key, value, ctx, quotedAs) => `${key} <= ${quoteValue(value, ctx, quotedAs)}`
980
980
  ),
981
981
  gt: make(
982
- (key, value, ctx, quotedAs) => `${key} > ${quoteValue$1(value, ctx, quotedAs)}`
982
+ (key, value, ctx, quotedAs) => `${key} > ${quoteValue(value, ctx, quotedAs)}`
983
983
  ),
984
984
  gte: make(
985
- (key, value, ctx, quotedAs) => `${key} >= ${quoteValue$1(value, ctx, quotedAs)}`
985
+ (key, value, ctx, quotedAs) => `${key} >= ${quoteValue(value, ctx, quotedAs)}`
986
986
  ),
987
987
  between: make(
988
- (key, [from, to], ctx, quotedAs) => `${key} BETWEEN ${quoteValue$1(from, ctx, quotedAs)} AND ${quoteValue$1(
988
+ (key, [from, to], ctx, quotedAs) => `${key} BETWEEN ${quoteValue(from, ctx, quotedAs)} AND ${quoteValue(
989
989
  to,
990
990
  ctx,
991
991
  quotedAs
@@ -1039,10 +1039,10 @@ const json = __spreadProps$b(__spreadValues$k({}, base), {
1039
1039
  { _op: jsonPathQueryOp }
1040
1040
  ),
1041
1041
  jsonSupersetOf: make(
1042
- (key, value, ctx, quotedAs) => `${key} @> ${quoteValue$1(value, ctx, quotedAs, true)}`
1042
+ (key, value, ctx, quotedAs) => `${key} @> ${quoteValue(value, ctx, quotedAs, true)}`
1043
1043
  ),
1044
1044
  jsonSubsetOf: make(
1045
- (key, value, ctx, quotedAs) => `${key} <@ ${quoteValue$1(value, ctx, quotedAs, true)}`
1045
+ (key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs, true)}`
1046
1046
  ),
1047
1047
  jsonSet: makeVarArg(
1048
1048
  (key, [path, value], ctx) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${addValue(
@@ -3180,25 +3180,26 @@ const defaultSchemaConfig = {
3180
3180
  timestamp: (precision) => new TimestampTZColumn(defaultSchemaConfig, precision)
3181
3181
  };
3182
3182
 
3183
- const quoteValue = (value, nested = false) => {
3183
+ const escape = (value, migration, nested) => {
3184
3184
  const type = typeof value;
3185
3185
  if (type === "number" || type === "bigint")
3186
3186
  return String(value);
3187
3187
  else if (type === "string")
3188
- return quoteString(value);
3188
+ return escapeString(value);
3189
3189
  else if (type === "boolean")
3190
3190
  return value ? "true" : "false";
3191
3191
  else if (value instanceof Date)
3192
3192
  return `'${value.toISOString()}'`;
3193
3193
  else if (Array.isArray(value))
3194
- return `${nested ? "" : "ARRAY"}[${value.map((el) => quoteValue(el, true)).join(",")}]`;
3194
+ return migration && nested && !value.length ? "" : (migration ? "{" : nested ? "[" : "ARRAY[") + value.map((el) => escape(el, migration, true)).join(",") + (migration ? "}" : "]");
3195
3195
  else if (value === null || value === void 0)
3196
3196
  return "NULL";
3197
3197
  else
3198
- return quoteString(JSON.stringify(value));
3198
+ return escapeString(JSON.stringify(value));
3199
3199
  };
3200
- const quote = (value) => quoteValue(value);
3201
- const quoteString = (value) => `'${value.replaceAll("'", "''")}'`;
3200
+ const escapeForLog = (value) => escape(value);
3201
+ const escapeForMigration = (value) => escape(value, true);
3202
+ const escapeString = (value) => `'${value.replaceAll("'", "''")}'`;
3202
3203
 
3203
3204
  const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values) => {
3204
3205
  const elapsed = process.hrtime(time);
@@ -3207,7 +3208,7 @@ const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values
3207
3208
  if (!(values == null ? void 0 : values.length)) {
3208
3209
  return result;
3209
3210
  }
3210
- const formattedValues = `[${values.map(quote).join(", ")}]`;
3211
+ const formattedValues = `[${values.map(escapeForLog).join(", ")}]`;
3211
3212
  return `${result} ${colors ? valuesColor(formattedValues) : formattedValues}`;
3212
3213
  };
3213
3214
  const logParamToLogObject = (logger, log) => {
@@ -4240,7 +4241,7 @@ const addParserForSelectItem = (q, as, key, arg) => {
4240
4241
  let returnType = originalReturnType;
4241
4242
  const { hookSelect } = query;
4242
4243
  const batches = [];
4243
- let last = path.length;
4244
+ const last = path.length;
4244
4245
  if (returnType === "value" || returnType === "valueOrThrow") {
4245
4246
  if (hookSelect) {
4246
4247
  batches.push = (item) => {
@@ -4250,8 +4251,6 @@ const addParserForSelectItem = (q, as, key, arg) => {
4250
4251
  batches.push = Array.prototype.push;
4251
4252
  return batches.push(item);
4252
4253
  };
4253
- } else {
4254
- last--;
4255
4254
  }
4256
4255
  }
4257
4256
  collectNestedSelectBatches(batches, rows, path, last);
@@ -4312,19 +4311,19 @@ const addParserForSelectItem = (q, as, key, arg) => {
4312
4311
  const parse = (_b2 = query.parsers) == null ? void 0 : _b2[getValueKey];
4313
4312
  if (parse) {
4314
4313
  if (returnType === "value") {
4315
- for (const { data } of batches) {
4316
- data[key] = data[key] === void 0 ? arg.q.notFoundDefault : parse(data[key]);
4314
+ for (const item of batches) {
4315
+ item.parent[item.key] = item.data = item.data === void 0 ? arg.q.notFoundDefault : parse(item.data);
4317
4316
  }
4318
4317
  } else {
4319
- for (const { data } of batches) {
4320
- if (data[key] === void 0)
4318
+ for (const item of batches) {
4319
+ if (item.data === void 0)
4321
4320
  throw new NotFoundError(arg);
4322
- data[key] = parse(data[key]);
4321
+ item.parent[item.key] = item.data = parse(item.data);
4323
4322
  }
4324
4323
  }
4325
4324
  } else if (returnType !== "value") {
4326
4325
  for (const { data } of batches) {
4327
- if (data[key] === void 0)
4326
+ if (data === void 0)
4328
4327
  throw new NotFoundError(arg);
4329
4328
  }
4330
4329
  }
@@ -4393,7 +4392,9 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
4393
4392
  const stack = rows.map(
4394
4393
  (row) => ({
4395
4394
  data: row,
4396
- i: 0
4395
+ parent: row,
4396
+ i: 0,
4397
+ key: path[0]
4397
4398
  })
4398
4399
  );
4399
4400
  while (stack.length > 0) {
@@ -5825,7 +5826,7 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
5825
5826
  }).join(", ")})` : "";
5826
5827
  const target = "from" in copy ? copy.from : copy.to;
5827
5828
  sql.push(
5828
- `COPY "${table.table}"${columns} ${"from" in copy ? "FROM" : "TO"} ${typeof target === "string" ? quoteString(target) : `PROGRAM ${quoteString(target.program)}`}`
5829
+ `COPY "${table.table}"${columns} ${"from" in copy ? "FROM" : "TO"} ${typeof target === "string" ? escapeString(target) : `PROGRAM ${escapeString(target.program)}`}`
5829
5830
  );
5830
5831
  if (Object.keys(copy).length > (copy.columns ? 2 : 1)) {
5831
5832
  const options = [];
@@ -5834,15 +5835,15 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
5834
5835
  if (copy.freeze)
5835
5836
  options.push(`FREEZE ${copy.freeze}`);
5836
5837
  if (copy.delimiter)
5837
- options.push(`DELIMITER ${quoteString(copy.delimiter)}`);
5838
+ options.push(`DELIMITER ${escapeString(copy.delimiter)}`);
5838
5839
  if (copy.null)
5839
- options.push(`NULL ${quoteString(copy.null)}`);
5840
+ options.push(`NULL ${escapeString(copy.null)}`);
5840
5841
  if (copy.header)
5841
5842
  options.push(`HEADER ${copy.header}`);
5842
5843
  if (copy.quote)
5843
- options.push(`QUOTE ${quoteString(copy.quote)}`);
5844
+ options.push(`QUOTE ${escapeString(copy.quote)}`);
5844
5845
  if (copy.escape)
5845
- options.push(`ESCAPE ${quoteString(copy.escape)}`);
5846
+ options.push(`ESCAPE ${escapeString(copy.escape)}`);
5846
5847
  if (copy.forceQuote)
5847
5848
  options.push(
5848
5849
  `FORCE_QUOTE ${copy.forceQuote === "*" ? "*" : `(${copy.forceQuote.map((x) => `"${x}"`).join(", ")})`}`
@@ -5856,7 +5857,7 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
5856
5857
  `FORCE_NULL (${copy.forceNull.map((x) => `"${x}"`).join(", ")})`
5857
5858
  );
5858
5859
  if (copy.encoding)
5859
- options.push(`ENCODING ${quoteString(copy.encoding)}`);
5860
+ options.push(`ENCODING ${escapeString(copy.encoding)}`);
5860
5861
  sql.push(`WITH (${options.join(", ")})`);
5861
5862
  }
5862
5863
  pushWhereStatementSql(ctx, table, query, quotedAs);
@@ -12986,5 +12987,5 @@ function copyTableData(query, arg) {
12986
12987
  return q;
12987
12988
  }
12988
12989
 
12989
- export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _afterCommitError, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
12990
+ export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _afterCommitError, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
12990
12991
  //# sourceMappingURL=index.mjs.map