orange-orm 4.5.0-beta.0 → 4.5.0-beta.1
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/README.md +6 -1
- package/docs/changelog.md +4 -0
- package/package.json +8 -5
- package/src/client/index.js +3 -2
- package/src/client/index.mjs +253 -137
- package/src/createDomain.js +11 -16
- package/src/d1/newDatabase.js +23 -37
- package/src/d1/newPool.js +6 -6
- package/src/d1/pool/newGenericPool.js +2 -1
- package/src/emitEvent.js +6 -4
- package/src/emptyFilter.js +12 -12
- package/src/getManyDto/newQuery.js +5 -5
- package/src/getManyDto/query/newSingleQuery.js +5 -5
- package/src/getManyDto.js +25 -24
- package/src/hostExpress/cycle.ts +211 -0
- package/src/hostExpress/executePath.js +360 -357
- package/src/hostLocal.js +8 -8
- package/src/index.js +11 -16
- package/src/mssql/newDatabase.js +19 -31
- package/src/mssql/newPool.js +2 -2
- package/src/mssql/newTransaction.js +4 -3
- package/src/mssql/pool/newGenericPool.js +1 -1
- package/src/mySql/deleteFromSql.js +1 -1
- package/src/mySql/insert.js +5 -5
- package/src/mySql/insertSql.js +2 -3
- package/src/mySql/lastInsertedSql.js +3 -4
- package/src/mySql/newDatabase.js +20 -34
- package/src/mySql/newPool.js +10 -10
- package/src/mySql/newTransaction.js +2 -2
- package/src/mySql/pool/newGenericPool.js +2 -3
- package/src/mySql/quote.js +1 -0
- package/src/newImmutable.js +1 -2
- package/src/oracle/deleteFromSql.js +1 -1
- package/src/oracle/formatDateOut.js +1 -1
- package/src/oracle/insert.js +6 -6
- package/src/oracle/insertSql.js +6 -14
- package/src/oracle/lastInsertedSql.js +3 -3
- package/src/oracle/mergeSql.js +3 -6
- package/src/oracle/newDatabase.js +18 -33
- package/src/oracle/newInsertCommandCore.js +3 -3
- package/src/oracle/newPool.js +10 -10
- package/src/oracle/newTransaction.js +2 -1
- package/src/oracle/pool/newGenericPool.js +2 -2
- package/src/oracle/quote.js +1 -0
- package/src/oracle/wrapQuery.js +0 -3
- package/src/patchRow.js +2 -2
- package/src/patchTable.js +6 -5
- package/src/pg/deleteFromSql.js +1 -1
- package/src/pg/formatDateOut.js +1 -2
- package/src/pg/insert.js +3 -3
- package/src/pg/insertSql.js +2 -7
- package/src/pg/lastInsertedSql.js +1 -2
- package/src/pg/newDatabase.js +20 -37
- package/src/pg/newPool.js +10 -10
- package/src/pg/newTransaction.js +2 -1
- package/src/pg/pool/newPgPool.js +23 -4
- package/src/pg/pool/parseSearchPathParam.js +10 -0
- package/src/pg/quote.js +2 -0
- package/src/pg/schema.js +2 -2
- package/src/{mySql/pool/defaults.js → poolDefaults.js} +0 -2
- package/src/query.js +2 -2
- package/src/sap/deleteFromSql.js +1 -1
- package/src/sap/formatDateOut.js +1 -1
- package/src/sap/insert.js +5 -5
- package/src/sap/insertSql.js +4 -5
- package/src/sap/lastInsertedSql.js +3 -3
- package/src/sap/mergeSql.js +1 -2
- package/src/sap/newDatabase.js +23 -34
- package/src/sap/newPool.js +2 -2
- package/src/sap/newTransaction.js +2 -1
- package/src/sap/quote.js +1 -0
- package/src/sqlite/deleteFromSql.js +1 -1
- package/src/sqlite/insert.js +5 -5
- package/src/sqlite/insertSql.js +2 -2
- package/src/sqlite/lastInsertedSql.js +2 -2
- package/src/sqlite/newDatabase.js +16 -32
- package/src/sqlite/newPool.js +10 -10
- package/src/sqlite/newTransaction.js +2 -1
- package/src/sqlite/pool/newGenericPool.js +2 -1
- package/src/sqlite/quote.js +1 -0
- package/src/table/aggregate.js +1 -1
- package/src/table/begin.js +5 -5
- package/src/table/cascadeDelete.js +2 -2
- package/src/table/column/binary/newDecode.js +2 -2
- package/src/table/column/binary/newEncode.js +3 -4
- package/src/table/column/boolean/newDecode.js +1 -1
- package/src/table/column/boolean/newEncode.js +6 -6
- package/src/table/column/date/formatOut.js +3 -5
- package/src/table/column/date/newDecode.js +2 -2
- package/src/table/column/date/newEncode.js +8 -8
- package/src/table/column/date/tryParseISO.js +6 -8
- package/src/table/column/date.js +1 -1
- package/src/table/column/dateWithTimeZone/newEncode.js +3 -4
- package/src/table/column/dateWithTimeZone.js +1 -1
- package/src/table/column/encodeFilterArg.js +3 -3
- package/src/table/column/equal.js +3 -3
- package/src/table/column/extractAlias.js +0 -2
- package/src/table/column/greaterThan.js +3 -3
- package/src/table/column/greaterThanOrEqual.js +3 -3
- package/src/table/column/guid/newDecode.js +1 -1
- package/src/table/column/guid/newEncode.js +3 -3
- package/src/table/column/in.js +3 -3
- package/src/table/column/json/formatOut.js +3 -3
- package/src/table/column/json/newDecode.js +3 -3
- package/src/table/column/json/newEncode.js +6 -6
- package/src/table/column/json.js +2 -1
- package/src/table/column/lessThan.js +3 -3
- package/src/table/column/lessThanOrEqual.js +4 -4
- package/src/table/column/negotiateRawSqlFilter.js +9 -9
- package/src/table/column/newBoolean.js +9 -9
- package/src/table/column/newColumn.js +21 -21
- package/src/table/column/newDecodeCore.js +1 -1
- package/src/table/column/notEqual.js +3 -3
- package/src/table/column/numeric/newDecode.js +2 -2
- package/src/table/column/numeric/newEncode.js +3 -3
- package/src/table/column/string/contains.js +2 -1
- package/src/table/column/string/containsCore.js +5 -5
- package/src/table/column/string/endsWith.js +1 -1
- package/src/table/column/string/endsWithCore.js +4 -4
- package/src/table/column/string/iContains.js +2 -1
- package/src/table/column/string/iEndsWith.js +1 -1
- package/src/table/column/string/iEqual.js +3 -3
- package/src/table/column/string/iStartsWith.js +1 -1
- package/src/table/column/string/newEncode.js +3 -3
- package/src/table/column/string/startsWith.js +1 -1
- package/src/table/column/string/startsWithCore.js +4 -4
- package/src/table/column/string.js +14 -14
- package/src/table/commands/beginCommand.js +2 -2
- package/src/table/commands/compressChanges.js +2 -2
- package/src/table/commands/delete/newSingleCommand.js +5 -5
- package/src/table/commands/delete/singleCommand/joinSql.js +12 -12
- package/src/table/commands/delete/singleCommand/newSingleCommandCore.js +2 -2
- package/src/table/commands/delete/singleCommand/selectSql.js +6 -6
- package/src/table/commands/delete/singleCommand/subFilter.js +11 -11
- package/src/table/commands/delete/singleCommand/whereSql.js +2 -2
- package/src/table/commands/getChangeSet.js +2 -2
- package/src/table/commands/insert/getSqlTemplate.js +16 -16
- package/src/table/commands/lastCommandMatches.js +2 -2
- package/src/table/commands/newDeleteCommand.js +5 -5
- package/src/table/commands/newGetLastInsertedCommand.js +4 -4
- package/src/table/commands/newGetLastInsertedCommandCore.js +5 -5
- package/src/table/commands/newInsertCommand.js +0 -1
- package/src/table/commands/newInsertCommandCore.js +3 -3
- package/src/table/commands/newRow.js +4 -4
- package/src/table/commands/newUpdateCommand.js +4 -4
- package/src/table/commands/newUpdateCommandCore.js +4 -4
- package/src/table/commands/pushCommand.js +2 -2
- package/src/table/commit.js +13 -11
- package/src/table/count.js +8 -8
- package/src/table/delete.js +4 -4
- package/src/table/deleteSessionContext.js +4 -13
- package/src/table/executeQueries/executeChanges.js +3 -3
- package/src/table/executeQueries/executeQueriesCore.js +2 -2
- package/src/table/executeQueries/executeQuery.js +2 -2
- package/src/table/executeQueries/resolveExecuteQuery.js +4 -4
- package/src/table/executeQueries.js +4 -4
- package/src/table/getFromDbById.js +1 -1
- package/src/table/getMany.js +7 -7
- package/src/table/getManyDto.js +3 -4
- package/src/table/getSessionContext.js +4 -4
- package/src/table/getSessionSingleton.js +3 -2
- package/src/table/groupBy/newQuery.js +4 -4
- package/src/table/groupBy.js +9 -9
- package/src/table/insert.js +10 -13
- package/src/table/joinRelation/getRelatives.js +6 -6
- package/src/table/newGetRelated.js +3 -3
- package/src/table/newManyRelation.js +9 -9
- package/src/table/newOneRelation.js +9 -9
- package/src/table/newPrimaryKeyFilter.js +6 -6
- package/src/table/newQuery.js +5 -5
- package/src/table/newRelatedTable.js +2 -2
- package/src/table/newRowCache.js +17 -17
- package/src/table/newThrow.js +2 -2
- package/src/table/oneRelation/getRelatives.js +5 -5
- package/src/table/popChanges.js +3 -3
- package/src/table/promise.js +2 -8
- package/src/table/query/extractLimit.js +2 -2
- package/src/table/query/extractOffset.js +2 -2
- package/src/table/query/extractOrderBy.js +2 -2
- package/src/table/query/newSingleQuery.js +7 -7
- package/src/table/query/singleQuery/columnSql/joinLegToColumnSql.js +5 -5
- package/src/table/query/singleQuery/columnSql/newJoinedColumnSql.js +2 -2
- package/src/table/query/singleQuery/columnSql/newShallowColumnSql.js +4 -4
- package/src/table/query/singleQuery/joinSql/joinLegToJoinSql.js +2 -2
- package/src/table/query/singleQuery/joinSql/joinLegToShallowJoinSql.js +2 -2
- package/src/table/query/singleQuery/joinSql/newDiscriminatorSql.js +2 -2
- package/src/table/query/singleQuery/joinSql/newShallowJoinSql.js +5 -5
- package/src/table/query/singleQuery/joinSql/newShallowJoinSqlCore.js +6 -5
- package/src/table/query/singleQuery/joinSql/oneLegToJoinSql.js +2 -2
- package/src/table/query/singleQuery/joinSql/oneLegToShallowJoinSql.js +2 -2
- package/src/table/query/singleQuery/negotiateExclusive.js +2 -2
- package/src/table/query/singleQuery/newColumnSql.js +3 -3
- package/src/table/query/singleQuery/newDiscriminatorSql.js +2 -2
- package/src/table/query/singleQuery/newJoinSql.js +6 -6
- package/src/table/query/singleQuery/newWhereSql.js +3 -3
- package/src/table/quote.js +4 -4
- package/src/table/relatedTable/aggregate.js +2 -2
- package/src/table/relatedTable/all.js +5 -5
- package/src/table/relatedTable/any.js +3 -3
- package/src/table/relatedTable/childColumn.js +12 -12
- package/src/table/relatedTable/columnAggregate.js +3 -3
- package/src/table/relatedTable/columnAggregateGroup.js +11 -11
- package/src/table/relatedTable/joinSql.js +5 -5
- package/src/table/relatedTable/joinSqlArray.js +3 -3
- package/src/table/relatedTable/none.js +3 -3
- package/src/table/relatedTable/relatedColumn.js +13 -13
- package/src/table/relatedTable/selectSql.js +2 -2
- package/src/table/relatedTable/subFilter.js +4 -4
- package/src/table/relatedTable/where.js +3 -3
- package/src/table/relatedTable/whereSql.js +2 -2
- package/src/table/relation/manyCache/synchronizeAdded.js +2 -2
- package/src/table/relation/manyCache/synchronizeChanged.js +3 -3
- package/src/table/relation/manyCache/synchronizeRemoved.js +2 -2
- package/src/table/relation/newForeignKeyFilter.js +2 -2
- package/src/table/relation/newManyCache.js +16 -16
- package/src/table/relation/newOneCache.js +6 -6
- package/src/table/releaseDbClient.js +4 -4
- package/src/table/resultToPromise.js +1 -3
- package/src/table/resultToRows/dbRowToRow.js +8 -8
- package/src/table/resultToRows/dbRowsToRows.js +2 -2
- package/src/table/resultToRows/decodeDbRow.js +2 -2
- package/src/table/resultToRows/delete/removeFromCache.js +6 -6
- package/src/table/resultToRows/delete.js +6 -6
- package/src/table/resultToRows/newDecodeDbRow.js +19 -18
- package/src/table/resultToRows/toDto.js +3 -3
- package/src/table/resultToRows.js +3 -3
- package/src/table/rollback.js +21 -11
- package/src/table/rowArray/negotiateNextTick.js +1 -2
- package/src/table/setSessionSingleton.js +6 -3
- package/src/table/tryGetFirstFromDb.js +4 -4
- package/src/table/tryGetFromCacheById.js +3 -3
- package/src/table/tryGetFromDbById/extractStrategy.js +2 -2
- package/src/table/tryGetFromDbById.js +8 -6
- package/src/table/tryGetSessionContext.js +5 -10
- package/src/table/tryReleaseDbClient.js +2 -2
- package/src/table/updateField.js +4 -4
- package/src/table/where.js +2 -2
- package/src/table.js +58 -51
- package/src/tedious/deleteFromSql.js +1 -1
- package/src/tedious/formatDateOut.js +1 -1
- package/src/tedious/getManyDto/newQueryCore.js +5 -5
- package/src/tedious/getManyDto/query/newSingleQuery.js +5 -5
- package/src/tedious/getManyDto/query/newSubQueries/joinLegToQuery.js +3 -3
- package/src/tedious/getManyDto/query/newSubQueries/manyLegToQuery.js +3 -3
- package/src/tedious/getManyDto/query/newSubQueries/oneLegToQuery.js +4 -4
- package/src/tedious/getManyDto/query/newSubQueries.js +8 -8
- package/src/tedious/getManyDto/query/singleQuery/newShallowColumnSql.js +5 -6
- package/src/tedious/getManyDto.js +6 -6
- package/src/tedious/insert.js +3 -3
- package/src/tedious/insertSql.js +3 -3
- package/src/tedious/newDatabase.js +17 -30
- package/src/tedious/newPool.js +10 -10
- package/src/tedious/newTransaction.js +3 -4
- package/src/tedious/pool/newGenericPool.js +1 -1
- package/src/tedious/quote.js +1 -0
- package/src/d1/pool/defaults.js +0 -45
- package/src/mssql/pool/defaults.js +0 -45
- package/src/oracle/pool/defaults.js +0 -45
- package/src/pg/pool/defaults.js +0 -45
- package/src/sqlite/pool/defaults.js +0 -45
- package/src/tedious/pool/defaults.js +0 -45
|
@@ -4,10 +4,6 @@ let _begin = require('../table/begin');
|
|
|
4
4
|
let commit = require('../table/commit');
|
|
5
5
|
let rollback = require('../table/rollback');
|
|
6
6
|
let newPool = require('./newPool');
|
|
7
|
-
let useHook = require('../useHook');
|
|
8
|
-
let promise = require('promise/domains');
|
|
9
|
-
let versionArray = process.version.replace('v', '').split('.');
|
|
10
|
-
let major = parseInt(versionArray[0]);
|
|
11
7
|
let express = require('../hostExpress');
|
|
12
8
|
let hostLocal = require('../hostLocal');
|
|
13
9
|
let doQuery = require('../query');
|
|
@@ -34,15 +30,12 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
34
30
|
|
|
35
31
|
if (fn)
|
|
36
32
|
return domain.run(runInTransaction);
|
|
37
|
-
else if ((major >= 12) && useHook()) {
|
|
38
|
-
domain.exitContext = true;
|
|
39
|
-
return domain.start().then(run);
|
|
40
|
-
}
|
|
41
33
|
else
|
|
42
34
|
return domain.run(run);
|
|
43
35
|
|
|
36
|
+
|
|
44
37
|
function begin() {
|
|
45
|
-
return _begin(options
|
|
38
|
+
return _begin(domain, options);
|
|
46
39
|
}
|
|
47
40
|
|
|
48
41
|
async function runInTransaction() {
|
|
@@ -50,68 +43,60 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
50
43
|
let transaction = newTransaction(domain, pool, options);
|
|
51
44
|
await new Promise(transaction)
|
|
52
45
|
.then(begin)
|
|
53
|
-
.then(fn)
|
|
46
|
+
.then(() => fn(domain))
|
|
54
47
|
.then((res) => result = res)
|
|
55
|
-
.then(
|
|
56
|
-
.then(null,
|
|
48
|
+
.then(() => commit(domain))
|
|
49
|
+
.then(null, (e) => rollback(domain, e));
|
|
57
50
|
return result;
|
|
51
|
+
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
function run() {
|
|
61
55
|
let p;
|
|
62
56
|
let transaction = newTransaction(domain, pool, options);
|
|
63
|
-
|
|
64
|
-
p = new Promise(transaction);
|
|
65
|
-
else
|
|
66
|
-
p = new promise(transaction);
|
|
57
|
+
p = new Promise(transaction);
|
|
67
58
|
|
|
68
59
|
return p.then(begin);
|
|
69
60
|
}
|
|
70
61
|
|
|
71
62
|
};
|
|
72
63
|
|
|
73
|
-
c.createTransaction = function() {
|
|
64
|
+
c.createTransaction = function(options) {
|
|
74
65
|
let domain = createDomain();
|
|
75
66
|
let transaction = newTransaction(domain, pool);
|
|
76
|
-
let p = domain.run(() => new Promise(transaction).then(
|
|
67
|
+
let p = domain.run(() => new Promise(transaction).then(begin));
|
|
77
68
|
|
|
78
69
|
function run(fn) {
|
|
79
|
-
return p.then(
|
|
70
|
+
return p.then(() => fn(domain));
|
|
80
71
|
}
|
|
72
|
+
run.rollback = rollback.bind(null, domain);
|
|
73
|
+
run.commit = commit.bind(null, domain);
|
|
81
74
|
return run;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
c.bindTransaction = function() {
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
var domain = process.domain;
|
|
87
|
-
let p = domain.run(() => true);
|
|
88
75
|
|
|
89
|
-
function
|
|
90
|
-
return
|
|
76
|
+
function begin() {
|
|
77
|
+
return _begin(domain, options);
|
|
91
78
|
}
|
|
92
|
-
return run;
|
|
93
79
|
};
|
|
94
80
|
|
|
95
81
|
c.query = function(query) {
|
|
96
82
|
let domain = createDomain();
|
|
97
83
|
let transaction = newTransaction(domain, pool);
|
|
98
84
|
let p = domain.run(() => new Promise(transaction)
|
|
99
|
-
.then(() => setSessionSingleton('changes', []))
|
|
100
|
-
.then(() => doQuery(query).then(onResult, onError)));
|
|
85
|
+
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
86
|
+
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
101
87
|
return p;
|
|
102
88
|
|
|
103
89
|
function onResult(result) {
|
|
104
|
-
releaseDbClient();
|
|
90
|
+
releaseDbClient(domain);
|
|
105
91
|
return result;
|
|
106
92
|
}
|
|
107
93
|
|
|
108
94
|
function onError(e) {
|
|
109
|
-
releaseDbClient();
|
|
95
|
+
releaseDbClient(domain);
|
|
110
96
|
throw e;
|
|
111
97
|
}
|
|
112
98
|
};
|
|
113
99
|
|
|
114
|
-
|
|
115
100
|
c.rollback = rollback;
|
|
116
101
|
c.commit = commit;
|
|
117
102
|
|
|
@@ -2,16 +2,16 @@ var newParameterized = require('../table/query/newParameterized');
|
|
|
2
2
|
var insertSql = require('./insertSql');
|
|
3
3
|
var util = require('util');
|
|
4
4
|
|
|
5
|
-
function newInsertCommandCore(table, row, options = {}) {
|
|
5
|
+
function newInsertCommandCore(context,table, row, options = {}) {
|
|
6
6
|
var parameters = [];
|
|
7
|
-
var values = [insertSql(table, row, options)];
|
|
7
|
+
var values = [insertSql(context,table, row, options)];
|
|
8
8
|
|
|
9
9
|
var columns = table._columns;
|
|
10
10
|
for (var i = 0; i < columns.length; i++) {
|
|
11
11
|
var column = columns[i];
|
|
12
12
|
var alias = column.alias;
|
|
13
13
|
if (row['__' + column.alias] !== undefined) {
|
|
14
|
-
var encoded = column.encode(row[alias]);
|
|
14
|
+
var encoded = column.encode(context, row[alias]);
|
|
15
15
|
if (encoded.parameters.length > 0) {
|
|
16
16
|
values.push('?');
|
|
17
17
|
parameters.push(encoded.parameters[0]);
|
package/src/oracle/newPool.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const promisify = require('node:util').promisify;
|
|
2
|
+
const pools = require('../pools');
|
|
3
|
+
const end = require('./pool/end');
|
|
4
|
+
const newGenericPool = require('./pool/newGenericPool');
|
|
5
|
+
const newId = require('../newId');
|
|
6
6
|
|
|
7
7
|
function newPool(connectionString, poolOptions) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
let pool = newGenericPool(connectionString, poolOptions);
|
|
9
|
+
let id = newId();
|
|
10
|
+
let boundEnd = end.bind(null, pool, id);
|
|
11
|
+
let c = {};
|
|
12
12
|
|
|
13
13
|
c.connect = pool.connect;
|
|
14
|
-
c.end =
|
|
14
|
+
c.end = promisify(boundEnd);
|
|
15
15
|
pools[id] = c;
|
|
16
16
|
return c;
|
|
17
17
|
}
|
|
@@ -8,6 +8,7 @@ const insertSql = require('./insertSql');
|
|
|
8
8
|
const insert = require('./insert');
|
|
9
9
|
const formatDateOut = require('./formatDateOut');
|
|
10
10
|
const formatDateIn = require('./formatDateIn');
|
|
11
|
+
const quote = require('./quote');
|
|
11
12
|
|
|
12
13
|
function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
13
14
|
var rdb = {poolFactory: pool};
|
|
@@ -35,7 +36,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
|
35
36
|
caller.visitSqlite();
|
|
36
37
|
};
|
|
37
38
|
rdb.aggregateCount = 0;
|
|
38
|
-
rdb.quote =
|
|
39
|
+
rdb.quote = quote;
|
|
39
40
|
|
|
40
41
|
if (readonly) {
|
|
41
42
|
rdb.dbClient = {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable no-prototype-builtins */
|
|
3
3
|
var EventEmitter = require('events').EventEmitter;
|
|
4
4
|
|
|
5
|
-
var defaults = require('
|
|
5
|
+
var defaults = require('../../poolDefaults');
|
|
6
6
|
var genericPool = require('../../generic-pool');
|
|
7
7
|
var oracle = require('oracledb');
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ function newGenericPool(connectionString, poolOptions) {
|
|
|
15
15
|
max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
|
|
16
16
|
idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
|
|
17
17
|
reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
|
|
18
|
-
log: poolOptions.log
|
|
18
|
+
log: poolOptions.log,
|
|
19
19
|
create: function(cb) {
|
|
20
20
|
var client;
|
|
21
21
|
oracle.getConnection(connectionString, onConnected);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = (name) => `"${name}"`;
|
package/src/oracle/wrapQuery.js
CHANGED
|
@@ -10,9 +10,6 @@ function wrapQuery(connection) {
|
|
|
10
10
|
var sql = replaceParamChar(query, params);
|
|
11
11
|
log.emitQuery({ sql, parameters: params });
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
13
|
runOriginalQuery.call(connection, sql, params, {
|
|
17
14
|
fetchTypeHandler: function(metaData) {
|
|
18
15
|
// Tells the database to return column names in lowercase
|
package/src/patchRow.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
let patchTable = require('./patchTable');
|
|
2
2
|
|
|
3
|
-
function patchRow(table, row, patches, options) {
|
|
3
|
+
function patchRow(context, table, row, patches, options) {
|
|
4
4
|
patches = JSON.parse(JSON.stringify(patches));
|
|
5
5
|
let pkName = table._primaryColumns[0].alias;
|
|
6
6
|
let id = row[pkName];
|
|
7
7
|
for (let i = 0; i < patches.length; i++) {
|
|
8
8
|
patches[i].path = '/' + id + patches[i].path;
|
|
9
9
|
}
|
|
10
|
-
return patchTable(table, patches, options);
|
|
10
|
+
return patchTable(context, table, patches, options);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
module.exports = patchRow;
|
package/src/patchTable.js
CHANGED
|
@@ -12,7 +12,7 @@ async function patchTable() {
|
|
|
12
12
|
return patchTableCore.apply(null, arguments);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
async function patchTableCore(table, patches, { strategy = undefined, deduceStrategy = false, ...options } = {}, dryrun) {
|
|
15
|
+
async function patchTableCore(context, table, patches, { strategy = undefined, deduceStrategy = false, ...options } = {}, dryrun) {
|
|
16
16
|
options = cleanOptions(options);
|
|
17
17
|
strategy = JSON.parse(JSON.stringify(strategy || {}));
|
|
18
18
|
let changed = new Set();
|
|
@@ -41,7 +41,8 @@ async function patchTableCore(table, patches, { strategy = undefined, deduceStra
|
|
|
41
41
|
|
|
42
42
|
async function toDtos(set) {
|
|
43
43
|
set = [...set];
|
|
44
|
-
|
|
44
|
+
const result = await table.getManyDto(context, set, strategy);
|
|
45
|
+
return result;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
function toKey(property) {
|
|
@@ -56,7 +57,7 @@ async function patchTableCore(table, patches, { strategy = undefined, deduceStra
|
|
|
56
57
|
path = path.slice(1);
|
|
57
58
|
if (!row && path.length > 0) {
|
|
58
59
|
const key = toKey(property);
|
|
59
|
-
row = await table.tryGetById.apply(null,
|
|
60
|
+
row = await table.tryGetById.apply(null, [context, ...key, strategy]);
|
|
60
61
|
if (!row)
|
|
61
62
|
throw new Error(`Row ${table._dbName} with id ${key} was not found.`);
|
|
62
63
|
}
|
|
@@ -98,7 +99,7 @@ async function patchTableCore(table, patches, { strategy = undefined, deduceStra
|
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
|
-
let row = table.insertWithConcurrency.apply(null, [options, value]);
|
|
102
|
+
let row = table.insertWithConcurrency.apply(null, [context, options, value]);
|
|
102
103
|
row = await row;
|
|
103
104
|
|
|
104
105
|
for (let i = 0; i < childInserts.length; i++) {
|
|
@@ -212,7 +213,7 @@ async function patchTableCore(table, patches, { strategy = undefined, deduceStra
|
|
|
212
213
|
async function remove({ path, op, oldValue, options }, table, row) {
|
|
213
214
|
let property = path[0];
|
|
214
215
|
path = path.slice(1);
|
|
215
|
-
row = row || await table.getById.apply(null, toKey(property));
|
|
216
|
+
row = row || await table.getById.apply(null, [context, ...toKey(property)]);
|
|
216
217
|
if (path.length === 0) {
|
|
217
218
|
await validateDeleteAllowed({ row, options, table });
|
|
218
219
|
if (await validateDeleteConflict({ row, oldValue, options, table }))
|
package/src/pg/deleteFromSql.js
CHANGED
package/src/pg/formatDateOut.js
CHANGED
package/src/pg/insert.js
CHANGED
|
@@ -3,11 +3,11 @@ let newInsertCommandCore = require('../table/commands/newInsertCommandCore');
|
|
|
3
3
|
let executeQueries = require('../table/executeQueries');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
function insertDefault(table, row, options) {
|
|
7
|
-
let insertCmd = newInsertCommand(newInsertCommandCore, table, row, options);
|
|
6
|
+
function insertDefault(context, table, row, options) {
|
|
7
|
+
let insertCmd = newInsertCommand(newInsertCommandCore.bind(null, context), table, row, options);
|
|
8
8
|
insertCmd.disallowCompress = true;
|
|
9
9
|
|
|
10
|
-
return executeQueries([insertCmd]).then((result) => result[result.length - 1]);
|
|
10
|
+
return executeQueries(context, [insertCmd]).then((result) => result[result.length - 1]);
|
|
11
11
|
|
|
12
12
|
}
|
|
13
13
|
|
package/src/pg/insertSql.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
let lastInsertedSql = require('./lastInsertedSql');
|
|
2
|
-
|
|
3
|
-
const getSessionSingleton = require('../table/getSessionSingleton');
|
|
2
|
+
const quote = require('./quote');
|
|
4
3
|
|
|
5
|
-
function insertSql(table, row, options) {
|
|
6
|
-
const quote = getSessionSingleton('quote');
|
|
4
|
+
function insertSql(_context, table, row, options) {
|
|
7
5
|
let columnNames = [];
|
|
8
6
|
let regularColumnNames = [];
|
|
9
7
|
let conflictColumnUpdateSql = '';
|
|
@@ -65,9 +63,6 @@ function insertSql(table, row, options) {
|
|
|
65
63
|
|
|
66
64
|
|
|
67
65
|
function outputInserted() {
|
|
68
|
-
let context = getSessionContext();
|
|
69
|
-
if (!context.lastInsertedIsSeparate && context.outputInsertedSql)
|
|
70
|
-
return context.outputInsertedSql(table) + ' ';
|
|
71
66
|
return '';
|
|
72
67
|
}
|
|
73
68
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const quote = require('./quote');
|
|
2
2
|
|
|
3
3
|
function lastInsertedSql(table) {
|
|
4
|
-
const quote = getSessionSingleton('quote');
|
|
5
4
|
let separator = '';
|
|
6
5
|
let result = 'RETURNING ';
|
|
7
6
|
for (let i = 0; i < table._columns.length; i++) {
|
package/src/pg/newDatabase.js
CHANGED
|
@@ -6,10 +6,6 @@ let rollback = require('../table/rollback');
|
|
|
6
6
|
let newPool = require('./newPool');
|
|
7
7
|
let lock = require('../lock');
|
|
8
8
|
let executeSchema = require('./schema');
|
|
9
|
-
let useHook = require('../useHook');
|
|
10
|
-
let promise = require('promise/domains');
|
|
11
|
-
let versionArray = process.version.replace('v', '').split('.');
|
|
12
|
-
let major = parseInt(versionArray[0]);
|
|
13
9
|
let express = require('../hostExpress');
|
|
14
10
|
let hostLocal = require('../hostLocal');
|
|
15
11
|
let doQuery = require('../query');
|
|
@@ -41,39 +37,30 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
41
37
|
|
|
42
38
|
if (fn)
|
|
43
39
|
return domain.run(runInTransaction);
|
|
44
|
-
else if ((major >= 12) && useHook()) {
|
|
45
|
-
domain.exitContext = true;
|
|
46
|
-
return domain.start().then(run);
|
|
47
|
-
}
|
|
48
40
|
else
|
|
49
41
|
return domain.run(run);
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
53
43
|
async function runInTransaction() {
|
|
54
44
|
let result;
|
|
55
45
|
let transaction = newTransaction(domain, pool, options);
|
|
56
46
|
await new Promise(transaction)
|
|
57
47
|
.then(begin)
|
|
58
48
|
.then(negotiateSchema)
|
|
59
|
-
.then(fn)
|
|
49
|
+
.then(() => fn(domain))
|
|
60
50
|
.then((res) => result = res)
|
|
61
|
-
.then(
|
|
62
|
-
.then(null,
|
|
51
|
+
.then(() => commit(domain))
|
|
52
|
+
.then(null, (e) => rollback(domain,e));
|
|
63
53
|
return result;
|
|
64
54
|
}
|
|
65
55
|
|
|
66
56
|
function begin() {
|
|
67
|
-
return _begin(options
|
|
57
|
+
return _begin(domain, options);
|
|
68
58
|
}
|
|
69
59
|
|
|
70
60
|
function run() {
|
|
71
61
|
let p;
|
|
72
62
|
let transaction = newTransaction(domain, pool, options);
|
|
73
|
-
|
|
74
|
-
p = new Promise(transaction);
|
|
75
|
-
else
|
|
76
|
-
p = new promise(transaction);
|
|
63
|
+
p = new Promise(transaction);
|
|
77
64
|
|
|
78
65
|
return p.then(begin)
|
|
79
66
|
.then(negotiateSchema);
|
|
@@ -83,37 +70,34 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
83
70
|
let schema = options && options.schema;
|
|
84
71
|
if (!schema)
|
|
85
72
|
return previous;
|
|
86
|
-
return executeSchema(schema);
|
|
73
|
+
return executeSchema(domain, schema);
|
|
87
74
|
}
|
|
88
75
|
};
|
|
89
76
|
|
|
90
77
|
c.createTransaction = function(options) {
|
|
91
78
|
let domain = createDomain();
|
|
92
|
-
let transaction = newTransaction(domain, pool);
|
|
93
|
-
let p = domain.run(() => new Promise(transaction)
|
|
79
|
+
let transaction = newTransaction(domain, pool, options);
|
|
80
|
+
let p = domain.run(() => new Promise(transaction)
|
|
81
|
+
.then(begin).then(negotiateSchema));
|
|
94
82
|
|
|
95
83
|
function run(fn) {
|
|
96
84
|
return p.then(domain.run.bind(domain, fn));
|
|
97
85
|
}
|
|
98
86
|
|
|
87
|
+
function begin() {
|
|
88
|
+
return _begin(domain, options);
|
|
89
|
+
}
|
|
90
|
+
|
|
99
91
|
function negotiateSchema(previous) {
|
|
100
92
|
let schema = options && options.schema;
|
|
101
93
|
if (!schema)
|
|
102
94
|
return previous;
|
|
103
|
-
return executeSchema(schema);
|
|
95
|
+
return executeSchema(domain,schema);
|
|
104
96
|
}
|
|
105
97
|
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
run.rollback = rollback.bind(null, domain);
|
|
99
|
+
run.commit = commit.bind(null, domain);
|
|
108
100
|
|
|
109
|
-
c.bindTransaction = function() {
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
var domain = process.domain;
|
|
112
|
-
let p = domain.run(() => true);
|
|
113
|
-
|
|
114
|
-
function run(fn) {
|
|
115
|
-
return p.then(domain.run.bind(domain, fn));
|
|
116
|
-
}
|
|
117
101
|
return run;
|
|
118
102
|
};
|
|
119
103
|
|
|
@@ -121,22 +105,21 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
121
105
|
let domain = createDomain();
|
|
122
106
|
let transaction = newTransaction(domain, pool);
|
|
123
107
|
let p = domain.run(() => new Promise(transaction)
|
|
124
|
-
.then(() => setSessionSingleton('changes', []))
|
|
125
|
-
.then(() => doQuery(query).then(onResult, onError)));
|
|
108
|
+
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
109
|
+
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
126
110
|
return p;
|
|
127
111
|
|
|
128
112
|
function onResult(result) {
|
|
129
|
-
releaseDbClient();
|
|
113
|
+
releaseDbClient(domain);
|
|
130
114
|
return result;
|
|
131
115
|
}
|
|
132
116
|
|
|
133
117
|
function onError(e) {
|
|
134
|
-
releaseDbClient();
|
|
118
|
+
releaseDbClient(domain);
|
|
135
119
|
throw e;
|
|
136
120
|
}
|
|
137
121
|
};
|
|
138
122
|
|
|
139
|
-
|
|
140
123
|
c.rollback = rollback;
|
|
141
124
|
c.commit = commit;
|
|
142
125
|
c.lock = lock;
|
package/src/pg/newPool.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const promisify = require('node:util').promisify;
|
|
2
|
+
const pools = require('../pools');
|
|
3
|
+
const end = require('./pool/end');
|
|
4
|
+
const newPgPool = require('./pool/newPgPool');
|
|
5
|
+
const newId = require('../newId');
|
|
6
6
|
|
|
7
7
|
function newPool(connectionString, poolOptions) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
let pool = newPgPool(connectionString, poolOptions);
|
|
9
|
+
let id = newId();
|
|
10
|
+
let boundEnd = end.bind(null, pool, id);
|
|
11
|
+
let c = {};
|
|
12
12
|
|
|
13
13
|
c.connect = pool.connect;
|
|
14
|
-
c.end =
|
|
14
|
+
c.end = promisify(boundEnd);
|
|
15
15
|
pools[id] = c;
|
|
16
16
|
return c;
|
|
17
17
|
}
|
package/src/pg/newTransaction.js
CHANGED
|
@@ -8,6 +8,7 @@ var formatDateOut = require('./formatDateOut');
|
|
|
8
8
|
var encodeJSON = require('./encodeJSON');
|
|
9
9
|
var insertSql = require('./insertSql');
|
|
10
10
|
var insert = require('./insert');
|
|
11
|
+
var quote = require('./quote');
|
|
11
12
|
|
|
12
13
|
function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
13
14
|
var rdb = { poolFactory: pool };
|
|
@@ -32,7 +33,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
|
32
33
|
caller.visitPg();
|
|
33
34
|
};
|
|
34
35
|
rdb.aggregateCount = 0;
|
|
35
|
-
rdb.quote =
|
|
36
|
+
rdb.quote = quote;
|
|
36
37
|
|
|
37
38
|
if (readonly) {
|
|
38
39
|
rdb.dbClient = {
|
package/src/pg/pool/newPgPool.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
/* eslint-disable no-prototype-builtins */
|
|
2
2
|
//slightly modified code from github.com/brianc/node-postgres
|
|
3
|
+
var log = require('../../table/log');
|
|
3
4
|
var EventEmitter = require('events').EventEmitter;
|
|
4
5
|
|
|
5
|
-
var defaults = require('
|
|
6
|
+
var defaults = require('../../poolDefaults');
|
|
6
7
|
var genericPool = require('../../generic-pool');
|
|
7
8
|
var _pg = require('pg');
|
|
9
|
+
var parseSearchPathParam = require('./parseSearchPathParam');
|
|
8
10
|
|
|
9
11
|
function newPgPool(connectionString, poolOptions) {
|
|
10
12
|
poolOptions = poolOptions || {};
|
|
11
13
|
let pg = poolOptions.native ? _pg.native : _pg;
|
|
14
|
+
|
|
15
|
+
// @ts-ignore
|
|
12
16
|
var pool = genericPool.Pool({
|
|
13
17
|
max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
|
|
14
18
|
idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
|
|
15
19
|
reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
|
|
16
|
-
log: poolOptions.log
|
|
20
|
+
log: poolOptions.log,
|
|
17
21
|
create: function(cb) {
|
|
18
22
|
var client = new pg.Client(connectionString);
|
|
19
23
|
client.connect(function(err) {
|
|
@@ -41,7 +45,8 @@ function newPgPool(connectionString, poolOptions) {
|
|
|
41
45
|
}
|
|
42
46
|
});
|
|
43
47
|
client.poolCount = 0;
|
|
44
|
-
|
|
48
|
+
negotiateSearchPath(client, connectionString, (err) => cb(err, client));
|
|
49
|
+
|
|
45
50
|
});
|
|
46
51
|
},
|
|
47
52
|
destroy: function(client) {
|
|
@@ -65,7 +70,8 @@ function newPgPool(connectionString, poolOptions) {
|
|
|
65
70
|
cb = domain.bind(cb);
|
|
66
71
|
}
|
|
67
72
|
if (err) return cb(err, null, function() {
|
|
68
|
-
/*NOOP*/
|
|
73
|
+
/*NOOP*/
|
|
74
|
+
});
|
|
69
75
|
client.poolCount++;
|
|
70
76
|
cb(null, client, function(err) {
|
|
71
77
|
if (err) {
|
|
@@ -79,4 +85,17 @@ function newPgPool(connectionString, poolOptions) {
|
|
|
79
85
|
return pool;
|
|
80
86
|
}
|
|
81
87
|
|
|
88
|
+
function negotiateSearchPath(client, connectionString, cb) {
|
|
89
|
+
const searchPath = parseSearchPathParam(connectionString);
|
|
90
|
+
if (searchPath) {
|
|
91
|
+
const sql = `set search_path to ${searchPath}`;
|
|
92
|
+
log.emitQuery({sql, parameters: []});
|
|
93
|
+
return client.query(sql, cb);
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
cb();
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
82
101
|
module.exports = newPgPool;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function parseSearchPathParam(connectionString = '') {
|
|
2
|
+
const [, queryString] = connectionString.split('?');
|
|
3
|
+
if (!queryString)
|
|
4
|
+
return;
|
|
5
|
+
const params = new URLSearchParams(queryString);
|
|
6
|
+
const searchPath = params.get('search_path');
|
|
7
|
+
return searchPath;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = parseSearchPathParam;
|
package/src/pg/quote.js
ADDED
package/src/pg/schema.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var query = require('../query');
|
|
2
2
|
|
|
3
|
-
function executeSchema(schema) {
|
|
3
|
+
function executeSchema(context, schema) {
|
|
4
4
|
if (!schema)
|
|
5
5
|
throw new Error('Missing schema');
|
|
6
6
|
if (!Array.isArray(schema))
|
|
7
7
|
schema = [schema];
|
|
8
|
-
return query('SET LOCAL search_path TO ' + schema.join(','));
|
|
8
|
+
return query(context, 'SET LOCAL search_path TO ' + schema.join(','));
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
module.exports = executeSchema;
|
package/src/query.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var executeQueries = require('./table/executeQueries');
|
|
2
2
|
var wrapQuery = require('./query/wrapQuery');
|
|
3
3
|
|
|
4
|
-
function doQuery(query) {
|
|
4
|
+
function doQuery(context, query) {
|
|
5
5
|
var wrappedQuery = wrapQuery(query);
|
|
6
|
-
return executeQueries([wrappedQuery]).then(unwrapResult);
|
|
6
|
+
return executeQueries(context, [wrappedQuery]).then(unwrapResult);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
function unwrapResult(results) {
|
package/src/sap/deleteFromSql.js
CHANGED
package/src/sap/formatDateOut.js
CHANGED