orange-orm 4.9.0 → 4.10.0-beta.0
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 +120 -0
- package/deno.lock +76 -0
- package/dist/index.browser.mjs +192 -56
- package/dist/index.mjs +292 -179
- package/docs/changelog.md +2 -0
- package/other.db +0 -0
- package/package.json +1 -1
- package/src/bunPg/newDatabase.js +3 -14
- package/src/bunPg/newTransaction.js +1 -0
- package/src/bunSqlite/newDatabase.js +22 -13
- package/src/bunSqlite/newTransaction.js +1 -0
- package/src/client/index.js +8 -1
- package/src/client/netAdapter.js +13 -2
- package/src/d1/newDatabase.js +3 -13
- package/src/d1/newTransaction.js +1 -0
- package/src/getTSDefinition.js +14 -1
- package/src/hostExpress.js +8 -3
- package/src/hostLocal.js +66 -6
- package/src/map2.d.ts +18 -1
- package/src/mssql/newDatabase.js +3 -13
- package/src/mssql/newTransaction.js +1 -0
- package/src/mySql/newDatabase.js +3 -13
- package/src/mySql/newTransaction.js +1 -0
- package/src/nodeSqlite/newDatabase.js +29 -18
- package/src/nodeSqlite/newTransaction.js +1 -0
- package/src/oracle/newDatabase.js +3 -13
- package/src/oracle/newTransaction.js +1 -0
- package/src/pg/newDatabase.js +4 -16
- package/src/pg/newTransaction.js +1 -0
- package/src/pglite/newDatabase.js +3 -14
- package/src/pglite/newTransaction.js +1 -0
- package/src/sap/newDatabase.js +3 -13
- package/src/sap/newTransaction.js +1 -0
- package/src/sqlite3/newDatabase.js +22 -13
- package/src/sqlite3/newTransaction.js +1 -0
- package/src/sqliteFunction.js +20 -0
- package/src/table/begin.js +0 -1
- package/src/table/commit.js +21 -1
- package/src/table/query/singleQuery/joinSql/newShallowJoinSqlCore.js +6 -4
- package/src/table/rollback.js +22 -2
- package/src/tedious/newDatabase.js +3 -13
- package/src/tedious/newTransaction.js +1 -0
|
@@ -7,8 +7,8 @@ let newPool = require('./newPool');
|
|
|
7
7
|
let express = require('../hostExpress');
|
|
8
8
|
let hostLocal = require('../hostLocal');
|
|
9
9
|
let doQuery = require('../query');
|
|
10
|
+
let doSqliteFunction = require('../sqliteFunction');
|
|
10
11
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
11
|
-
let setSessionSingleton = require('../table/setSessionSingleton');
|
|
12
12
|
|
|
13
13
|
function newDatabase(connectionString, poolOptions) {
|
|
14
14
|
if (!connectionString)
|
|
@@ -24,11 +24,9 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
24
24
|
options = undefined;
|
|
25
25
|
}
|
|
26
26
|
let domain = createDomain();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
else
|
|
31
|
-
return domain.run(run);
|
|
27
|
+
if (!fn)
|
|
28
|
+
throw new Error('transaction requires a function');
|
|
29
|
+
return domain.run(runInTransaction);
|
|
32
30
|
|
|
33
31
|
function begin() {
|
|
34
32
|
return _begin(domain, options);
|
|
@@ -42,30 +40,27 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
42
40
|
.then(() => fn(domain))
|
|
43
41
|
.then((res) => result = res)
|
|
44
42
|
.then(() => commit(domain))
|
|
45
|
-
.then(null, (e) => rollback(domain, e));
|
|
43
|
+
.then(null, (e) => Promise.resolve(rollback(domain, e)));
|
|
46
44
|
return result;
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
function run() {
|
|
50
|
-
let p;
|
|
51
|
-
let transaction = newTransaction(domain, pool, options);
|
|
52
|
-
p = new Promise(transaction);
|
|
53
|
-
|
|
54
|
-
return p.then(begin);
|
|
55
|
-
}
|
|
56
47
|
|
|
57
48
|
};
|
|
58
49
|
|
|
59
50
|
c.createTransaction = function(options) {
|
|
51
|
+
console.dir('create transaction');
|
|
60
52
|
let domain = createDomain();
|
|
61
53
|
let transaction = newTransaction(domain, pool);
|
|
62
54
|
let p = domain.run(() => new Promise(transaction).then(begin));
|
|
63
|
-
|
|
64
55
|
function run(fn) {
|
|
65
56
|
return p.then(() => fn(domain));
|
|
66
57
|
}
|
|
67
|
-
run.rollback =
|
|
68
|
-
|
|
58
|
+
run.rollback = function(error) {
|
|
59
|
+
return Promise.resolve(rollback(domain, error));
|
|
60
|
+
};
|
|
61
|
+
run.commit = function() {
|
|
62
|
+
return Promise.resolve(commit(domain));
|
|
63
|
+
};
|
|
69
64
|
return run;
|
|
70
65
|
|
|
71
66
|
function begin() {
|
|
@@ -77,7 +72,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
77
72
|
let domain = createDomain();
|
|
78
73
|
let transaction = newTransaction(domain, pool);
|
|
79
74
|
let p = domain.run(() => new Promise(transaction)
|
|
80
|
-
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
81
75
|
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
82
76
|
return p;
|
|
83
77
|
|
|
@@ -92,6 +86,23 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
92
86
|
}
|
|
93
87
|
};
|
|
94
88
|
|
|
89
|
+
c.sqliteFunction = function(...args) {
|
|
90
|
+
let domain = createDomain();
|
|
91
|
+
let transaction = newTransaction(domain, pool);
|
|
92
|
+
let p = domain.run(() => new Promise(transaction)
|
|
93
|
+
.then(() => doSqliteFunction(domain, ...args).then(onResult, onError)));
|
|
94
|
+
return p;
|
|
95
|
+
|
|
96
|
+
function onResult(result) {
|
|
97
|
+
releaseDbClient(domain);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function onError(e) {
|
|
102
|
+
releaseDbClient(domain);
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
95
106
|
|
|
96
107
|
c.rollback = rollback;
|
|
97
108
|
c.commit = commit;
|
|
@@ -8,7 +8,6 @@ let express = require('../hostExpress');
|
|
|
8
8
|
let hostLocal = require('../hostLocal');
|
|
9
9
|
let doQuery = require('../query');
|
|
10
10
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
11
|
-
let setSessionSingleton = require('../table/setSessionSingleton');
|
|
12
11
|
|
|
13
12
|
function newDatabase(connectionString, poolOptions) {
|
|
14
13
|
if (!connectionString)
|
|
@@ -25,10 +24,9 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
25
24
|
}
|
|
26
25
|
let domain = createDomain();
|
|
27
26
|
|
|
28
|
-
if (fn)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return domain.run(run);
|
|
27
|
+
if (!fn)
|
|
28
|
+
throw new Error('transaction requires a function');
|
|
29
|
+
return domain.run(runInTransaction);
|
|
32
30
|
|
|
33
31
|
|
|
34
32
|
function begin() {
|
|
@@ -48,13 +46,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
48
46
|
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
function run() {
|
|
52
|
-
let p;
|
|
53
|
-
let transaction = newTransaction(domain, pool, options);
|
|
54
|
-
p = new Promise(transaction);
|
|
55
|
-
|
|
56
|
-
return p.then(begin);
|
|
57
|
-
}
|
|
58
49
|
|
|
59
50
|
};
|
|
60
51
|
|
|
@@ -79,7 +70,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
79
70
|
let domain = createDomain();
|
|
80
71
|
let transaction = newTransaction(domain, pool);
|
|
81
72
|
let p = domain.run(() => new Promise(transaction)
|
|
82
|
-
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
83
73
|
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
84
74
|
return p;
|
|
85
75
|
|
package/src/pg/newDatabase.js
CHANGED
|
@@ -10,7 +10,6 @@ let express = require('../hostExpress');
|
|
|
10
10
|
let hostLocal = require('../hostLocal');
|
|
11
11
|
let doQuery = require('../query');
|
|
12
12
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
13
|
-
let setSessionSingleton = require('../table/setSessionSingleton');
|
|
14
13
|
|
|
15
14
|
function newDatabase(connectionString, poolOptions) {
|
|
16
15
|
if (!connectionString)
|
|
@@ -27,10 +26,9 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
27
26
|
}
|
|
28
27
|
let domain = createDomain();
|
|
29
28
|
|
|
30
|
-
if (fn)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return domain.run(run);
|
|
29
|
+
if (!fn)
|
|
30
|
+
throw new Error('transaction requires a function');
|
|
31
|
+
return domain.run(runInTransaction);
|
|
34
32
|
|
|
35
33
|
async function runInTransaction() {
|
|
36
34
|
let result;
|
|
@@ -49,15 +47,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
49
47
|
return _begin(domain, options);
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
function run() {
|
|
53
|
-
let p;
|
|
54
|
-
let transaction = newTransaction(domain, pool, options);
|
|
55
|
-
p = new Promise(transaction);
|
|
56
|
-
|
|
57
|
-
return p.then(begin)
|
|
58
|
-
.then(negotiateSchema);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
50
|
function negotiateSchema(previous) {
|
|
62
51
|
let schema = options && options.schema;
|
|
63
52
|
if (!schema)
|
|
@@ -97,7 +86,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
97
86
|
let domain = createDomain();
|
|
98
87
|
let transaction = newTransaction(domain, pool);
|
|
99
88
|
let p = domain.run(() => new Promise(transaction)
|
|
100
|
-
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
101
89
|
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
102
90
|
return p;
|
|
103
91
|
|
|
@@ -131,4 +119,4 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
131
119
|
return c;
|
|
132
120
|
}
|
|
133
121
|
|
|
134
|
-
module.exports = newDatabase;
|
|
122
|
+
module.exports = newDatabase;
|
package/src/pg/newTransaction.js
CHANGED
|
@@ -10,7 +10,6 @@ let express = require('../hostExpress');
|
|
|
10
10
|
let hostLocal = require('../hostLocal');
|
|
11
11
|
let doQuery = require('../query');
|
|
12
12
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
13
|
-
let setSessionSingleton = require('../table/setSessionSingleton');
|
|
14
13
|
|
|
15
14
|
function newDatabase(connectionString, poolOptions) {
|
|
16
15
|
poolOptions = poolOptions || { min: 1 };
|
|
@@ -25,10 +24,9 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
25
24
|
}
|
|
26
25
|
let domain = createDomain();
|
|
27
26
|
|
|
28
|
-
if (fn)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return domain.run(run);
|
|
27
|
+
if (!fn)
|
|
28
|
+
throw new Error('transaction requires a function');
|
|
29
|
+
return domain.run(runInTransaction);
|
|
32
30
|
|
|
33
31
|
async function runInTransaction() {
|
|
34
32
|
let result;
|
|
@@ -47,14 +45,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
47
45
|
return _begin(domain, options);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
function run() {
|
|
51
|
-
let p;
|
|
52
|
-
let transaction = newTransaction(domain, pool, options);
|
|
53
|
-
p = new Promise(transaction);
|
|
54
|
-
|
|
55
|
-
return p.then(begin)
|
|
56
|
-
.then(negotiateSchema);
|
|
57
|
-
}
|
|
58
48
|
|
|
59
49
|
function negotiateSchema(previous) {
|
|
60
50
|
let schema = options && options.schema;
|
|
@@ -95,7 +85,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
95
85
|
let domain = createDomain();
|
|
96
86
|
let transaction = newTransaction(domain, pool);
|
|
97
87
|
let p = domain.run(() => new Promise(transaction)
|
|
98
|
-
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
99
88
|
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
100
89
|
return p;
|
|
101
90
|
|
package/src/sap/newDatabase.js
CHANGED
|
@@ -8,7 +8,6 @@ let express = require('../hostExpress');
|
|
|
8
8
|
let hostLocal = require('../hostLocal');
|
|
9
9
|
let doQuery = require('../query');
|
|
10
10
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
11
|
-
let setSessionSingleton = require('../table/setSessionSingleton');
|
|
12
11
|
|
|
13
12
|
function newDatabase(connectionString, poolOptions) {
|
|
14
13
|
if (!connectionString)
|
|
@@ -25,10 +24,9 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
25
24
|
}
|
|
26
25
|
let domain = createDomain();
|
|
27
26
|
|
|
28
|
-
if (fn)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return domain.run(run);
|
|
27
|
+
if (!fn)
|
|
28
|
+
throw new Error('transaction requires a function');
|
|
29
|
+
return domain.run(runInTransaction);
|
|
32
30
|
|
|
33
31
|
|
|
34
32
|
function begin() {
|
|
@@ -48,13 +46,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
48
46
|
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
function run() {
|
|
52
|
-
let p;
|
|
53
|
-
let transaction = newTransaction(domain, pool, options);
|
|
54
|
-
p = new Promise(transaction);
|
|
55
|
-
|
|
56
|
-
return p.then(begin);
|
|
57
|
-
}
|
|
58
49
|
|
|
59
50
|
};
|
|
60
51
|
|
|
@@ -84,7 +75,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
84
75
|
let domain = createDomain();
|
|
85
76
|
let transaction = newTransaction(domain, pool);
|
|
86
77
|
let p = domain.run(() => new Promise(transaction)
|
|
87
|
-
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
88
78
|
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
89
79
|
return p;
|
|
90
80
|
|
|
@@ -7,8 +7,8 @@ let newPool = require('./newPool');
|
|
|
7
7
|
let express = require('../hostExpress');
|
|
8
8
|
let hostLocal = require('../hostLocal');
|
|
9
9
|
let doQuery = require('../query');
|
|
10
|
+
let doSqliteFunction = require('../sqliteFunction');
|
|
10
11
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
11
|
-
let setSessionSingleton = require('../table/setSessionSingleton');
|
|
12
12
|
|
|
13
13
|
function newDatabase(connectionString, poolOptions) {
|
|
14
14
|
if (!connectionString)
|
|
@@ -25,10 +25,9 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
25
25
|
}
|
|
26
26
|
let domain = createDomain();
|
|
27
27
|
|
|
28
|
-
if (fn)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return domain.run(run);
|
|
28
|
+
if (!fn)
|
|
29
|
+
throw new Error('transaction requires a function');
|
|
30
|
+
return domain.run(runInTransaction);
|
|
32
31
|
|
|
33
32
|
function begin() {
|
|
34
33
|
return _begin(domain, options);
|
|
@@ -46,13 +45,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
46
45
|
return result;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
function run() {
|
|
50
|
-
let p;
|
|
51
|
-
let transaction = newTransaction(domain, pool, options);
|
|
52
|
-
p = new Promise(transaction);
|
|
53
|
-
|
|
54
|
-
return p.then(begin);
|
|
55
|
-
}
|
|
56
48
|
|
|
57
49
|
};
|
|
58
50
|
|
|
@@ -77,7 +69,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
77
69
|
let domain = createDomain();
|
|
78
70
|
let transaction = newTransaction(domain, pool);
|
|
79
71
|
let p = domain.run(() => new Promise(transaction)
|
|
80
|
-
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
81
72
|
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
82
73
|
return p;
|
|
83
74
|
|
|
@@ -92,6 +83,24 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
92
83
|
}
|
|
93
84
|
};
|
|
94
85
|
|
|
86
|
+
c.sqliteFunction = function(...args) {
|
|
87
|
+
let domain = createDomain();
|
|
88
|
+
let transaction = newTransaction(domain, pool);
|
|
89
|
+
let p = domain.run(() => new Promise(transaction)
|
|
90
|
+
.then(() => doSqliteFunction(domain, ...args).then(onResult, onError)));
|
|
91
|
+
return p;
|
|
92
|
+
|
|
93
|
+
function onResult(result) {
|
|
94
|
+
releaseDbClient(domain);
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function onError(e) {
|
|
99
|
+
releaseDbClient(domain);
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
95
104
|
|
|
96
105
|
c.rollback = rollback;
|
|
97
106
|
c.commit = commit;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const executeChanges = require('./table/executeQueries/executeChanges');
|
|
2
|
+
const popChanges = require('./table/popChanges');
|
|
3
|
+
const getSessionSingleton = require('./table/getSessionSingleton');
|
|
4
|
+
|
|
5
|
+
function executeQueries(context, ...rest) {
|
|
6
|
+
var changes = popChanges(context);
|
|
7
|
+
|
|
8
|
+
return executeChanges(context, changes).then(onDoneChanges);
|
|
9
|
+
|
|
10
|
+
function onDoneChanges() {
|
|
11
|
+
var client = getSessionSingleton(context, 'dbClient');
|
|
12
|
+
if (client && typeof client.function === 'function')
|
|
13
|
+
return client.function.apply(client, rest);
|
|
14
|
+
if (client && typeof client.createFunction === 'function')
|
|
15
|
+
return client.createFunction.apply(client, rest);
|
|
16
|
+
throw new Error('SQLite client does not support user-defined functions');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = executeQueries;
|
package/src/table/begin.js
CHANGED
|
@@ -3,7 +3,6 @@ let executeQuery = require('./executeQueries/executeQuery');
|
|
|
3
3
|
let setSessionSingleton = require('./setSessionSingleton');
|
|
4
4
|
|
|
5
5
|
function begin(context, transactionLess) {
|
|
6
|
-
setSessionSingleton(context, 'changes', []);
|
|
7
6
|
if (transactionLess) {
|
|
8
7
|
setSessionSingleton(context, 'transactionLess', true);
|
|
9
8
|
return Promise.resolve();
|
package/src/table/commit.js
CHANGED
|
@@ -6,14 +6,34 @@ let popChanges = require('./popChanges');
|
|
|
6
6
|
const getSessionSingleton = require('./getSessionSingleton');
|
|
7
7
|
|
|
8
8
|
function _commit(context, result) {
|
|
9
|
+
let hookError;
|
|
9
10
|
return popAndPushChanges()
|
|
11
|
+
.then(callAfterCommit)
|
|
10
12
|
.then(releaseDbClient.bind(null, context))
|
|
11
|
-
.then(onReleased)
|
|
13
|
+
.then(onReleased)
|
|
14
|
+
.then(throwHookErrorIfAny);
|
|
12
15
|
|
|
13
16
|
function onReleased() {
|
|
14
17
|
return result;
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
function throwHookErrorIfAny(res) {
|
|
21
|
+
if (hookError)
|
|
22
|
+
throw hookError;
|
|
23
|
+
return res;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function callAfterCommit() {
|
|
27
|
+
const hook = getSessionSingleton(context, 'afterCommitHook');
|
|
28
|
+
if (!hook)
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
return Promise.resolve()
|
|
31
|
+
.then(() => hook())
|
|
32
|
+
.catch((e) => {
|
|
33
|
+
hookError = e;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
17
37
|
async function popAndPushChanges() {
|
|
18
38
|
let changes = popChanges(context);
|
|
19
39
|
while (changes.length > 0) {
|
|
@@ -4,8 +4,10 @@ const getSessionSingleton = require('../../../getSessionSingleton');
|
|
|
4
4
|
|
|
5
5
|
function _new(context, rightTable, leftColumns, rightColumns, leftAlias, rightAlias, filter) {
|
|
6
6
|
const quote = getSessionSingleton(context, 'quote');
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const leftAliasRaw = leftAlias;
|
|
8
|
+
const rightAliasRaw = rightAlias;
|
|
9
|
+
leftAlias = quote(leftAliasRaw);
|
|
10
|
+
rightAlias = quote(rightAliasRaw);
|
|
9
11
|
var sql = '';
|
|
10
12
|
var delimiter = '';
|
|
11
13
|
for (var i = 0; i < leftColumns.length; i++) {
|
|
@@ -19,11 +21,11 @@ function _new(context, rightTable, leftColumns, rightColumns, leftAlias, rightAl
|
|
|
19
21
|
sql += delimiter + leftAlias + '.' + quote(leftColumn._dbName) + '=' + rightAlias + '.' + quote(rightColumn._dbName);
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
sql += newDiscriminatorSql(context, rightTable,
|
|
24
|
+
sql += newDiscriminatorSql(context, rightTable, rightAliasRaw);
|
|
23
25
|
var result = newParameterized(sql);
|
|
24
26
|
if (filter)
|
|
25
27
|
result = result.append(delimiter).append(filter);
|
|
26
28
|
return result;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
module.exports = _new;
|
|
31
|
+
module.exports = _new;
|
package/src/table/rollback.js
CHANGED
|
@@ -8,10 +8,13 @@ const conflictId = '12345678-1234-1234-1234-123456789012';
|
|
|
8
8
|
const getSessionSingleton = require('./getSessionSingleton');
|
|
9
9
|
|
|
10
10
|
function _rollback(context, e) {
|
|
11
|
+
let hookError;
|
|
11
12
|
var chain = resultToPromise()
|
|
12
13
|
.then(() => popChanges(context))
|
|
13
14
|
.then(executeRollback)
|
|
14
|
-
.then(
|
|
15
|
+
.then(callAfterRollback)
|
|
16
|
+
.then(() => releaseDbClient(context))
|
|
17
|
+
.then(throwHookErrorIfAny);
|
|
15
18
|
|
|
16
19
|
|
|
17
20
|
function executeRollback() {
|
|
@@ -21,6 +24,23 @@ function _rollback(context, e) {
|
|
|
21
24
|
return executeQuery(context, rollbackCommand);
|
|
22
25
|
}
|
|
23
26
|
|
|
27
|
+
function callAfterRollback() {
|
|
28
|
+
const hook = getSessionSingleton(context, 'afterRollbackHook');
|
|
29
|
+
if (!hook)
|
|
30
|
+
return Promise.resolve();
|
|
31
|
+
return Promise.resolve()
|
|
32
|
+
.then(() => hook(e))
|
|
33
|
+
.catch((err) => {
|
|
34
|
+
hookError = err;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function throwHookErrorIfAny(res) {
|
|
39
|
+
if (hookError)
|
|
40
|
+
throw hookError;
|
|
41
|
+
return res;
|
|
42
|
+
}
|
|
43
|
+
|
|
24
44
|
if (e) {
|
|
25
45
|
if (e.message?.indexOf('ORA-01476: divisor is equal to zero') > -1)
|
|
26
46
|
return newThrow(context, new Error('Conflict when updating a column'), chain);
|
|
@@ -38,4 +58,4 @@ function rollback(context, e) {
|
|
|
38
58
|
return Promise.resolve().then(() => _rollback(context, e));
|
|
39
59
|
}
|
|
40
60
|
|
|
41
|
-
module.exports = rollback;
|
|
61
|
+
module.exports = rollback;
|
|
@@ -8,7 +8,6 @@ let express = require('../hostExpress');
|
|
|
8
8
|
let hostLocal = require('../hostLocal');
|
|
9
9
|
let doQuery = require('../query');
|
|
10
10
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
11
|
-
let setSessionSingleton = require('../table/setSessionSingleton');
|
|
12
11
|
|
|
13
12
|
function newDatabase(connectionString, poolOptions) {
|
|
14
13
|
if (!connectionString)
|
|
@@ -25,10 +24,9 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
25
24
|
}
|
|
26
25
|
let domain = createDomain();
|
|
27
26
|
|
|
28
|
-
if (fn)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return domain.run(run);
|
|
27
|
+
if (!fn)
|
|
28
|
+
throw new Error('transaction requires a function');
|
|
29
|
+
return domain.run(runInTransaction);
|
|
32
30
|
|
|
33
31
|
function begin() {
|
|
34
32
|
return _begin(domain, options);
|
|
@@ -47,13 +45,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
|
|
50
|
-
function run() {
|
|
51
|
-
let p;
|
|
52
|
-
let transaction = newTransaction(domain, pool, options);
|
|
53
|
-
p = new Promise(transaction);
|
|
54
|
-
|
|
55
|
-
return p.then(begin);
|
|
56
|
-
}
|
|
57
48
|
|
|
58
49
|
};
|
|
59
50
|
|
|
@@ -81,7 +72,6 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
81
72
|
let domain = createDomain();
|
|
82
73
|
let transaction = newTransaction(domain, pool);
|
|
83
74
|
let p = domain.run(() => new Promise(transaction)
|
|
84
|
-
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
85
75
|
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
86
76
|
return p;
|
|
87
77
|
|