orange-orm 4.1.1 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/changelog.md +4 -0
- package/package.json +1 -1
- package/src/getManyDto.js +17 -13
- package/src/hostLocal.js +7 -4
- package/src/mssql/newDatabase.js +8 -4
- package/src/mySql/newDatabase.js +6 -2
- package/src/oracle/newDatabase.js +8 -4
- package/src/pg/newDatabase.js +8 -2
- package/src/sap/newDatabase.js +6 -2
- package/src/sqlite/newDatabase.js +6 -2
- package/src/table/begin.js +5 -1
- package/src/table/commit.js +3 -1
- package/src/tedious/newDatabase.js +9 -4
- package/src/tedious/outputInsertedSql.js +1 -1
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
## Changelog
|
|
2
|
+
__4.1.3__
|
|
3
|
+
Do not use transaction in readonly operations. [#109](https://github.com/alfateam/orange-orm/issues/109)
|
|
4
|
+
__4.1.2__
|
|
5
|
+
Bugfix with composite primary key with hasMany relation. [#106](https://github.com/alfateam/orange-orm/issues/106)
|
|
2
6
|
__4.1.1__
|
|
3
7
|
Some fixes regarding NotNull mappings. [#104](https://github.com/alfateam/orange-orm/issues/91)
|
|
4
8
|
__4.1.0__
|
package/package.json
CHANGED
package/src/getManyDto.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
const emptyFilter = require('./emptyFilter');
|
|
1
2
|
const newQuery = require('./getManyDto/newQuery');
|
|
2
3
|
const negotiateRawSqlFilter = require('./table/column/negotiateRawSqlFilter');
|
|
3
4
|
const strategyToSpan = require('./table/strategyToSpan');
|
|
4
5
|
const executeQueries = require('./table/executeQueries');
|
|
5
|
-
const newPrimaryKeyFilter = require('./table/newPrimaryKeyFilter');
|
|
6
|
-
const newForeignKeyFilter = require('./table/relation/newForeignKeyFilter');
|
|
7
6
|
|
|
8
7
|
async function getManyDto(table, filter, strategy, spanFromParent) {
|
|
9
8
|
filter = negotiateRawSqlFilter(filter, table);
|
|
@@ -151,7 +150,7 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
151
150
|
function createGetIds() {
|
|
152
151
|
const primaryColumns = table._primaryColumns;
|
|
153
152
|
const length = primaryColumns.length;
|
|
154
|
-
if (length
|
|
153
|
+
if (length === 1) {
|
|
155
154
|
const alias = table._primaryColumns[0].alias;
|
|
156
155
|
return (row) => row[alias];
|
|
157
156
|
}
|
|
@@ -186,7 +185,7 @@ async function decodeRelations(strategy, span, rawRows, resultRows, keys) {
|
|
|
186
185
|
const name = leg.name;
|
|
187
186
|
const table = span.table;
|
|
188
187
|
const relation = table._relations[name];
|
|
189
|
-
const filter = createOneFilter(relation, span._ids
|
|
188
|
+
const filter = createOneFilter(relation, span._ids);
|
|
190
189
|
const rowsMap = span._rowsMap;
|
|
191
190
|
const p = getManyDto(relation.childTable, filter, strategy[name], leg.span).then(subRows => {
|
|
192
191
|
for (let i = 0; i < subRows.length; i++) {
|
|
@@ -207,21 +206,26 @@ async function decodeRelations(strategy, span, rawRows, resultRows, keys) {
|
|
|
207
206
|
await Promise.all(promises);
|
|
208
207
|
}
|
|
209
208
|
|
|
210
|
-
function createOneFilter(relation, ids
|
|
211
|
-
|
|
209
|
+
function createOneFilter(relation, ids) {
|
|
210
|
+
const columns = relation.joinRelation.columns;
|
|
212
211
|
|
|
213
|
-
if (
|
|
214
|
-
return
|
|
212
|
+
if (columns.length === 1)
|
|
213
|
+
return columns[0].in(ids);
|
|
215
214
|
|
|
216
215
|
else
|
|
217
216
|
return createCompositeFilter();
|
|
218
217
|
|
|
219
218
|
function createCompositeFilter() {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
let filter = emptyFilter;
|
|
220
|
+
for(let id of ids) {
|
|
221
|
+
let nextFilter;
|
|
222
|
+
for (let i = 0; i < columns.length; i++) {
|
|
223
|
+
if (nextFilter)
|
|
224
|
+
nextFilter = nextFilter.and(columns[i].eq(id[i]));
|
|
225
|
+
else
|
|
226
|
+
nextFilter = columns[i].eq(id[i]);
|
|
227
|
+
}
|
|
228
|
+
filter = filter.or(nextFilter);
|
|
225
229
|
}
|
|
226
230
|
return filter;
|
|
227
231
|
}
|
package/src/hostLocal.js
CHANGED
|
@@ -3,7 +3,7 @@ let getMeta = require('./hostExpress/getMeta');
|
|
|
3
3
|
let setSessionSingleton = require('./table/setSessionSingleton');
|
|
4
4
|
let executeQuery = require('./query');
|
|
5
5
|
let hostExpress = require('./hostExpress');
|
|
6
|
-
|
|
6
|
+
const readonlyOps = ['getManyDto', 'getMany', 'aggregate', 'count'];
|
|
7
7
|
// { db, table, defaultConcurrency,
|
|
8
8
|
// concurrency,
|
|
9
9
|
// customFilters,
|
|
@@ -20,7 +20,7 @@ function hostLocal() {
|
|
|
20
20
|
return getMeta(table);
|
|
21
21
|
|
|
22
22
|
}
|
|
23
|
-
async function patch(body,_req, _res) {
|
|
23
|
+
async function patch(body, _req, _res) {
|
|
24
24
|
if (!table) {
|
|
25
25
|
const error = new Error('Table is not exposed');
|
|
26
26
|
// @ts-ignore
|
|
@@ -65,7 +65,10 @@ function hostLocal() {
|
|
|
65
65
|
else
|
|
66
66
|
db = dbPromise;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
if (readonlyOps.includes(body.path))
|
|
69
|
+
await db.transaction({ readonly: true }, fn);
|
|
70
|
+
else
|
|
71
|
+
await db.transaction(fn);
|
|
69
72
|
}
|
|
70
73
|
return result;
|
|
71
74
|
|
|
@@ -101,7 +104,7 @@ function hostLocal() {
|
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
function express(client, options) {
|
|
104
|
-
return hostExpress(client, options
|
|
107
|
+
return hostExpress(client, options);
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
return c;
|
package/src/mssql/newDatabase.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let createDomain = require('../createDomain');
|
|
2
2
|
let newTransaction = require('./newTransaction');
|
|
3
|
-
let
|
|
3
|
+
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');
|
|
@@ -19,11 +19,11 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
19
19
|
throw new Error('Connection string cannot be empty');
|
|
20
20
|
var pool;
|
|
21
21
|
if (!poolOptions)
|
|
22
|
-
pool = newPool.bind(null,connectionString, poolOptions);
|
|
22
|
+
pool = newPool.bind(null, connectionString, poolOptions);
|
|
23
23
|
else
|
|
24
24
|
pool = newPool(connectionString, poolOptions);
|
|
25
25
|
|
|
26
|
-
let c = {poolFactory: pool, hostLocal, express};
|
|
26
|
+
let c = { poolFactory: pool, hostLocal, express };
|
|
27
27
|
|
|
28
28
|
c.transaction = function(options, fn) {
|
|
29
29
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
|
@@ -53,6 +53,10 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
function begin() {
|
|
57
|
+
return _begin(options?.readonly);
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
function run() {
|
|
57
61
|
let p;
|
|
58
62
|
let transaction = newTransaction(domain, pool);
|
|
@@ -69,7 +73,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
69
73
|
c.createTransaction = function() {
|
|
70
74
|
let domain = createDomain();
|
|
71
75
|
let transaction = newTransaction(domain, pool);
|
|
72
|
-
let p = domain.run(() => new Promise(transaction).then(
|
|
76
|
+
let p = domain.run(() => new Promise(transaction).then(_begin));
|
|
73
77
|
|
|
74
78
|
function run(fn) {
|
|
75
79
|
return p.then(domain.run.bind(domain, fn));
|
package/src/mySql/newDatabase.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let createDomain = require('../createDomain');
|
|
2
2
|
let newTransaction = require('./newTransaction');
|
|
3
|
-
let
|
|
3
|
+
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');
|
|
@@ -52,6 +52,10 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
52
52
|
return result;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
function begin() {
|
|
56
|
+
return _begin(options?.readonly);
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
function run() {
|
|
56
60
|
let p;
|
|
57
61
|
let transaction = newTransaction(domain, pool);
|
|
@@ -68,7 +72,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
68
72
|
c.createTransaction = function() {
|
|
69
73
|
let domain = createDomain();
|
|
70
74
|
let transaction = newTransaction(domain, pool);
|
|
71
|
-
let p = domain.run(() => new Promise(transaction).then(
|
|
75
|
+
let p = domain.run(() => new Promise(transaction).then(_begin));
|
|
72
76
|
|
|
73
77
|
function run(fn) {
|
|
74
78
|
return p.then(domain.run.bind(domain, fn));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let createDomain = require('../createDomain');
|
|
2
2
|
let newTransaction = require('./newTransaction');
|
|
3
|
-
let
|
|
3
|
+
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');
|
|
@@ -19,11 +19,11 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
19
19
|
throw new Error('Connection string cannot be empty');
|
|
20
20
|
var pool;
|
|
21
21
|
if (!poolOptions)
|
|
22
|
-
pool = newPool.bind(null,connectionString, poolOptions);
|
|
22
|
+
pool = newPool.bind(null, connectionString, poolOptions);
|
|
23
23
|
else
|
|
24
24
|
pool = newPool(connectionString, poolOptions);
|
|
25
25
|
|
|
26
|
-
let c = {poolFactory: pool, hostLocal, express};
|
|
26
|
+
let c = { poolFactory: pool, hostLocal, express };
|
|
27
27
|
|
|
28
28
|
c.transaction = function(options, fn) {
|
|
29
29
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
|
@@ -41,6 +41,10 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
41
41
|
else
|
|
42
42
|
return domain.run(run);
|
|
43
43
|
|
|
44
|
+
function begin() {
|
|
45
|
+
return _begin(options?.readonly);
|
|
46
|
+
}
|
|
47
|
+
|
|
44
48
|
async function runInTransaction() {
|
|
45
49
|
let result;
|
|
46
50
|
let transaction = newTransaction(domain, pool);
|
|
@@ -69,7 +73,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
69
73
|
c.createTransaction = function() {
|
|
70
74
|
let domain = createDomain();
|
|
71
75
|
let transaction = newTransaction(domain, pool);
|
|
72
|
-
let p = domain.run(() => new Promise(transaction).then(
|
|
76
|
+
let p = domain.run(() => new Promise(transaction).then(_begin));
|
|
73
77
|
|
|
74
78
|
function run(fn) {
|
|
75
79
|
return p.then(domain.run.bind(domain, fn));
|
package/src/pg/newDatabase.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let createDomain = require('../createDomain');
|
|
2
2
|
let newTransaction = require('./newTransaction');
|
|
3
|
-
let
|
|
3
|
+
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');
|
|
@@ -48,6 +48,8 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
48
48
|
else
|
|
49
49
|
return domain.run(run);
|
|
50
50
|
|
|
51
|
+
|
|
52
|
+
|
|
51
53
|
async function runInTransaction() {
|
|
52
54
|
let result;
|
|
53
55
|
let transaction = newTransaction(domain, pool);
|
|
@@ -61,6 +63,10 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
61
63
|
return result;
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
function begin() {
|
|
67
|
+
return _begin(options?.readonly);
|
|
68
|
+
}
|
|
69
|
+
|
|
64
70
|
function run() {
|
|
65
71
|
let p;
|
|
66
72
|
let transaction = newTransaction(domain, pool);
|
|
@@ -84,7 +90,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
84
90
|
c.createTransaction = function(options) {
|
|
85
91
|
let domain = createDomain();
|
|
86
92
|
let transaction = newTransaction(domain, pool);
|
|
87
|
-
let p = domain.run(() => new Promise(transaction).then(
|
|
93
|
+
let p = domain.run(() => new Promise(transaction).then(_begin).then(negotiateSchema));
|
|
88
94
|
|
|
89
95
|
function run(fn) {
|
|
90
96
|
return p.then(domain.run.bind(domain, fn));
|
package/src/sap/newDatabase.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let createDomain = require('../createDomain');
|
|
2
2
|
let newTransaction = require('./newTransaction');
|
|
3
|
-
let
|
|
3
|
+
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');
|
|
@@ -41,6 +41,10 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
41
41
|
else
|
|
42
42
|
return domain.run(run);
|
|
43
43
|
|
|
44
|
+
function begin() {
|
|
45
|
+
return _begin(options?.readonly);
|
|
46
|
+
}
|
|
47
|
+
|
|
44
48
|
async function runInTransaction() {
|
|
45
49
|
let result;
|
|
46
50
|
let transaction = newTransaction(domain, pool);
|
|
@@ -69,7 +73,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
69
73
|
c.createTransaction = function() {
|
|
70
74
|
let domain = createDomain();
|
|
71
75
|
let transaction = newTransaction(domain, pool);
|
|
72
|
-
let p = domain.run(() => new Promise(transaction).then(
|
|
76
|
+
let p = domain.run(() => new Promise(transaction).then(_begin));
|
|
73
77
|
|
|
74
78
|
function run(fn) {
|
|
75
79
|
return p.then(domain.run.bind(domain, fn));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let createDomain = require('../createDomain');
|
|
2
2
|
let newTransaction = require('./newTransaction');
|
|
3
|
-
let
|
|
3
|
+
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');
|
|
@@ -41,6 +41,10 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
41
41
|
else
|
|
42
42
|
return domain.run(run);
|
|
43
43
|
|
|
44
|
+
function begin() {
|
|
45
|
+
return _begin(options?.readonly);
|
|
46
|
+
}
|
|
47
|
+
|
|
44
48
|
async function runInTransaction() {
|
|
45
49
|
let result;
|
|
46
50
|
let transaction = newTransaction(domain, pool);
|
|
@@ -69,7 +73,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
69
73
|
c.createTransaction = function() {
|
|
70
74
|
let domain = createDomain();
|
|
71
75
|
let transaction = newTransaction(domain, pool);
|
|
72
|
-
let p = domain.run(() => new Promise(transaction).then(
|
|
76
|
+
let p = domain.run(() => new Promise(transaction).then(_begin));
|
|
73
77
|
|
|
74
78
|
function run(fn) {
|
|
75
79
|
return p.then(domain.run.bind(domain, fn));
|
package/src/table/begin.js
CHANGED
|
@@ -2,8 +2,12 @@ let beginCommand = require('./commands/beginCommand');
|
|
|
2
2
|
let executeQuery = require('./executeQueries/executeQuery');
|
|
3
3
|
let setSessionSingleton = require('./setSessionSingleton');
|
|
4
4
|
|
|
5
|
-
function begin() {
|
|
5
|
+
function begin(readonly) {
|
|
6
6
|
setSessionSingleton('changes', []);
|
|
7
|
+
if (readonly) {
|
|
8
|
+
setSessionSingleton('readonly', true);
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
}
|
|
7
11
|
return executeQuery(beginCommand());
|
|
8
12
|
}
|
|
9
13
|
|
package/src/table/commit.js
CHANGED
|
@@ -3,6 +3,7 @@ let pushCommand = require('./commands/pushCommand');
|
|
|
3
3
|
let executeChanges = require('./executeQueries/executeChanges');
|
|
4
4
|
let releaseDbClient = require('./releaseDbClient');
|
|
5
5
|
let popChanges = require('./popChanges');
|
|
6
|
+
const getSessionSingleton = require('./getSessionSingleton');
|
|
6
7
|
|
|
7
8
|
function commit(result) {
|
|
8
9
|
return popAndPushChanges()
|
|
@@ -19,7 +20,8 @@ function commit(result) {
|
|
|
19
20
|
await executeChanges(changes);
|
|
20
21
|
changes = popChanges();
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
if (!getSessionSingleton('readonly'))
|
|
24
|
+
pushCommand(commitCommand);
|
|
23
25
|
return executeChanges(popChanges());
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let createDomain = require('../createDomain');
|
|
2
2
|
let newTransaction = require('./newTransaction');
|
|
3
|
-
let
|
|
3
|
+
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');
|
|
@@ -19,11 +19,11 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
19
19
|
throw new Error('Connection string cannot be empty');
|
|
20
20
|
var pool;
|
|
21
21
|
if (!poolOptions)
|
|
22
|
-
pool = newPool.bind(null,connectionString, poolOptions);
|
|
22
|
+
pool = newPool.bind(null, connectionString, poolOptions);
|
|
23
23
|
else
|
|
24
24
|
pool = newPool(connectionString, poolOptions);
|
|
25
25
|
|
|
26
|
-
let c = {poolFactory: pool, hostLocal, express};
|
|
26
|
+
let c = { poolFactory: pool, hostLocal, express };
|
|
27
27
|
|
|
28
28
|
c.transaction = function(options, fn) {
|
|
29
29
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
|
@@ -41,6 +41,10 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
41
41
|
else
|
|
42
42
|
return domain.run(run);
|
|
43
43
|
|
|
44
|
+
function begin() {
|
|
45
|
+
return _begin(options?.readonly);
|
|
46
|
+
}
|
|
47
|
+
|
|
44
48
|
async function runInTransaction() {
|
|
45
49
|
let result;
|
|
46
50
|
let transaction = newTransaction(domain, pool);
|
|
@@ -53,6 +57,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
53
57
|
return result;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
|
|
56
61
|
function run() {
|
|
57
62
|
let p;
|
|
58
63
|
let transaction = newTransaction(domain, pool);
|
|
@@ -69,7 +74,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
69
74
|
c.createTransaction = function() {
|
|
70
75
|
let domain = createDomain();
|
|
71
76
|
let transaction = newTransaction(domain, pool);
|
|
72
|
-
let p = domain.run(() => new Promise(transaction).then(
|
|
77
|
+
let p = domain.run(() => new Promise(transaction).then(_begin));
|
|
73
78
|
|
|
74
79
|
function run(fn) {
|
|
75
80
|
return p.then(domain.run.bind(domain, fn));
|
|
@@ -2,7 +2,7 @@ function outputInsertedSql(table) {
|
|
|
2
2
|
let separator = '';
|
|
3
3
|
let result = 'OUTPUT ';
|
|
4
4
|
for (let i = 0; i < table._columns.length; i++) {
|
|
5
|
-
result += separator + 'INSERTED.' + table._columns[i]._dbName;
|
|
5
|
+
result += separator + 'INSERTED.[' + table._columns[i]._dbName + ']';
|
|
6
6
|
separator = ',';
|
|
7
7
|
}
|
|
8
8
|
return result;
|