pqb 0.55.1 → 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.d.ts +26 -72
- package/dist/index.js +117 -252
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -250
- package/dist/index.mjs.map +1 -1
- package/dist/node-postgres.d.ts +65 -0
- package/dist/node-postgres.js +242 -0
- package/dist/node-postgres.js.map +1 -0
- package/dist/node-postgres.mjs +238 -0
- package/dist/node-postgres.mjs.map +1 -0
- package/dist/postgres-js.d.ts +58 -0
- package/dist/postgres-js.js +221 -0
- package/dist/postgres-js.js.map +1 -0
- package/dist/postgres-js.mjs +217 -0
- package/dist/postgres-js.mjs.map +1 -0
- package/package.json +26 -7
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
|
-
|
|
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
|
-
|
|
2791
|
-
|
|
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,
|
|
3347
|
-
|
|
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
|
|
3350
|
-
|
|
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
|
|
4566
|
+
const commitSql = {
|
|
4543
4567
|
text: "COMMIT"
|
|
4544
4568
|
};
|
|
4545
|
-
const rollbackSql
|
|
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
|
|
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
|
-
|
|
4610
|
-
if (
|
|
4611
|
-
|
|
4612
|
-
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
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
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
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
|
-
|
|
5132
|
-
|
|
5133
|
-
await
|
|
5134
|
-
|
|
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
|
|
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
|
-
|
|
5318
|
-
|
|
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;
|
|
@@ -5919,7 +5925,9 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5919
5925
|
return false;
|
|
5920
5926
|
}
|
|
5921
5927
|
}
|
|
5922
|
-
if (!orchidCore.isExpression(value) && orchidCore.isRelationQuery(value)
|
|
5928
|
+
if (!orchidCore.isExpression(value) && orchidCore.isRelationQuery(value) && // `subQuery = 1` case is when callback returns the same query as it gets,
|
|
5929
|
+
// for example `q => q.get('name')`.
|
|
5930
|
+
value.q.subQuery !== 1) {
|
|
5923
5931
|
query.q.selectRelation = joinQuery = true;
|
|
5924
5932
|
value = value.joinQuery(value, q);
|
|
5925
5933
|
let subQuery;
|
|
@@ -6082,7 +6090,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
|
|
|
6082
6090
|
key
|
|
6083
6091
|
);
|
|
6084
6092
|
} else if (orchidCore.isExpression(it)) {
|
|
6085
|
-
result[key] = it.result.value;
|
|
6093
|
+
result[key] = it.result.value || UnknownColumn.instance;
|
|
6086
6094
|
} else if (it) {
|
|
6087
6095
|
const { returnType } = it.q;
|
|
6088
6096
|
if (returnType === "value" || returnType === "valueOrThrow") {
|
|
@@ -7725,149 +7733,6 @@ function pushLimitSQL(sql, values, q) {
|
|
|
7725
7733
|
}
|
|
7726
7734
|
}
|
|
7727
7735
|
|
|
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
7736
|
class FnExpression extends orchidCore.Expression {
|
|
7872
7737
|
/**
|
|
7873
7738
|
* @param query - query object.
|
|
@@ -12266,7 +12131,7 @@ class QueryMethods {
|
|
|
12266
12131
|
* @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
|
|
12267
12132
|
*/
|
|
12268
12133
|
findBy(uniqueColumnValues) {
|
|
12269
|
-
return _queryFindBy(_clone(this),
|
|
12134
|
+
return _queryFindBy(_clone(this), uniqueColumnValues);
|
|
12270
12135
|
}
|
|
12271
12136
|
/**
|
|
12272
12137
|
* Finds a single unique record, returns `undefined` if not found.
|
|
@@ -12282,9 +12147,10 @@ class QueryMethods {
|
|
|
12282
12147
|
* @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
|
|
12283
12148
|
*/
|
|
12284
12149
|
findByOptional(uniqueColumnValues) {
|
|
12285
|
-
return _queryFindByOptional(
|
|
12150
|
+
return _queryFindByOptional(
|
|
12151
|
+
_clone(this),
|
|
12286
12152
|
uniqueColumnValues
|
|
12287
|
-
|
|
12153
|
+
);
|
|
12288
12154
|
}
|
|
12289
12155
|
/**
|
|
12290
12156
|
* Specifies the schema to be used as a prefix of a table name.
|
|
@@ -12879,7 +12745,8 @@ const performQuery = async (q, args, method) => {
|
|
|
12879
12745
|
if (log) logData = log.beforeQuery(sql);
|
|
12880
12746
|
try {
|
|
12881
12747
|
const result = await (trx?.adapter || q.adapter)[method](
|
|
12882
|
-
sql
|
|
12748
|
+
sql.text,
|
|
12749
|
+
sql.values
|
|
12883
12750
|
);
|
|
12884
12751
|
if (log) log.afterQuery(sql, logData);
|
|
12885
12752
|
return result;
|
|
@@ -13165,7 +13032,7 @@ class Db extends QueryMethods {
|
|
|
13165
13032
|
}
|
|
13166
13033
|
orchidCore.applyMixins(Db, [QueryMethods]);
|
|
13167
13034
|
Db.prototype.constructor = Db;
|
|
13168
|
-
const
|
|
13035
|
+
const createDbWithAdapter = ({
|
|
13169
13036
|
log,
|
|
13170
13037
|
logger,
|
|
13171
13038
|
snakeCase,
|
|
@@ -13173,7 +13040,7 @@ const createDb = ({
|
|
|
13173
13040
|
columnTypes: ctOrFn = makeColumnTypes(schemaConfig),
|
|
13174
13041
|
...options
|
|
13175
13042
|
}) => {
|
|
13176
|
-
const
|
|
13043
|
+
const { adapter } = options;
|
|
13177
13044
|
const commonOptions = {
|
|
13178
13045
|
log,
|
|
13179
13046
|
logger,
|
|
@@ -13370,7 +13237,6 @@ function copyTableData(query, arg) {
|
|
|
13370
13237
|
return q;
|
|
13371
13238
|
}
|
|
13372
13239
|
|
|
13373
|
-
exports.Adapter = Adapter;
|
|
13374
13240
|
exports.AfterCommitError = AfterCommitError;
|
|
13375
13241
|
exports.AggregateMethods = AggregateMethods;
|
|
13376
13242
|
exports.ArrayColumn = ArrayColumn;
|
|
@@ -13454,7 +13320,6 @@ exports.TimeColumn = TimeColumn;
|
|
|
13454
13320
|
exports.TimestampColumn = TimestampColumn;
|
|
13455
13321
|
exports.TimestampTZColumn = TimestampTZColumn;
|
|
13456
13322
|
exports.Transaction = Transaction;
|
|
13457
|
-
exports.TransactionAdapter = TransactionAdapter;
|
|
13458
13323
|
exports.TransformMethods = TransformMethods;
|
|
13459
13324
|
exports.TsQueryColumn = TsQueryColumn;
|
|
13460
13325
|
exports.TsVectorColumn = TsVectorColumn;
|
|
@@ -13537,12 +13402,12 @@ exports.columnExcludesToCode = columnExcludesToCode;
|
|
|
13537
13402
|
exports.columnForeignKeysToCode = columnForeignKeysToCode;
|
|
13538
13403
|
exports.columnIndexesToCode = columnIndexesToCode;
|
|
13539
13404
|
exports.columnsShapeToCode = columnsShapeToCode;
|
|
13540
|
-
exports.commitSql = commitSql
|
|
13405
|
+
exports.commitSql = commitSql;
|
|
13541
13406
|
exports.constraintInnerToCode = constraintInnerToCode;
|
|
13542
13407
|
exports.constraintToCode = constraintToCode;
|
|
13543
13408
|
exports.copyTableData = copyTableData;
|
|
13544
13409
|
exports.countSelect = countSelect;
|
|
13545
|
-
exports.
|
|
13410
|
+
exports.createDbWithAdapter = createDbWithAdapter;
|
|
13546
13411
|
exports.defaultSchemaConfig = defaultSchemaConfig;
|
|
13547
13412
|
exports.escapeForLog = escapeForLog;
|
|
13548
13413
|
exports.escapeForMigration = escapeForMigration;
|
|
@@ -13597,7 +13462,7 @@ exports.queryWrap = queryWrap;
|
|
|
13597
13462
|
exports.raw = raw;
|
|
13598
13463
|
exports.referencesArgsToCode = referencesArgsToCode;
|
|
13599
13464
|
exports.resolveSubQueryCallbackV2 = resolveSubQueryCallbackV2;
|
|
13600
|
-
exports.rollbackSql = rollbackSql
|
|
13465
|
+
exports.rollbackSql = rollbackSql;
|
|
13601
13466
|
exports.saveAliasedShape = saveAliasedShape;
|
|
13602
13467
|
exports.setColumnDefaultParse = setColumnDefaultParse;
|
|
13603
13468
|
exports.setColumnEncode = setColumnEncode;
|