pqb 0.39.3 → 0.40.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.js CHANGED
@@ -3179,30 +3179,10 @@ const defaultSchemaConfig = {
3179
3179
  timestamp: (precision) => new TimestampTZColumn(defaultSchemaConfig, precision)
3180
3180
  };
3181
3181
 
3182
- const singleQuoteRegex = /'/g;
3183
- const doubleQuoteRegex = /"/g;
3184
- const quoteValue = (value) => {
3182
+ const quoteValue = (value, nested = false) => {
3185
3183
  const type = typeof value;
3186
- if (type === "number")
3184
+ if (type === "number" || type === "bigint")
3187
3185
  return String(value);
3188
- else if (type === "string")
3189
- return `"${value.replace(doubleQuoteRegex, '\\"').replace(singleQuoteRegex, "''")}"`;
3190
- else if (type === "boolean")
3191
- return value ? "true" : "false";
3192
- else if (value instanceof Date)
3193
- return `"${value.toISOString()}"`;
3194
- else if (Array.isArray(value))
3195
- return quoteArray(value);
3196
- else if (value === null || value === void 0)
3197
- return "NULL";
3198
- else
3199
- return `"${JSON.stringify(value).replace(doubleQuoteRegex, '\\"').replace(singleQuoteRegex, "''")}"`;
3200
- };
3201
- const quoteArray = (array) => `'{${array.map(quoteValue).join(",")}}'`;
3202
- const quote = (value) => {
3203
- const type = typeof value;
3204
- if (type === "number")
3205
- return `${value}`;
3206
3186
  else if (type === "string")
3207
3187
  return quoteString(value);
3208
3188
  else if (type === "boolean")
@@ -3210,15 +3190,14 @@ const quote = (value) => {
3210
3190
  else if (value instanceof Date)
3211
3191
  return `'${value.toISOString()}'`;
3212
3192
  else if (Array.isArray(value))
3213
- return quoteArray(value);
3193
+ return `${nested ? "" : "ARRAY"}[${value.map((el) => quoteValue(el, true)).join(",")}]`;
3214
3194
  else if (value === null || value === void 0)
3215
3195
  return "NULL";
3216
3196
  else
3217
- return `'${JSON.stringify(value).replace(singleQuoteRegex, "''")}'`;
3218
- };
3219
- const quoteString = (value) => {
3220
- return `'${value.replace(singleQuoteRegex, "''")}'`;
3197
+ return quoteString(JSON.stringify(value));
3221
3198
  };
3199
+ const quote = (value) => quoteValue(value);
3200
+ const quoteString = (value) => `'${value.replaceAll("'", "''")}'`;
3222
3201
 
3223
3202
  const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values) => {
3224
3203
  const elapsed = process.hrtime(time);
@@ -3882,7 +3861,8 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3882
3861
  );
3883
3862
  }
3884
3863
  if (afterCommitHooks) {
3885
- if (trx) {
3864
+ if (trx && // when inside test transactions, push to a transaction only unless it's the outer user transaction.
3865
+ (!trx.testTransactionCount || trx.transactionId + 1 > trx.testTransactionCount)) {
3886
3866
  ((_c = trx.afterCommit) != null ? _c : trx.afterCommit = []).push(
3887
3867
  result,
3888
3868
  q,