pqb 0.55.0 → 0.56.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
@@ -1,5 +1,4 @@
1
- import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, templateLiteralSQLToCode, quoteObjectKey, toArray, emptyArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, setObjectValueImmutable, getValueKey, addValue, isExpression, dateDataToCode, joinTruthy, arrayDataToCode, numberDataToCode, noop, stringDataToCode, getDefaultLanguage, setDefaultNowFn, setDefaultLanguage, setCurrentColumnName, timestampHelpers, _getQueryAliasOrName, _getQueryOuterAliases, returnArg as returnArg$1, pushQueryValueImmutable, NotFoundError, _setSubQueryAliases, _applyRelationAliases, isRelationQuery, OrchidOrmInternalError, _checkIfAliased, logColors, OrchidOrmError, applyTransforms, callWithThis, requirePrimaryKeys, pick, getFreeAlias, _setQueryAs, _copyQueryAliasToQuery, setParserToQuery, newDelayedRelationSelect, pushOrNewArray, getPrimaryKeys, setDelayedRelation, UnhandledTypeError, isRawSQL, setAdapterConnectRetry, pushOrNewArrayToObjectImmutable, QueryHookUtils, MoreThanOneRowError, isObjectEmpty, ValExpression, applyMixins, _getQueryAs, _setQueryAlias, QueryError, snakeCaseKey } from 'orchid-core';
2
- import pg from 'pg';
1
+ import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, templateLiteralSQLToCode, quoteObjectKey, toArray, emptyArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, setObjectValueImmutable, getValueKey, addValue, isExpression, dateDataToCode, joinTruthy, arrayDataToCode, numberDataToCode, noop, stringDataToCode, getDefaultLanguage, setDefaultNowFn, setDefaultLanguage, setCurrentColumnName, timestampHelpers, _getQueryAliasOrName, _getQueryOuterAliases, returnArg, pushQueryValueImmutable, NotFoundError, OrchidOrmInternalError, _setSubQueryAliases, _applyRelationAliases, isRelationQuery, _checkIfAliased, logColors, OrchidOrmError, applyTransforms, callWithThis, requirePrimaryKeys, pick, getFreeAlias, _setQueryAs, _copyQueryAliasToQuery, setParserToQuery, newDelayedRelationSelect, pushOrNewArray, getPrimaryKeys, setDelayedRelation, UnhandledTypeError, isRawSQL, pushOrNewArrayToObjectImmutable, QueryHookUtils, MoreThanOneRowError, isObjectEmpty, ValExpression, applyMixins, _getQueryAs, _setQueryAlias, QueryError, snakeCaseKey } from 'orchid-core';
3
2
  import { inspect } from 'node:util';
4
3
  import { AsyncLocalStorage } from 'node:async_hooks';
5
4
  import { templateLiteralToSQL as templateLiteralToSQL$1 } from 'pqb';
@@ -2747,6 +2746,7 @@ const processAnds = (and, ctx, table, query, quotedAs, parens) => {
2747
2746
  for (const data of and) {
2748
2747
  processWhere(ands, ctx, table, query, data, quotedAs);
2749
2748
  }
2749
+ if (!ands.length) return;
2750
2750
  const sql = ands.join(" AND ");
2751
2751
  return parens && ands.length > 1 ? `(${sql})` : sql;
2752
2752
  };
@@ -2782,12 +2782,16 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2782
2782
  if (value === void 0) continue;
2783
2783
  if (key === "AND") {
2784
2784
  const arr = toArray(value);
2785
- ands.push(processAnds(arr, ctx, table, query, quotedAs));
2785
+ const sql = processAnds(arr, ctx, table, query, quotedAs);
2786
+ if (sql) ands.push(sql);
2786
2787
  } else if (key === "OR") {
2787
2788
  const arr = value.map(toArray);
2788
- ands.push(
2789
- `(${arr.map((and) => processAnds(and, ctx, table, query, quotedAs)).join(" OR ")})`
2790
- );
2789
+ const sqls = arr.reduce((acc, and) => {
2790
+ const sql = processAnds(and, ctx, table, query, quotedAs);
2791
+ if (sql) acc.push(sql);
2792
+ return acc;
2793
+ }, []);
2794
+ if (sqls.length) ands.push(`(${sqls.join(" OR ")})`);
2791
2795
  } else if (key === "NOT") {
2792
2796
  const arr = toArray(value);
2793
2797
  ands.push(`NOT ${processAnds(arr, ctx, table, query, quotedAs, true)}`);
@@ -3224,7 +3228,7 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
3224
3228
  };
