pqb 0.55.1 → 0.56.3

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
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var orchidCore = require('orchid-core');
4
- var pg = require('pg');
5
4
  var node_util = require('node:util');
6
5
  var node_async_hooks = require('node:async_hooks');
7
6
  var pqb = require('pqb');
@@ -2749,6 +2748,7 @@ const processAnds = (and, ctx, table, query, quotedAs, parens) => {
2749
2748
  for (const data of and) {
2750
2749
  processWhere(ands, ctx, table, query, data, quotedAs);
2751
2750
  }
2751
+ if (!ands.length) return;
2752
2752
  const sql = ands.join(" AND ");
2753
2753
  return parens && ands.length > 1 ? `(${sql})` : sql;
2754
2754
  };
@@ -2784,12 +2784,16 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2784
2784
  if (value === void 0) continue;
2785
2785
  if (key === "AND") {
2786
2786
  const arr = orchidCore.toArray(value);
2787
- ands.push(processAnds(arr, ctx, table, query, quotedAs));
2787
+ const sql = processAnds(arr, ctx, table, query, quotedAs);
2788
+ if (sql) ands.push(sql);
2788
2789
  } else if (key === "OR") {
2789
2790
  const arr = value.map(orchidCore.toArray);
2790
- ands.push(
2791
- `(${arr.map((and) => processAnds(and, ctx, table, query, quotedAs)).join(" OR ")})`
2792
- );
2791
+ const sqls = arr.reduce((acc, and) => {
2792
+ const sql = processAnds(and, ctx, table, query, quotedAs);
2793
+ if (sql) acc.push(sql);
2794
+ return acc;
2795
+ }, []);
2796
+ if (sqls.length) ands.push(`(${sqls.join(" OR ")})`);
2793
2797
  } else if (key === "NOT") {
2794
2798
  const arr = orchidCore.toArray(value);
2795
2799
  ands.push(`NOT ${processAnds(arr, ctx, table, query, quotedAs, true)}`);
@@ -3343,11 +3347,31 @@ const _queryWhere = (q, args) => {
3343
3347
  resolveCallbacksInArgs(q, args);
3344
3348
  return pushQueryArrayImmutable(q, "and", args);
3345
3349
  };
3346
- const _queryFindBy = (q, args) => {
3347
- return _queryTake(_queryWhere(q, args));
3350
+ const _queryFindBy = (q, arg) => {
3351
+ validateFindBy(q, arg, "findBy");
3352
+ return _queryTake(_queryWhere(q, [arg]));
3353
+ };
3354
+ const _queryFindByOptional = (q, arg) => {
3355
+ validateFindBy(q, arg, "findByOptional");
3356
+ return _queryTakeOptional(_queryWhere(q, [arg]));
3348
3357
  };
3349
- const _queryFindByOptional = (q, args) => {
3350
- return _queryTakeOptional(_queryWhere(q, args));
3358
+ const validateFindBy = (q, arg, method) => {
3359
+ let nonEmpty;
3360
+ for (const key in arg) {
3361
+ nonEmpty = true;
3362
+ if (arg[key] === void 0) {
3363
+ throw new orchidCore.OrchidOrmInternalError(
3364
+ q,
3365
+ `${method} was called with undefined value`
3366
+ );
3367
+ }
3368
+ }
3369
+ if (!nonEmpty) {
3370
+ throw new orchidCore.OrchidOrmInternalError(
3371
+ q,
3372
+ `${method} was called with empty object`
3373
+ );
3374
+ }
3351
3375
  };
3352
3376
  const _queryWhereSql = (q, args) => {
3353
3377
  return orchidCore.pushQueryValueImmutable(
@@ -4539,10 +4563,10 @@ class QueryLog {
4539
4563
  }
4540
4564
  }
4541
4565
 
4542
- const commitSql$1 = {
4566
+ const commitSql = {
4543
4567
  text: "COMMIT"
4544
4568
  };
4545
- const rollbackSql$1 = {
4569
+ const rollbackSql = {
4546
4570
  text: "ROLLBACK"
4547
4571
  };
4548
4572
  class AfterCommitError extends orchidCore.OrchidOrmError {
@@ -4591,7 +4615,7 @@ class Transaction {
4591
4615
  const transactionId = trx ? trx.transactionId + 1 : 0;
4592
4616
  const callback = (adapter) => {
4593
4617
  if (log) log.afterQuery(sql, logData);
4594
- if (log) logData = log.beforeQuery(commitSql$1);
4618
+ if (log) logData = log.beforeQuery(commitSql);
4595
4619
  if (trx) {
4596
4620
  trx.transactionId = transactionId;
4597
4621
  return fn();
@@ -4606,13 +4630,29 @@ class Transaction {
4606
4630
  return this.internal.transactionStorage.run(trx, fn);
4607
4631
  };
4608
4632
  if (!trx) {
4609
- 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` : ""}`;
4610
- if (log) logData = log.beforeQuery(sql);
4611
- const result = await this.q.adapter.transaction(sql, callback).catch((err) => {
4612
- if (log) log.afterQuery(rollbackSql$1, logData);
4633
+ let beginOptions = void 0;
4634
+ if (options.level) {
4635
+ beginOptions = `ISOLATION LEVEL ${options.level}`;
4636
+ }
4637
+ if (options.readOnly !== void 0) {
4638
+ const add = `READ ${options.readOnly ? "ONLY" : "WRITE"}`;
4639
+ if (beginOptions) beginOptions += " " + add;
4640
+ else beginOptions = add;
4641
+ }
4642
+ if (options.deferrable !== void 0) {
4643
+ const add = `${options.deferrable ? "" : "NOT "}DEFERRABLE`;
4644
+ if (beginOptions) beginOptions += " " + add;
4645
+ else beginOptions = add;
4646
+ }
4647
+ if (log) {
4648
+ sql.text = beginOptions ? `BEGIN ${beginOptions}` : "BEGIN";
4649
+ logData = log.beforeQuery(sql);
4650
+ }
4651
+ const result = await this.q.adapter.transaction(beginOptions, callback).catch((err) => {
4652
+ if (log) log.afterQuery(rollbackSql, logData);
4613
4653
  throw err;
4614
4654
  });
4615
- if (log) log.afterQuery(commitSql$1, logData);
4655
+ if (log) log.afterQuery(commitSql, logData);
4616
4656
  runAfterCommit(trx.afterCommit, result);
4617
4657
  return result;
4618
4658
  } else {
@@ -4620,20 +4660,20 @@ class Transaction {
4620
4660
  sql.text = `SAVEPOINT "${transactionId}"`;
4621
4661
  if (log) logData = log.beforeQuery(sql);
4622
4662
  const { adapter } = trx;
4623
- await adapter.query(sql);
4663
+ await adapter.arrays(sql.text, sql.values);
4624
4664
  let result;
4625
4665
  try {
4626
4666
  result = await callback(adapter);
4627
4667
  } catch (err) {
4628
4668
  sql.text = `ROLLBACK TO SAVEPOINT "${transactionId}"`;
4629
4669
  if (log) logData = log.beforeQuery(sql);
4630
- await adapter.query(sql);
4670
+ await adapter.arrays(sql.text, sql.values);
4631
4671
  if (log) log.afterQuery(sql, logData);
4632
4672
  throw err;
4633
4673
  }
4634
4674
  sql.text = `RELEASE SAVEPOINT "${transactionId}"`;
4635
4675
  if (log) logData = log.beforeQuery(sql);
4636
- await adapter.query(sql);
4676
+ await adapter.arrays(sql.text, sql.values);
4637
4677
  if (log) log.afterQuery(sql, logData);
4638
4678
  if (transactionId === trx.testTransactionCount) {
4639
4679
  const { afterCommit } = trx;
@@ -4978,25 +5018,10 @@ class Then {
4978
5018
  }
4979
5019
  }
4980
5020
  let queryError = void 0;
4981
- let getThen;
4982
- if (process.versions.bun) {
4983
- getThen = function() {
4984
- queryError = new Error();
4985
- if (!this.internal) return maybeWrappedThen;
4986
- const trx = this.internal.transactionStorage.getStore();
4987
- if (!trx) return maybeWrappedThen;
4988
- return (resolve, reject) => {
4989
- return this.internal.transactionStorage.run(trx, () => {
4990
- return maybeWrappedThen.call(this, resolve, reject);
4991
- });
4992
- };
4993
- };
4994
- } else {
4995
- getThen = function() {
4996
- queryError = new Error();
4997
- return maybeWrappedThen;
4998
- };
4999
- }
5021
+ const getThen = function() {
5022
+ queryError = new Error();
5023
+ return maybeWrappedThen;
5024
+ };
5000
5025
  Object.defineProperty(Then.prototype, "then", {
5001
5026
  configurable: true,
5002
5027
  get: getThen,
@@ -5106,32 +5131,37 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
5106
5131
  result = query.handleResult(q, tempReturnType, queryResult);
5107
5132
  } else {
5108
5133
  const queryMethod = queryMethodByReturnType[tempReturnType];
5109
- if (!trx) {
5110
- if (log) logData = log.beforeQuery(beginSql);
5111
- await adapter.arrays(beginSql);
5112
- if (log) log.afterQuery(beginSql, logData);
5113
- }
5114
- for (const item of sql.batch) {
5115
- sql = item;
5116
- if (log) {
5117
- logData = log.beforeQuery(sql);
5118
- }
5119
- const result2 = await execQuery(adapter, queryMethod, sql);
5120
- if (queryResult) {
5121
- queryResult.rowCount += result2.rowCount;
5122
- queryResult.rows.push(...result2.rows);
5123
- } else {
5124
- queryResult = result2;
5125
- }
5126
- if (log) {
5127
- log.afterQuery(sql, logData);
5128
- sql = void 0;
5134
+ const queryBatch = async (batch) => {
5135
+ for (const item of batch) {
5136
+ sql = item;
5137
+ if (log) {
5138
+ logData = log.beforeQuery(sql);
5139
+ }
5140
+ const result2 = await execQuery(adapter, queryMethod, sql);
5141
+ if (queryResult) {
5142
+ queryResult.rowCount += result2.rowCount;
5143
+ queryResult.rows.push(...result2.rows);
5144
+ } else {
5145
+ queryResult = result2;
5146
+ }
5147
+ if (log) {
5148
+ log.afterQuery(sql, logData);
5149
+ }
5129
5150
  }
5130
- }
5131
- if (!trx) {
5132
- if (log) logData = log.beforeQuery(commitSql$1);
5133
- await adapter.arrays(commitSql$1);
5134
- if (log) log.afterQuery(commitSql$1, logData);
5151
+ sql = void 0;
5152
+ };
5153
+ if (trx) {
5154
+ await queryBatch(sql.batch);
5155
+ } else {
5156
+ const { batch } = sql;
5157
+ if (log) logData = log.beforeQuery(beginSql);
5158
+ await adapter.transaction(void 0, async () => {
5159
+ if (log) log.afterQuery(beginSql, logData);
5160
+ const res = await queryBatch(batch);
5161
+ if (log) logData = log.beforeQuery(commitSql);
5162
+ return res;
5163
+ });
5164
+ if (log) log.afterQuery(commitSql, logData);
5135
5165
  }
5136
5166
  if (query.patchResult) {
5137
5167
  await query.patchResult(q, hookSelect, queryResult);
@@ -5284,9 +5314,9 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
5284
5314
  return resolve ? resolve(result) : result;
5285
5315
  } catch (err) {
5286
5316
  let error;
5287
- if (err instanceof pg.DatabaseError) {
5317
+ if (err instanceof adapter.errorClass) {
5288
5318
  error = new q.error();
5289
- assignError(error, err);
5319
+ adapter.assignError(error, err);
5290
5320
  error.cause = localError;
5291
5321
  } else {
5292
5322
  error = err;
@@ -5312,37 +5342,13 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
5312
5342
  }
5313
5343
  };
5314
5344
  const execQuery = (adapter, method, sql) => {
5315
- return adapter[method](sql).then(
5316
- (result) => {
5317
- if (result.rowCount && !result.rows.length) {
5318
- result.rows.length = result.rowCount;
5319
- result.rows.fill({});
5320
- }
5321
- return result;
5345
+ return adapter[method](sql.text, sql.values).then((result) => {
5346
+ if (result.rowCount && !result.rows.length) {
5347
+ result.rows.length = result.rowCount;
5348
+ result.rows.fill({});
5322
5349
  }
5323
- );
5324
- };
5325
- const assignError = (to, from) => {
5326
- to.message = from.message;
5327
- to.length = from.length;
5328
- to.name = from.name;
5329
- to.severity = from.severity;
5330
- to.code = from.code;
5331
- to.detail = from.detail;
5332
- to.hint = from.hint;
5333
- to.position = from.position;
5334
- to.internalPosition = from.internalPosition;
5335
- to.internalQuery = from.internalQuery;
5336
- to.where = from.where;
5337
- to.schema = from.schema;
5338
- to.table = from.table;
5339
- to.column = from.column;
5340
- to.dataType = from.dataType;
5341
- to.constraint = from.constraint;
5342
- to.file = from.file;
5343
- to.line = from.line;
5344
- to.routine = from.routine;
5345
- return to;
5350
+ return result;
5351
+ });
5346
5352
  };
5347
5353
  const handleResult = (q, returnType, result, isSubQuery) => {
5348
5354
  const { parsers } = q.q;
@@ -5708,7 +5714,7 @@ const addParserForSelectItem = (q, as, key, arg, columnAlias, joinQuery) => {
5708
5714
  }))
5709
5715
  );
5710
5716
  }
5711
- if (query.hookSelect || query.parsers || query.transform) {
5717
+ if (query.hookSelect || query.parsers || query.transform || query.returnType === "oneOrThrow" || query.returnType === "valueOrThrow" || query.returnType === "one" || query.returnType === "value") {
5712
5718
  orchidCore.pushQueryValueImmutable(q, "batchParsers", {
5713
5719
  path: [key],
5714
5720
  fn: (path, queryResult) => {
@@ -5749,7 +5755,7 @@ const addParserForSelectItem = (q, as, key, arg, columnAlias, joinQuery) => {
5749
5755
  if (returnType === "one") {
5750
5756
  for (const batch of batches) {
5751
5757
  if (batch.data) parseRecord(parsers, batch.data);
5752
- else batch.data = void 0;
5758
+ else batch.parent[batch.key] = batch.data = void 0;
5753
5759
  }
5754
5760
  } else {
5755
5761
  for (const { data } of batches) {
@@ -5759,7 +5765,8 @@ const addParserForSelectItem = (q, as, key, arg, columnAlias, joinQuery) => {
5759
5765
  }
5760
5766
  } else if (returnType === "one") {
5761
5767
  for (const batch of batches) {
5762
- if (!batch.data) batch.data = void 0;
5768
+ if (!batch.data)
5769
+ batch.parent[batch.key] = batch.data = void 0;
5763
5770
  }
5764
5771
  } else {
5765
5772
  for (const { data } of batches) {
@@ -5786,22 +5793,30 @@ const addParserForSelectItem = (q, as, key, arg, columnAlias, joinQuery) => {
5786
5793
  }
5787
5794
  case "value":
5788
5795
  case "valueOrThrow": {
5796
+ const notNullable = !query.getColumn?.data.isNullable;
5789
5797
  const parse = query.parsers?.[orchidCore.getValueKey];
5790
5798
  if (parse) {
5791
5799
  if (returnType === "value") {
5792
5800
  for (const item of batches) {
5793
- item.parent[item.key] = item.data = item.data === void 0 ? query.notFoundDefault : parse(item.data);
5801
+ item.parent[item.key] = item.data = item.data === null ? query.notFoundDefault : parse(item.data);
5794
5802
  }
5795
5803
  } else {
5796
5804
  for (const item of batches) {
5797
- if (item.data === void 0)
5805
+ if (notNullable && item.data === null) {
5798
5806
  throw new orchidCore.NotFoundError(arg);
5807
+ }
5799
5808
  item.parent[item.key] = item.data = parse(item.data);
5800
5809
  }
5801
5810
  }
5802
- } else if (returnType !== "value") {
5811
+ } else if (returnType === "value") {
5812
+ for (const item of batches) {
5813
+ if (item.data === null) {
5814
+ item.parent[item.key] = item.data = query.notFoundDefault;
5815
+ }
5816
+ }
5817
+ } else if (notNullable) {
5803
5818
  for (const { data } of batches) {
5804
- if (data === void 0) throw new orchidCore.NotFoundError(arg);
5819
+ if (data === null) throw new orchidCore.NotFoundError(arg);
5805
5820
  }
5806
5821
  }
5807
5822
  if (hookSelect) {
@@ -5919,7 +5934,9 @@ const processSelectArg = (q, as, arg, columnAs) => {
5919
5934
  return false;
5920
5935
  }
5921
5936
  }
5922
- if (!orchidCore.isExpression(value) && orchidCore.isRelationQuery(value)) {
5937
+ if (!orchidCore.isExpression(value) && orchidCore.isRelationQuery(value) && // `subQuery = 1` case is when callback returns the same query as it gets,
5938
+ // for example `q => q.get('name')`.
5939
+ value.q.subQuery !== 1) {
5923
5940
  query.q.selectRelation = joinQuery = true;
5924
5941
  value = value.joinQuery(value, q);
5925
5942
  let subQuery;
@@ -6082,7 +6099,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
6082
6099
  key
6083
6100
  );
6084
6101
  } else if (orchidCore.isExpression(it)) {
6085
- result[key] = it.result.value;
6102
+ result[key] = it.result.value || UnknownColumn.instance;
6086
6103
  } else if (it) {
6087
6104
  const { returnType } = it.q;
6088
6105
  if (returnType === "value" || returnType === "valueOrThrow") {
@@ -7725,149 +7742,6 @@ function pushLimitSQL(sql, values, q) {
7725
7742
  }
7726
7743
  }
7727
7744
 
7728
- const { types } = pg;
7729
- const defaultTypeParsers = {};
7730
- for (const key in types.builtins) {
7731
- const id = types.builtins[key];
7732
- defaultTypeParsers[id] = types.getTypeParser(id);
7733
- }
7734
- [
7735
- types.builtins.DATE,
7736
- types.builtins.TIMESTAMP,
7737
- types.builtins.TIMESTAMPTZ,
7738
- types.builtins.TIME,
7739
- types.builtins.CIRCLE
7740
- ].forEach((id) => {
7741
- delete defaultTypeParsers[id];
7742
- });
7743
- const returnArg = (arg) => arg;
7744
- const rollbackSql = { text: "ROLLBACK" };
7745
- const commitSql = { text: "COMMIT" };
7746
- class Adapter {
7747
- constructor({ types: types2 = defaultTypeParsers, ...config }) {
7748
- this.types = types2;
7749
- let schema = config.schema;
7750
- if (config.databaseURL) {
7751
- const url = new URL(config.databaseURL);
7752
- const ssl = url.searchParams.get("ssl");
7753
- if (ssl === "false") {
7754
- url.searchParams.delete("ssl");
7755
- } else if (!config.ssl && ssl === "true") {
7756
- config.ssl = true;
7757
- }
7758
- if (!schema) {
7759
- schema = url.searchParams.get("schema") || void 0;
7760
- }
7761
- config.databaseURL = url.toString();
7762
- config.connectionString = config.databaseURL;
7763
- }
7764
- if (schema) this.schema = schema === "public" ? void 0 : schema;
7765
- this.config = config;
7766
- this.pool = new pg.Pool(config);
7767
- if (config.connectRetry) {
7768
- orchidCore.setAdapterConnectRetry(
7769
- this,
7770
- () => this.pool.connect(),
7771
- config.connectRetry === true ? orchidCore.emptyObject : config.connectRetry
7772
- );
7773
- }
7774
- }
7775
- connect() {
7776
- return this.pool.connect();
7777
- }
7778
- query(query, types2) {
7779
- return performQuery$1(this, query, types2);
7780
- }
7781
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7782
- arrays(query, types2) {
7783
- return performQuery$1(this, query, types2, "array");
7784
- }
7785
- async transaction(begin, cb, end = commitSql) {
7786
- const client = await this.connect();
7787
- try {
7788
- await setSearchPath(client, this.schema);
7789
- await performQueryOnClient(client, begin, this.types);
7790
- let result;
7791
- try {
7792
- result = await cb(new TransactionAdapter(this, client, this.types));
7793
- } catch (err) {
7794
- await performQueryOnClient(client, rollbackSql, this.types);
7795
- throw err;
7796
- }
7797
- await performQueryOnClient(client, end, this.types);
7798
- return result;
7799
- } finally {
7800
- client.release();
7801
- }
7802
- }
7803
- close() {
7804
- const { pool } = this;
7805
- this.pool = new pg.Pool(this.config);
7806
- return pool.end();
7807
- }
7808
- }
7809
- const defaultTypesConfig = {
7810
- getTypeParser(id) {
7811
- return defaultTypeParsers[id] || returnArg;
7812
- }
7813
- };
7814
- const setSearchPath = (client, schema) => {
7815
- if (client.connection.schema !== schema) {
7816
- client.connection.schema = schema;
7817
- return client.query(`SET search_path = ${schema || "public"}`);
7818
- }
7819
- return;
7820
- };
7821
- const performQuery$1 = async (adapter, query, types2, rowMode) => {
7822
- const client = await adapter.connect();
7823
- try {
7824
- await setSearchPath(client, adapter.schema);
7825
- return await performQueryOnClient(client, query, types2, rowMode);
7826
- } finally {
7827
- client.release();
7828
- }
7829
- };
7830
- const performQueryOnClient = (client, query, types2, rowMode) => {
7831
- const params = {
7832
- text: typeof query === "string" ? query : query.text,
7833
- values: typeof query === "string" ? void 0 : query.values,
7834
- rowMode,
7835
- types: types2 ? {
7836
- getTypeParser(id) {
7837
- return types2[id] || returnArg;
7838
- }
7839
- } : defaultTypesConfig
7840
- };
7841
- return client.query(params);
7842
- };
7843
- class TransactionAdapter {
7844
- constructor(adapter, client, types2) {
7845
- this.adapter = adapter;
7846
- this.client = client;
7847
- this.types = types2;
7848
- this.pool = adapter.pool;
7849
- this.config = adapter.config;
7850
- this.schema = adapter.schema;
7851
- }
7852
- connect() {
7853
- return Promise.resolve(this.client);
7854
- }
7855
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7856
- async query(query, types2) {
7857
- return await performQueryOnClient(this.client, query, types2);
7858
- }
7859
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7860
- async arrays(query, types2) {
7861
- return await performQueryOnClient(this.client, query, types2, "array");
7862
- }
7863
- async transaction(_, cb) {
7864
- return await cb(this);
7865
- }
7866
- close() {
7867
- return this.adapter.close();
7868
- }
7869
- }
7870
-
7871
7745
  class FnExpression extends orchidCore.Expression {
7872
7746
  /**
7873
7747
  * @param query - query object.
@@ -7976,14 +7850,18 @@ const isSelectingCount = (q) => {
7976
7850
  const { expr } = q.q;
7977
7851
  return expr instanceof FnExpression && expr.fn === "count" && expr.args[0] === "*";
7978
7852
  };
7979
- const int = new IntegerColumn(defaultSchemaConfig).parse(parseInt);
7980
- const float = new RealColumn(defaultSchemaConfig).parse(parseFloat);
7981
- const stringAsNumber = new NumberAsStringBaseColumn(
7853
+ const intNullable = new IntegerColumn(defaultSchemaConfig).nullable().parse(parseInt);
7854
+ const floatNullable = new RealColumn(defaultSchemaConfig).nullable().parse(parseFloat);
7855
+ const booleanNullable = BooleanColumn.instance.nullable();
7856
+ const textNullable = TextColumn.instance.nullable();
7857
+ const jsonTextNullable = JSONTextColumn.instance.nullable();
7858
+ const xmlNullable = XMLColumn.instance.nullable();
7859
+ const stringAsNumberNullable = new NumberAsStringBaseColumn(
7982
7860
  defaultSchemaConfig
7983
- );
7861
+ ).nullable();
7984
7862
  const numericResultColumn = (q, arg) => {
7985
7863
  const type = typeof arg === "string" ? _getSelectableColumn(q, arg) : arg.result.value;
7986
- return type instanceof NumberBaseColumn ? float : stringAsNumber;
7864
+ return type instanceof NumberBaseColumn ? floatNullable : stringAsNumberNullable;
7987
7865
  };
7988
7866
  class AggregateMethods {
7989
7867
  /**
@@ -8026,7 +7904,13 @@ class AggregateMethods {
8026
7904
  * @param options - aggregation options
8027
7905
  */
8028
7906
  count(arg = "*", options) {
8029
- return makeFnExpression(this, int, "count", [arg], options);
7907
+ return makeFnExpression(
7908
+ this,
7909
+ intNullable,
7910
+ "count",
7911
+ [arg],
7912
+ options
7913
+ );
8030
7914
  }
8031
7915
  /**
8032
7916
  * Get the minimum value for the specified numeric column, returns number or `null` if there are no records.
@@ -8221,7 +8105,7 @@ class AggregateMethods {
8221
8105
  boolAnd(arg, options) {
8222
8106
  return makeFnExpression(
8223
8107
  this,
8224
- BooleanColumn.instance,
8108
+ booleanNullable,
8225
8109
  "bool_and",
8226
8110
  [arg],
8227
8111
  options
@@ -8250,7 +8134,7 @@ class AggregateMethods {
8250
8134
  boolOr(arg, options) {
8251
8135
  return makeFnExpression(
8252
8136
  this,
8253
- BooleanColumn.instance,
8137
+ booleanNullable,
8254
8138
  "bool_or",
8255
8139
  [arg],
8256
8140
  options
@@ -8262,7 +8146,7 @@ class AggregateMethods {
8262
8146
  every(arg, options) {
8263
8147
  return makeFnExpression(
8264
8148
  this,
8265
- BooleanColumn.instance,
8149
+ booleanNullable,
8266
8150
  "every",
8267
8151
  [arg],
8268
8152
  options
@@ -8295,7 +8179,7 @@ class AggregateMethods {
8295
8179
  jsonAgg(arg, options) {
8296
8180
  return makeFnExpression(
8297
8181
  this,
8298
- JSONTextColumn.instance,
8182
+ jsonTextNullable,
8299
8183
  "json_agg",
8300
8184
  [arg],
8301
8185
  options
@@ -8307,7 +8191,7 @@ class AggregateMethods {
8307
8191
  jsonbAgg(arg, options) {
8308
8192
  return makeFnExpression(
8309
8193
  this,
8310
- JSONTextColumn.instance,
8194
+ jsonTextNullable,
8311
8195
  "jsonb_agg",
8312
8196
  [arg],
8313
8197
  options
@@ -8348,7 +8232,7 @@ class AggregateMethods {
8348
8232
  jsonObjectAgg(arg, options) {
8349
8233
  return makeFnExpression(
8350
8234
  this,
8351
- JSONTextColumn.instance,
8235
+ jsonTextNullable,
8352
8236
  "json_object_agg",
8353
8237
  [{ pairs: arg }],
8354
8238
  options
@@ -8360,7 +8244,7 @@ class AggregateMethods {
8360
8244
  jsonbObjectAgg(arg, options) {
8361
8245
  return makeFnExpression(
8362
8246
  this,
8363
- JSONTextColumn.instance,
8247
+ jsonTextNullable,
8364
8248
  "jsonb_object_agg",
8365
8249
  [{ pairs: arg }],
8366
8250
  options
@@ -8391,7 +8275,7 @@ class AggregateMethods {
8391
8275
  stringAgg(arg, delimiter, options) {
8392
8276
  return makeFnExpression(
8393
8277
  this,
8394
- TextColumn.instance,
8278
+ textNullable,
8395
8279
  "string_agg",
8396
8280
  [arg, { value: delimiter }],
8397
8281
  options
@@ -8417,7 +8301,7 @@ class AggregateMethods {
8417
8301
  xmlAgg(arg, options) {
8418
8302
  return makeFnExpression(
8419
8303
  this,
8420
- XMLColumn.instance,
8304
+ xmlNullable,
8421
8305
  "xmlagg",
8422
8306
  [arg],
8423
8307
  options
@@ -8442,7 +8326,7 @@ class AggregateMethods {
8442
8326
  * @param over - OVER clause config
8443
8327
  */
8444
8328
  rowNumber(over) {
8445
- return makeFnExpression(this, int, "row_number", orchidCore.emptyArray, {
8329
+ return makeFnExpression(this, intNullable, "row_number", orchidCore.emptyArray, {
8446
8330
  over
8447
8331
  });
8448
8332
  }
@@ -8465,7 +8349,7 @@ class AggregateMethods {
8465
8349
  * @param over - OVER clause config
8466
8350
  */
8467
8351
  rank(over) {
8468
- return makeFnExpression(this, int, "rank", orchidCore.emptyArray, {
8352
+ return makeFnExpression(this, intNullable, "rank", orchidCore.emptyArray, {
8469
8353
  over
8470
8354
  });
8471
8355
  }
@@ -8488,7 +8372,7 @@ class AggregateMethods {
8488
8372
  * @param over - OVER clause config
8489
8373
  */
8490
8374
  denseRank(over) {
8491
- return makeFnExpression(this, int, "dense_rank", orchidCore.emptyArray, {
8375
+ return makeFnExpression(this, intNullable, "dense_rank", orchidCore.emptyArray, {
8492
8376
  over
8493
8377
  });
8494
8378
  }
@@ -8511,7 +8395,7 @@ class AggregateMethods {
8511
8395
  * @param over - OVER clause config
8512
8396
  */
8513
8397
  percentRank(over) {
8514
- return makeFnExpression(this, int, "percent_rank", orchidCore.emptyArray, {
8398
+ return makeFnExpression(this, intNullable, "percent_rank", orchidCore.emptyArray, {
8515
8399
  over
8516
8400
  });
8517
8401
  }
@@ -8534,7 +8418,7 @@ class AggregateMethods {
8534
8418
  * @param over - OVER clause config
8535
8419
  */
8536
8420
  cumeDist(over) {
8537
- return makeFnExpression(this, float, "cume_dist", orchidCore.emptyArray, {
8421
+ return makeFnExpression(this, floatNullable, "cume_dist", orchidCore.emptyArray, {
8538
8422
  over
8539
8423
  });
8540
8424
  }
@@ -12266,7 +12150,7 @@ class QueryMethods {
12266
12150
  * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
12267
12151
  */
12268
12152
  findBy(uniqueColumnValues) {
12269
- return _queryFindBy(_clone(this), [uniqueColumnValues]);
12153
+ return _queryFindBy(_clone(this), uniqueColumnValues);
12270
12154
  }
12271
12155
  /**
12272
12156
  * Finds a single unique record, returns `undefined` if not found.
@@ -12282,9 +12166,10 @@ class QueryMethods {
12282
12166
  * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
12283
12167
  */
12284
12168
  findByOptional(uniqueColumnValues) {
12285
- return _queryFindByOptional(_clone(this), [
12169
+ return _queryFindByOptional(
12170
+ _clone(this),
12286
12171
  uniqueColumnValues
12287
- ]);
12172
+ );
12288
12173
  }
12289
12174
  /**
12290
12175
  * Specifies the schema to be used as a prefix of a table name.
@@ -12879,7 +12764,8 @@ const performQuery = async (q, args, method) => {
12879
12764
  if (log) logData = log.beforeQuery(sql);
12880
12765
  try {
12881
12766
  const result = await (trx?.adapter || q.adapter)[method](
12882
- sql
12767
+ sql.text,
12768
+ sql.values
12883
12769
  );
12884
12770
  if (log) log.afterQuery(sql, logData);
12885
12771
  return result;
@@ -13165,7 +13051,7 @@ class Db extends QueryMethods {
13165
13051
  }
13166
13052
  orchidCore.applyMixins(Db, [QueryMethods]);
13167
13053
  Db.prototype.constructor = Db;
13168
- const createDb = ({
13054
+ const createDbWithAdapter = ({
13169
13055
  log,
13170
13056
  logger,
13171
13057
  snakeCase,
@@ -13173,7 +13059,7 @@ const createDb = ({
13173
13059
  columnTypes: ctOrFn = makeColumnTypes(schemaConfig),
13174
13060
  ...options
13175
13061
  }) => {
13176
- const adapter = "adapter" in options ? options.adapter : new Adapter(options);
13062
+ const { adapter } = options;
13177
13063
  const commonOptions = {
13178
13064
  log,
13179
13065
  logger,
@@ -13370,7 +13256,6 @@ function copyTableData(query, arg) {
13370
13256
  return q;
13371
13257
  }
13372
13258
 
13373
- exports.Adapter = Adapter;
13374
13259
  exports.AfterCommitError = AfterCommitError;
13375
13260
  exports.AggregateMethods = AggregateMethods;
13376
13261
  exports.ArrayColumn = ArrayColumn;
@@ -13454,7 +13339,6 @@ exports.TimeColumn = TimeColumn;
13454
13339
  exports.TimestampColumn = TimestampColumn;
13455
13340
  exports.TimestampTZColumn = TimestampTZColumn;
13456
13341
  exports.Transaction = Transaction;
13457
- exports.TransactionAdapter = TransactionAdapter;
13458
13342
  exports.TransformMethods = TransformMethods;
13459
13343
  exports.TsQueryColumn = TsQueryColumn;
13460
13344
  exports.TsVectorColumn = TsVectorColumn;
@@ -13537,12 +13421,12 @@ exports.columnExcludesToCode = columnExcludesToCode;
13537
13421
  exports.columnForeignKeysToCode = columnForeignKeysToCode;
13538
13422
  exports.columnIndexesToCode = columnIndexesToCode;
13539
13423
  exports.columnsShapeToCode = columnsShapeToCode;
13540
- exports.commitSql = commitSql$1;
13424
+ exports.commitSql = commitSql;
13541
13425
  exports.constraintInnerToCode = constraintInnerToCode;
13542
13426
  exports.constraintToCode = constraintToCode;
13543
13427
  exports.copyTableData = copyTableData;
13544
13428
  exports.countSelect = countSelect;
13545
- exports.createDb = createDb;
13429
+ exports.createDbWithAdapter = createDbWithAdapter;
13546
13430
  exports.defaultSchemaConfig = defaultSchemaConfig;
13547
13431
  exports.escapeForLog = escapeForLog;
13548
13432
  exports.escapeForMigration = escapeForMigration;
@@ -13597,7 +13481,7 @@ exports.queryWrap = queryWrap;
13597
13481
  exports.raw = raw;
13598
13482
  exports.referencesArgsToCode = referencesArgsToCode;
13599
13483
  exports.resolveSubQueryCallbackV2 = resolveSubQueryCallbackV2;
13600
- exports.rollbackSql = rollbackSql$1;
13484
+ exports.rollbackSql = rollbackSql;
13601
13485
  exports.saveAliasedShape = saveAliasedShape;
13602
13486
  exports.setColumnDefaultParse = setColumnDefaultParse;
13603
13487
  exports.setColumnEncode = setColumnEncode;