orange-orm 4.5.0-beta.0 → 4.5.0-beta.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/README.md +6 -1
- package/docs/changelog.md +4 -0
- package/package.json +10 -6
- package/src/applyPatch.js +5 -2
- package/src/client/index.js +3 -2
- package/src/client/index.mjs +13552 -6381
- package/src/client/rollup.config.js +24 -4
- package/src/client/stringify.js +2 -9
- package/src/createDomain.js +7 -28
- package/src/d1/newDatabase.js +23 -37
- package/src/d1/newPool.js +6 -6
- package/src/d1/newTransaction.js +1 -0
- package/src/d1/pool/newGenericPool.js +2 -14
- package/src/emitEvent.js +6 -4
- package/src/emptyFilter.js +12 -12
- package/src/format.js +9 -0
- package/src/generic-pool.js +274 -313
- package/src/getManyDto/newQuery.js +5 -5
- package/src/getManyDto/query/newSingleQuery.js +5 -5
- package/src/getManyDto.js +73 -41
- package/src/hostExpress/cycle.ts +211 -0
- package/src/hostExpress/executePath.js +361 -357
- package/src/hostExpress.js +2 -7
- package/src/hostLocal.js +9 -9
- package/src/index.js +13 -17
- package/src/indexBrowser.js +39 -0
- 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 -13
- package/src/mySql/deleteFromSql.js +5 -5
- 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 -15
- package/src/mySql/quote.js +1 -0
- package/src/newId.js +2 -1
- package/src/newImmutable.js +1 -2
- package/src/oracle/deleteFromSql.js +5 -5
- 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 +5 -5
- package/src/oracle/newPool.js +10 -10
- package/src/oracle/newTransaction.js +2 -1
- package/src/oracle/pool/newGenericPool.js +2 -14
- package/src/oracle/quote.js +1 -0
- package/src/oracle/wrapQuery.js +0 -3
- package/src/package.json +5 -0
- package/src/patchRow.js +2 -2
- package/src/patchTable.js +6 -5
- package/src/pg/deleteFromSql.js +5 -5
- 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 -16
- 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/promisify.js +24 -0
- package/src/query.js +2 -2
- package/src/sap/deleteFromSql.js +3 -3
- 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 +5 -5
- 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 +1 -13
- 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 +1 -72
- package/src/table/column/newBoolean.js +2 -53
- 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/column/utils.js +113 -0
- package/src/table/column.js +6 -2
- 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 -10
- package/src/table/commands/newGetLastInsertedCommand.js +4 -4
- package/src/table/commands/newGetLastInsertedCommandCore.js +5 -5
- package/src/table/commands/newInsertCommand.js +5 -3
- package/src/table/commands/newInsertCommandCore.js +12 -12
- 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 +2 -14
- 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 +3 -10
- 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/newCascadeDeleteStrategy.js +1 -7
- 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 +6 -12
- 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/newParameterized.js +8 -11
- package/src/table/query/newSingleQuery.js +7 -7
- package/src/table/query/singleQuery/columnSql/joinLegToColumnSql.js +2 -15
- package/src/table/query/singleQuery/columnSql/newJoinedColumnSql.js +2 -25
- package/src/table/query/singleQuery/columnSql/newShallowColumnSql.js +4 -4
- package/src/table/query/singleQuery/columnSql/sharedJoinUtils.js +37 -0
- package/src/table/query/singleQuery/joinSql/joinLegToJoinSql.js +2 -7
- 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 -8
- 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 +7 -7
- package/src/table/query/singleQuery/newWhereSql.js +3 -3
- package/src/table/quote.js +4 -4
- package/src/table/relatedTable/aggregate.js +2 -8
- package/src/table/relatedTable/all.js +6 -12
- package/src/table/relatedTable/any.js +4 -11
- 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 +4 -10
- 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 -9
- 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 +25 -17
- 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 +6 -13
- package/src/table/resultToRows/dbRowsToRows.js +2 -2
- package/src/table/resultToRows/decodeDbRow.js +2 -2
- package/src/table/resultToRows/delete/removeFromCache.js +4 -11
- package/src/table/resultToRows/delete.js +6 -6
- package/src/table/resultToRows/newDecodeDbRow.js +19 -25
- package/src/table/resultToRows/toDto/extractStrategy.js +1 -7
- 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 +3 -13
- 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 +56 -53
- package/src/tedious/deleteFromSql.js +5 -5
- 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 +4 -5
- package/src/tedious/getManyDto/query/newSubQueries/manyLegToQuery.js +4 -5
- package/src/tedious/getManyDto/query/newSubQueries/oneLegToQuery.js +13 -14
- package/src/tedious/getManyDto/query/newSubQueries.js +9 -26
- 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 -13
- package/src/tedious/quote.js +1 -0
- package/src/validateDeleteConflict.js +4 -2
- package/src/createDomain/negotiateForwardProperty.js +0 -23
- 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/table/createJSONReadStream.js +0 -7
- package/src/table/createJSONReadStreamDefault.js +0 -33
- package/src/table/createJSONReadStreamNative.js +0 -31
- package/src/table/createReadStream.js +0 -24
- package/src/table/createReadStreamCoreNative.js +0 -40
- package/src/table/createReadStreamDefault.js +0 -102
- package/src/table/createReadStreamNative.js +0 -17
- package/src/table/readStream/extractLimit.js +0 -7
- package/src/table/readStream/extractOrderBy.js +0 -59
- package/src/table/readStream/mySql/newQuery.js +0 -16
- package/src/table/readStream/mySql/query/newSingleQuery.js +0 -21
- package/src/table/readStream/mySql/query/newSubQueries/joinLegToQuery.js +0 -20
- package/src/table/readStream/mySql/query/newSubQueries/manyLegToQuery.js +0 -22
- package/src/table/readStream/mySql/query/newSubQueries/newQueryCore.js +0 -9
- package/src/table/readStream/mySql/query/newSubQueries/newSingleQueryCore.js +0 -18
- package/src/table/readStream/mySql/query/newSubQueries/oneLegToQuery.js +0 -22
- package/src/table/readStream/mySql/query/newSubQueries.js +0 -47
- package/src/table/readStream/mySql/query/singleQuery/newShallowColumnSql.js +0 -18
- package/src/table/readStream/newQuery.js +0 -32
- package/src/table/readStream/newQueryStream.js +0 -8
- package/src/table/readStream/pg/newQuery.js +0 -8
- package/src/table/readStream/pg/newQueryCore.js +0 -17
- package/src/table/readStream/pg/query/newSingleQuery.js +0 -19
- package/src/table/readStream/pg/query/newSubQueries/joinLegToQuery.js +0 -19
- package/src/table/readStream/pg/query/newSubQueries/manyLegToQuery.js +0 -22
- package/src/table/readStream/pg/query/newSubQueries/oneLegToQuery.js +0 -19
- package/src/table/readStream/pg/query/newSubQueries.js +0 -47
- package/src/table/readStream/pg/query/singleQuery/newShallowColumnSql.js +0 -20
- package/src/table/readStreamDefault/createBatchFilter.js +0 -39
- package/src/tedious/pool/defaults.js +0 -45
- package/src/useHook.js +0 -9
package/src/oracle/insert.js
CHANGED
|
@@ -4,17 +4,17 @@ const setSessionSingleton = require('../table/setSessionSingleton');
|
|
|
4
4
|
const newGetLastInsertedCommand = require('../table/commands/newGetLastInsertedCommand');
|
|
5
5
|
const executeQueries = require('../table/executeQueries');
|
|
6
6
|
|
|
7
|
-
function insert(table, row, options) {
|
|
7
|
+
function insert(context, table, row, options) {
|
|
8
8
|
|
|
9
9
|
return new Promise((res, rej) => {
|
|
10
|
-
const cmd = newInsertCommand(newInsertCommandCore, table, row, options);
|
|
10
|
+
const cmd = newInsertCommand(newInsertCommandCore.bind(null, context), table, row, options);
|
|
11
11
|
cmd.disallowCompress = true;
|
|
12
|
-
executeQueries([cmd]).then((result) => result[0]).then(onResult).then(res, rej);
|
|
12
|
+
executeQueries(context, [cmd]).then((result) => result[0]).then(onResult).then(res, rej);
|
|
13
13
|
|
|
14
14
|
function onResult([result]) {
|
|
15
|
-
setSessionSingleton('lastRowid', result.lastRowid);
|
|
16
|
-
const selectCmd = newGetLastInsertedCommand(table, row, cmd);
|
|
17
|
-
return executeQueries([selectCmd]).then((result) => res(result[0]));
|
|
15
|
+
setSessionSingleton(context, 'lastRowid', result.lastRowid);
|
|
16
|
+
const selectCmd = newGetLastInsertedCommand(context, table, row, cmd);
|
|
17
|
+
return executeQueries(context, [selectCmd]).then((result) => res(result[0]));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
});
|
package/src/oracle/insertSql.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
let outputInsertedSql = require('./outputInsertedSql');
|
|
2
1
|
let mergeSql = require('./mergeSql');
|
|
3
|
-
const
|
|
2
|
+
const quote = require('./quote');
|
|
4
3
|
|
|
5
|
-
function getSqlTemplate(_table, _row, options) {
|
|
4
|
+
function getSqlTemplate(_context, _table, _row, options) {
|
|
6
5
|
if (hasConcurrency(_table, options) && hasColumns())
|
|
7
|
-
return mergeSql.apply(null, arguments);
|
|
6
|
+
return mergeSql.apply(null, [...arguments].slice(1));
|
|
8
7
|
else
|
|
9
|
-
return insertSql.apply(null, arguments);
|
|
8
|
+
return insertSql.apply(null, [...arguments].slice(1));
|
|
10
9
|
|
|
11
10
|
function hasColumns() {
|
|
12
11
|
for(let p in _row) {
|
|
@@ -27,7 +26,6 @@ function hasConcurrency(table,options) {
|
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
function insertSql(table, row) {
|
|
30
|
-
const quote = getSessionSingleton('quote');
|
|
31
29
|
let columnNames = [];
|
|
32
30
|
let regularColumnNames = [];
|
|
33
31
|
let values = [];
|
|
@@ -35,9 +33,9 @@ function insertSql(table, row) {
|
|
|
35
33
|
addDiscriminators();
|
|
36
34
|
addColumns();
|
|
37
35
|
if (columnNames.length === 0)
|
|
38
|
-
sql +=
|
|
36
|
+
sql += ` (${quote(table._primaryColumns[0]._dbName)}) VALUES(DEFAULT)`;
|
|
39
37
|
else
|
|
40
|
-
sql = sql + '('+ columnNames.join(',') + ')'
|
|
38
|
+
sql = sql + '('+ columnNames.join(',') + ')' + ' VALUES (' + values.join(',') + ')';
|
|
41
39
|
return sql;
|
|
42
40
|
|
|
43
41
|
function addDiscriminators() {
|
|
@@ -65,12 +63,6 @@ function insertSql(table, row) {
|
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
function outputInserted() {
|
|
70
|
-
|
|
71
|
-
return ' ' + outputInsertedSql(table) + ' ';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
66
|
}
|
|
75
67
|
|
|
76
68
|
module.exports = getSqlTemplate;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
let getSessionSingleton = require('../table/getSessionSingleton');
|
|
2
2
|
|
|
3
|
-
function lastInsertedSql(table, keyValues) {
|
|
3
|
+
function lastInsertedSql(context,table, keyValues) {
|
|
4
4
|
return keyValues.map((value,i) => {
|
|
5
5
|
let column = table._primaryColumns[i];
|
|
6
6
|
if (value === undefined)
|
|
7
|
-
return `ROWID='${getSessionSingleton('lastRowid')}'`;
|
|
7
|
+
return `ROWID='${getSessionSingleton(context, 'lastRowid')}'`;
|
|
8
8
|
else
|
|
9
|
-
return column.eq(value);
|
|
9
|
+
return column.eq(context, value);
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
}
|
package/src/oracle/mergeSql.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
const getSessionSingleton = require('../table/getSessionSingleton');
|
|
1
|
+
const quote = require('./quote');
|
|
3
2
|
|
|
4
3
|
function insertSql(table, row, options) {
|
|
5
|
-
const quote = getSessionSingleton('quote');
|
|
6
4
|
let columnNames = [];
|
|
7
5
|
let regularColumnNames = [];
|
|
8
6
|
let conflictColumnUpdateSql = '';
|
|
@@ -13,9 +11,9 @@ function insertSql(table, row, options) {
|
|
|
13
11
|
const matched = whenMatched();
|
|
14
12
|
let sql;
|
|
15
13
|
if (matched)
|
|
16
|
-
sql = `MERGE INTO ${quote(table._dbName)} target USING (SELECT ${values.join(',')} FROM DUAL) source ON (${join()}) WHEN MATCHED THEN ${matched} WHEN NOT MATCHED THEN ${whenNotMatched()}
|
|
14
|
+
sql = `MERGE INTO ${quote(table._dbName)} target USING (SELECT ${values.join(',')} FROM DUAL) source ON (${join()}) WHEN MATCHED THEN ${matched} WHEN NOT MATCHED THEN ${whenNotMatched()}`;
|
|
17
15
|
else
|
|
18
|
-
sql = `MERGE INTO ${quote(table._dbName)} target USING (SELECT ${values.join(',')} FROM DUAL) source ON (${join()}) WHEN NOT MATCHED THEN ${whenNotMatched()}
|
|
16
|
+
sql = `MERGE INTO ${quote(table._dbName)} target USING (SELECT ${values.join(',')} FROM DUAL) source ON (${join()}) WHEN NOT MATCHED THEN ${whenNotMatched()}`;
|
|
19
17
|
return sql;
|
|
20
18
|
|
|
21
19
|
function join() {
|
|
@@ -72,7 +70,6 @@ function insertSql(table, row, options) {
|
|
|
72
70
|
if (concurrency === 'overwrite')
|
|
73
71
|
conflictColumnUpdates.push(`target.${columnName}=source.${columnName}`);
|
|
74
72
|
else if (concurrency === 'optimistic')
|
|
75
|
-
// conflictColumnUpdates.push(`target.${column._dbName} = CASE WHEN target.${column._dbName} <> source.${column._dbName} THEN RAISE_APPLICATION_ERROR(-20001, 'Conflict when updating ${column._dbName}') ELSE target.${column._dbName} END`);
|
|
76
73
|
conflictColumnUpdates.push(`target.${columnName} = CASE WHEN target.${columnName} <> source.${columnName} THEN 1/0 ELSE target.${columnName} END`);
|
|
77
74
|
|
|
78
75
|
}
|
|
@@ -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
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
var newParameterized = require('../table/query/newParameterized');
|
|
2
2
|
var insertSql = require('./insertSql');
|
|
3
|
-
|
|
3
|
+
const formatString = require('../format');
|
|
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]);
|
|
@@ -20,7 +20,7 @@ function newInsertCommandCore(table, row, options = {}) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
var sql =
|
|
23
|
+
var sql = formatString.apply(null, values);
|
|
24
24
|
return newParameterized(sql, parameters);
|
|
25
25
|
}
|
|
26
26
|
|
package/src/oracle/newPool.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const promisify = require('../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 = {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
/* eslint-disable no-prototype-builtins */
|
|
3
|
-
var EventEmitter = require('events').EventEmitter;
|
|
4
3
|
|
|
5
|
-
var defaults = require('
|
|
4
|
+
var defaults = require('../../poolDefaults');
|
|
6
5
|
var genericPool = require('../../generic-pool');
|
|
7
6
|
var oracle = require('oracledb');
|
|
8
7
|
|
|
@@ -15,7 +14,7 @@ function newGenericPool(connectionString, poolOptions) {
|
|
|
15
14
|
max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
|
|
16
15
|
idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
|
|
17
16
|
reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
|
|
18
|
-
log: poolOptions.log
|
|
17
|
+
log: poolOptions.log,
|
|
19
18
|
create: function(cb) {
|
|
20
19
|
var client;
|
|
21
20
|
oracle.getConnection(connectionString, onConnected);
|
|
@@ -33,20 +32,9 @@ function newGenericPool(connectionString, poolOptions) {
|
|
|
33
32
|
client.close();
|
|
34
33
|
}
|
|
35
34
|
});
|
|
36
|
-
//mixin EventEmitter to pool
|
|
37
|
-
EventEmitter.call(pool);
|
|
38
|
-
for (var key in EventEmitter.prototype) {
|
|
39
|
-
if (EventEmitter.prototype.hasOwnProperty(key)) {
|
|
40
|
-
pool[key] = EventEmitter.prototype[key];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
35
|
//monkey-patch with connect method
|
|
44
36
|
pool.connect = function(cb) {
|
|
45
|
-
var domain = process.domain;
|
|
46
37
|
pool.acquire(function(err, client) {
|
|
47
|
-
if (domain) {
|
|
48
|
-
cb = domain.bind(cb);
|
|
49
|
-
}
|
|
50
38
|
if (err) return cb(err, null, function() {/*NOOP*/ });
|
|
51
39
|
client.poolCount++;
|
|
52
40
|
cb(null, client, function(err) {
|
|
@@ -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/package.json
ADDED
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
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const quote = require('
|
|
1
|
+
const format = 'delete from %s %s%s';
|
|
2
|
+
const formatString = require('../format');
|
|
3
|
+
const quote = require('./quote');
|
|
4
4
|
|
|
5
5
|
function deleteFromSql(table, alias, whereSql) {
|
|
6
|
-
|
|
6
|
+
const name = quote(table._dbName);
|
|
7
7
|
alias = quote(alias);
|
|
8
|
-
return
|
|
8
|
+
return formatString(format, name, alias, whereSql);
|
|
9
9
|
}
|
|
10
10
|
module.exports = deleteFromSql;
|
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;
|