3225
3229
  }
3226
3230
  }
3227
- const args0 = args.length ? args[0] : returnArg$1;
3231
+ const args0 = args.length ? args[0] : returnArg;
3228
3232
  if (typeof args0 === "function") {
3229
3233
  const q = first;
3230
3234
  if (q.joinQueryAfterCallback) {
@@ -3341,11 +3345,31 @@ const _queryWhere = (q, args) => {
3341
3345
  resolveCallbacksInArgs(q, args);
3342
3346
  return pushQueryArrayImmutable(q, "and", args);
3343
3347
  };
3344
- const _queryFindBy = (q, args) => {
3345
- return _queryTake(_queryWhere(q, args));
3348
+ const _queryFindBy = (q, arg) => {
3349
+ validateFindBy(q, arg, "findBy");
3350
+ return _queryTake(_queryWhere(q, [arg]));
3351
+ };
3352
+ const _queryFindByOptional = (q, arg) => {
3353
+ validateFindBy(q, arg, "findByOptional");
3354
+ return _queryTakeOptional(_queryWhere(q, [arg]));
3346
3355
  };
3347
- const _queryFindByOptional = (q, args) => {
3348
- return _queryTakeOptional(_queryWhere(q, args));
3356
+ const validateFindBy = (q, arg, method) => {
3357
+ let nonEmpty;
3358
+ for (const key in arg) {
3359
+ nonEmpty = true;
3360
+ if (arg[key] === void 0) {
3361
+ throw new OrchidOrmInternalError(
3362
+ q,
3363
+ `${method} was called with undefined value`
3364
+ );
3365
+ }
3366
+ }
3367
+ if (!nonEmpty) {
3368
+ throw new OrchidOrmInternalError(
3369
+ q,
3370
+ `${method} was called with empty object`
3371
+ );
3372
+ }
3349
3373
  };
3350
3374
  const _queryWhereSql = (q, args) => {
3351
3375
  return pushQueryValueImmutable(
@@ -4537,10 +4561,10 @@ class QueryLog {
4537
4561
  }
4538
4562
  }
4539
4563
 
4540
- const commitSql$1 = {
4564
+ const commitSql = {
4541
4565
  text: "COMMIT"
4542
4566
  };
4543
- const rollbackSql$1 = {
4567
+ const rollbackSql = {
4544
4568
  text: "ROLLBACK"
4545
4569
  };
4546
4570
  class AfterCommitError extends OrchidOrmError {
@@ -4589,7 +4613,7 @@ class Transaction {
4589
4613
  const transactionId = trx ? trx.transactionId + 1 : 0;
4590
4614
  const callback = (adapter) => {
4591
4615
  if (log) log.afterQuery(sql, logData);
4592
- if (log) logData = log.beforeQuery(commitSql$1);
4616
+ if (log) logData = log.beforeQuery(commitSql);
4593
4617
  if (trx) {
4594
4618
  trx.transactionId = transactionId;
4595
4619
  return fn();
@@ -4604,13 +4628,29 @@ class Transaction {
4604
4628
  return this.internal.transactionStorage.run(trx, fn);
4605
4629
  };
4606
4630
  if (!trx) {
4607
- sql.text = `BEGIN${options.level ? ` ISOLATION LEVEL ${options.level}` : ""}${options.readOnly !== void 0 ? ` READ ${options.readOnly ? "ONLY" : "WRITE"}` : ""}${options.deferrable !== void 0 ? ` ${options.deferrable ? "" : "NOT "}DEFERRABLE` : ""}`;
4608
- if (log) logData = log.beforeQuery(sql);
4609
- const result = await this.q.adapter.transaction(sql, callback).catch((err) => {
4610
- if (log) log.afterQuery(rollbackSql$1, logData);
4631
+ let beginOptions = void 0;
4632
+ if (options.level) {
4633
+ beginOptions = `ISOLATION LEVEL ${options.level}`;
4634
+ }
4635
+ if (options.readOnly !== void 0) {
4636
+ const add = `READ ${options.readOnly ? "ONLY" : "WRITE"}`;
4637
+ if (beginOptions) beginOptions += " " + add;
4638
+ else beginOptions = add;
4639
+ }
4640
+ if (options.deferrable !== void 0) {
4641
+ const add = `${options.deferrable ? "" : "NOT "}DEFERRABLE`;
4642
+ if (beginOptions) beginOptions += " " + add;
4643
+ else beginOptions = add;
4644
+ }
4645
+ if (log) {
4646
+ sql.text = beginOptions ? `BEGIN ${beginOptions}` : "BEGIN";
4647
+ logData = log.beforeQuery(sql);
4648
+ }
4649
+ const result = await this.q.adapter.transaction(beginOptions, callback).catch((err) => {
4650
+ if (log) log.afterQuery(rollbackSql, logData);
4611
4651
  throw err;
4612
4652
  });
4613
- if (log) log.afterQuery(commitSql$1, logData);
4653
+ if (log) log.afterQuery(commitSql, logData);
4614
4654
  runAfterCommit(trx.afterCommit, result);
4615
4655
  return result;
4616
4656
  } else {
@@ -4618,20 +4658,20 @@ class Transaction {
4618
4658
  sql.text = `SAVEPOINT "${transactionId}"`;
4619
4659
  if (log) logData = log.beforeQuery(sql);
4620
4660
  const { adapter } = trx;
4621
- await adapter.query(sql);
4661
+ await adapter.arrays(sql.text, sql.values);
4622
4662
  let result;
4623
4663
  try {
4624
4664
  result = await callback(adapter);
4625
4665
  } catch (err) {
4626
4666
  sql.text = `ROLLBACK TO SAVEPOINT "${transactionId}"`;
4627
4667
  if (log) logData = log.beforeQuery(sql);
4628
- await adapter.query(sql);
4668
+ await adapter.arrays(sql.text, sql.values);
4629
4669
  if (log) log.afterQuery(sql, logData);
4630
4670
  throw err;
4631
4671
  }
4632
4672
  sql.text = `RELEASE SAVEPOINT "${transactionId}"`;
4633
4673
  if (log) logData = log.beforeQuery(sql);
4634
- await adapter.query(sql);
4674
+ await adapter.arrays(sql.text, sql.values);
4635
4675
  if (log) log.afterQuery(sql, logData);
4636
4676
  if (transactionId === trx.testTransactionCount) {
4637
4677
  const { afterCommit } = trx;
@@ -4976,25 +5016,10 @@ class Then {
4976
5016
  }
4977
5017
  }
4978
5018
  let queryError = void 0;
4979
- let getThen;
4980
- if (process.versions.bun) {
4981
- getThen = function() {
4982
- queryError = new Error();
4983
- if (!this.internal) return maybeWrappedThen;
4984
- const trx = this.internal.transactionStorage.getStore();
4985
- if (!trx) return maybeWrappedThen;
4986
- return (resolve, reject) => {
4987
- return this.internal.transactionStorage.run(trx, () => {
4988
- return maybeWrappedThen.call(this, resolve, reject);
4989
- });
4990
- };
4991
- };
4992
- } else {
4993
- getThen = function() {
4994
- queryError = new Error();
4995
- return maybeWrappedThen;
4996
- };
4997
- }
5019
+ const getThen = function() {
5020
+ queryError = new Error();
5021
+ return maybeWrappedThen;
5022
+ };
4998
5023
  Object.defineProperty(Then.prototype, "then", {
4999
5024
  configurable: true,
5000
5025
  get: getThen,
@@ -5104,32 +5129,37 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
5104
5129
  result = query.handleResult(q, tempReturnType, queryResult);
5105
5130
  } else {
5106
5131
  const queryMethod = queryMethodByReturnType[tempReturnType];
5107
- if (!trx) {
5108
- if (log) logData = log.beforeQuery(beginSql);
5109
- await adapter.arrays(beginSql);
5110
- if (log) log.afterQuery(beginSql, logData);
5111
- }
5112
- for (const item of sql.batch) {
5113
- sql = item;
5114
- if (log) {
5115
- logData = log.beforeQuery(sql);
5116
- }
5117
- const result2 = await execQuery(adapter, queryMethod, sql);
5118
- if (queryResult) {
5119
- queryResult.rowCount += result2.rowCount;
5120
- queryResult.rows.push(...result2.rows);
5121
- } else {
5122
- queryResult = result2;
5123
- }
5124
- if (log) {
5125
- log.afterQuery(sql, logData);
5126
- sql = void 0;
5132
+ const queryBatch = async (batch) => {
5133
+ for (const item of batch) {
5134
+ sql = item;
5135
+ if (log) {
5136
+ logData = log.beforeQuery(sql);
5137
+ }
5138
+ const result2 = await execQuery(adapter, queryMethod, sql);
5139
+ if (queryResult) {
5140
+ queryResult.rowCount += result2.rowCount;
5141
+ queryResult.rows.push(...result2.rows);
5142
+ } else {
5143
+ queryResult = result2;
5144
+ }
5145
+ if (log) {
5146
+ log.afterQuery(sql, logData);
5147
+ }
5127
5148
  }
5128
- }
5129
- if (!trx) {
5130
- if (log) logData = log.beforeQuery(commitSql$1);
5131
- await adapter.arrays(commitSql$1);
5132
- if (log) log.afterQuery(commitSql$1, logData);
5149
+ sql = void 0;
5150
+ };
5151
+ if (trx) {
5152
+ await queryBatch(sql.batch);
5153
+ } else {
5154
+ const { batch } = sql;
5155
+ if (log) logData = log.beforeQuery(beginSql);
5156
+ await adapter.transaction(void 0, async () => {
5157
+ if (log) log.afterQuery(beginSql, logData);
5158
+ const res = await queryBatch(batch);
5159
+ if (log) logData = log.beforeQuery(commitSql);
5160
+ return res;
5161
+ });
5162
+ if (log) log.afterQuery(commitSql, logData);
5133
5163
  }
5134
5164
  if (query.patchResult) {
5135
5165
  await query.patchResult(q, hookSelect, queryResult);
@@ -5282,9 +5312,9 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
5282
5312
  return resolve ? resolve(result) : result;
5283
5313
  } catch (err) {
5284
5314
  let error;
5285
- if (err instanceof pg.DatabaseError) {
5315
+ if (err instanceof adapter.errorClass) {
5286
5316
  error = new q.error();
5287
- assignError(error, err);
5317
+ adapter.assignError(error, err);
5288
5318
  error.cause = localError;
5289
5319
  } else {
5290
5320
  error = err;
@@ -5310,37 +5340,13 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
5310
5340
  }
5311
5341
  };
5312
5342
  const execQuery = (adapter, method, sql) => {
5313
- return adapter[method](sql).then(
5314
- (result) => {
5315
- if (result.rowCount && !result.rows.length) {
5316
- result.rows.length = result.rowCount;
5317
- result.rows.fill({});
5318
- }
5319
- return result;
5343
+ return adapter[method](sql.text, sql.values).then((result) => {
5344
+ if (result.rowCount && !result.rows.length) {
5345
+ result.rows.length = result.rowCount;
5346
+ result.rows.fill({});
5320
5347
  }
5321
- );
5322
- };
5323
- const assignError = (to, from) => {
5324
- to.message = from.message;
5325
- to.length = from.length;
5326
- to.name = from.name;
5327
- to.severity = from.severity;
5328
- to.code = from.code;
5329
- to.detail = from.detail;
5330
- to.hint = from.hint;
5331
- to.position = from.position;
5332
- to.internalPosition = from.internalPosition;
5333
- to.internalQuery = from.internalQuery;
5334
- to.where = from.where;
5335
- to.schema = from.schema;
5336
- to.table = from.table;
5337
- to.column = from.column;
5338
- to.dataType = from.dataType;
5339
- to.constraint = from.constraint;
5340
- to.file = from.file;
5341
- to.line = from.line;
5342
- to.routine = from.routine;
5343
- return to;
5348
+ return result;
5349
+ });
5344
5350
  };
5345
5351
  const handleResult = (q, returnType, result, isSubQuery) => {
5346
5352
  const { parsers } = q.q;
@@ -5917,7 +5923,9 @@ const processSelectArg = (q, as, arg, columnAs) => {
5917
5923
  return false;
5918
5924
  }
5919
5925
  }
5920
- if (!isExpression(value) && isRelationQuery(value)) {
5926
+ if (!isExpression(value) && isRelationQuery(value) && // `subQuery = 1` case is when callback returns the same query as it gets,
5927
+ // for example `q => q.get('name')`.
5928
+ value.q.subQuery !== 1) {
5921
5929
  query.q.selectRelation = joinQuery = true;
5922
5930
  value = value.joinQuery(value, q);
5923
5931
  let subQuery;
@@ -6080,7 +6088,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
6080
6088
  key
6081
6089
  );
6082
6090
  } else if (isExpression(it)) {
6083
- result[key] = it.result.value;
6091
+ result[key] = it.result.value || UnknownColumn.instance;
6084
6092
  } else if (it) {
6085
6093
  const { returnType } = it.q;
6086
6094
  if (returnType === "value" || returnType === "valueOrThrow") {
@@ -7723,149 +7731,6 @@ function pushLimitSQL(sql, values, q) {
7723
7731
  }
7724
7732
  }
7725
7733
 
7726
- const { types } = pg;
7727
- const defaultTypeParsers = {};
7728
- for (const key in types.builtins) {
7729
- const id = types.builtins[key];
7730
- defaultTypeParsers[id] = types.getTypeParser(id);
7731
- }
7732
- [
7733
- types.builtins.DATE,
7734
- types.builtins.TIMESTAMP,
7735
- types.builtins.TIMESTAMPTZ,
7736
- types.builtins.TIME,
7737
- types.builtins.CIRCLE
7738
- ].forEach((id) => {
7739
- delete defaultTypeParsers[id];
7740
- });
7741
- const returnArg = (arg) => arg;
7742
- const rollbackSql = { text: "ROLLBACK" };
7743
- const commitSql = { text: "COMMIT" };
7744
- class Adapter {
7745
- constructor({ types: types2 = defaultTypeParsers, ...config }) {
7746
- this.types = types2;
7747
- let schema = config.schema;
7748
- if (config.databaseURL) {
7749
- const url = new URL(config.databaseURL);
7750
- const ssl = url.searchParams.get("ssl");
7751
- if (ssl === "false") {
7752
- url.searchParams.delete("ssl");
7753
- } else if (!config.ssl && ssl === "true") {
7754
- config.ssl = true;
7755
- }
7756
- if (!schema) {
7757
- schema = url.searchParams.get("schema") || void 0;
7758
- }
7759
- config.databaseURL = url.toString();
7760
- config.connectionString = config.databaseURL;
7761
- }
7762
- if (schema) this.schema = schema === "public" ? void 0 : schema;
7763
- this.config = config;
7764
- this.pool = new pg.Pool(config);
7765
- if (config.connectRetry) {
7766
- setAdapterConnectRetry(
7767
- this,
7768
- () => this.pool.connect(),
7769
- config.connectRetry === true ? emptyObject : config.connectRetry
7770
- );
7771
- }
7772
- }
7773
- connect() {
7774
- return this.pool.connect();
7775
- }
7776
- query(query, types2) {
7777
- return performQuery$1(this, query, types2);
7778
- }
7779
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7780
- arrays(query, types2) {
7781
- return performQuery$1(this, query, types2, "array");
7782
- }
7783
- async transaction(begin, cb, end = commitSql) {
7784
- const client = await this.connect();
7785
- try {
7786
- await setSearchPath(client, this.schema);
7787
- await performQueryOnClient(client, begin, this.types);
7788
- let result;
7789
- try {
7790
- result = await cb(new TransactionAdapter(this, client, this.types));
7791
- } catch (err) {
7792
- await performQueryOnClient(client, rollbackSql, this.types);
7793
- throw err;
7794
- }
7795
- await performQueryOnClient(client, end, this.types);
7796
- return result;
7797
- } finally {
7798
- client.release();
7799
- }
7800
- }
7801
- close() {
7802
- const { pool } = this;
7803
- this.pool = new pg.Pool(this.config);
7804
- return pool.end();
7805
- }
7806
- }
7807
- const defaultTypesConfig = {
7808
- getTypeParser(id) {
7809
- return defaultTypeParsers[id] || returnArg;
7810
- }
7811
- };
7812
- const setSearchPath = (client, schema) => {
7813
- if (client.connection.schema !== schema) {
7814
- client.connection.schema = schema;
7815
- return client.query(`SET search_path = ${schema || "public"}`);
7816
- }
7817
- return;
7818
- };
7819
- const performQuery$1 = async (adapter, query, types2, rowMode) => {
7820
- const client = await adapter.connect();
7821
- try {
7822
- await setSearchPath(client, adapter.schema);
7823
- return await performQueryOnClient(client, query, types2, rowMode);
7824
- } finally {
7825
- client.release();
7826
- }
7827
- };
7828
- const performQueryOnClient = (client, query, types2, rowMode) => {
7829
- const params = {
7830
- text: typeof query === "string" ? query : query.text,
7831
- values: typeof query === "string" ? void 0 : query.values,
7832
- rowMode,
7833
- types: types2 ? {
7834
- getTypeParser(id) {
7835
- return types2[id] || returnArg;
7836
- }
7837
- } : defaultTypesConfig
7838
- };
7839
- return client.query(params);
7840
- };
7841
- class TransactionAdapter {
7842
- constructor(adapter, client, types2) {
7843
- this.adapter = adapter;
7844
- this.client = client;
7845
- this.types = types2;
7846
- this.pool = adapter.pool;
7847
- this.config = adapter.config;
7848
- this.schema = adapter.schema;
7849
- }
7850
- connect() {
7851
- return Promise.resolve(this.client);
7852
- }
7853
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7854
- async query(query, types2) {
7855
- return await performQueryOnClient(this.client, query, types2);
7856
- }
7857
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7858
- async arrays(query, types2) {
7859
- return await performQueryOnClient(this.client, query, types2, "array");
7860
- }
7861
- async transaction(_, cb) {
7862
- return await cb(this);
7863
- }
7864
- close() {
7865
- return this.adapter.close();
7866
- }
7867
- }
7868
-
7869
7734
  class FnExpression extends Expression {
7870
7735
  /**
7871
7736
  * @param query - query object.
@@ -12264,7 +12129,7 @@ class QueryMethods {
12264
12129
  * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
12265
12130
  */
12266
12131
  findBy(uniqueColumnValues) {
12267
- return _queryFindBy(_clone(this), [uniqueColumnValues]);
12132
+ return _queryFindBy(_clone(this), uniqueColumnValues);
12268
12133
  }
12269
12134
  /**
12270
12135
  * Finds a single unique record, returns `undefined` if not found.
@@ -12280,9 +12145,10 @@ class QueryMethods {
12280
12145
  * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
12281
12146
  */
12282
12147
  findByOptional(uniqueColumnValues) {
12283
- return _queryFindByOptional(_clone(this), [
12148
+ return _queryFindByOptional(
12149
+ _clone(this),
12284
12150
  uniqueColumnValues
12285
- ]);
12151
+ );
12286
12152
  }
12287
12153
  /**
12288
12154
  * Specifies the schema to be used as a prefix of a table name.
@@ -12877,7 +12743,8 @@ const performQuery = async (q, args, method) => {
12877
12743
  if (log) logData = log.beforeQuery(sql);
12878
12744
  try {
12879
12745
  const result = await (trx?.adapter || q.adapter)[method](
12880
- sql
12746
+ sql.text,
12747
+ sql.values
12881
12748
  );
12882
12749
  if (log) log.afterQuery(sql, logData);
12883
12750
  return result;
@@ -13163,7 +13030,7 @@ class Db extends QueryMethods {
13163
13030
  }
13164
13031
  applyMixins(Db, [QueryMethods]);
13165
13032
  Db.prototype.constructor = Db;
13166
- const createDb = ({
13033
+ const createDbWithAdapter = ({
13167
13034
  log,
13168
13035
  logger,
13169
13036
  snakeCase,
@@ -13171,7 +13038,7 @@ const createDb = ({
13171
13038
  columnTypes: ctOrFn = makeColumnTypes(schemaConfig),
13172
13039
  ...options
13173
13040
  }) => {
13174
- const adapter = "adapter" in options ? options.adapter : new Adapter(options);
13041
+ const { adapter } = options;
13175
13042
  const commonOptions = {
13176
13043
  log,
13177
13044
  logger,
@@ -13368,5 +13235,5 @@ function copyTableData(query, arg) {
13368
13235
  return q;
13369
13236
  }
13370
13237
 
13371
- export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, 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, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryAsMethods, QueryCreate, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsert, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql$1 as rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
13238
+ export { AfterCommitError, AggregateMethods, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, 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, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryAsMethods, QueryCreate, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsert, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDbWithAdapter, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
13372
13239
  //# sourceMappingURL=index.mjs.map