orange-orm 5.3.6 → 5.4.0-beta
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 -6
- package/dist/index.browser.mjs +351 -117
- package/dist/index.mjs +401 -142
- package/docs/changelog.md +2 -0
- package/package.json +1 -1
- package/src/applyPatch.js +25 -20
- package/src/client/index.js +33 -16
- package/src/getManyDto/query/newSingleQuery.js +5 -1
- package/src/getTSDefinition.js +2 -0
- package/src/hostExpress/executePath.js +39 -2
- package/src/hostLocal.js +19 -1
- package/src/map2.d.ts +3 -1
- package/src/mySql/selectForUpdateSql.js +10 -3
- package/src/oracle/selectForUpdateSql.js +10 -5
- package/src/patchTable.js +66 -3
- package/src/pg/selectForUpdateSql.js +13 -3
- package/src/sap/selectForUpdateSql.js +5 -5
- package/src/sqlite/selectForUpdateSql.js +5 -5
- package/src/table/commands/newUpdateCommandCore.js +7 -2
- package/src/table/getMany.js +2 -2
- package/src/table/newPrimaryKeyFilter.js +2 -2
- package/src/table/query/newSingleQuery.js +7 -5
- package/src/table/query/singleQuery/joinSql/joinLegToShallowJoinSql.js +2 -2
- package/src/table/query/singleQuery/joinSql/newShallowJoinSql.js +5 -3
- package/src/table/query/singleQuery/joinSql/oneLegToShallowJoinSql.js +2 -2
- package/src/table/query/singleQuery/lockSql.js +74 -0
- package/src/table/tryGetFromDbById.js +9 -3
- package/src/tedious/getManyDto/query/newSingleQuery.js +4 -2
- package/src/tedious/selectForUpdateSql.js +17 -4
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const getSessionSingleton = require('../../getSessionSingleton');
|
|
2
|
+
|
|
3
|
+
function selectLockSql(context, span, alias, exclusive) {
|
|
4
|
+
const lock = collectSelectLock(span, alias, exclusive);
|
|
5
|
+
if (!hasLock(lock))
|
|
6
|
+
return '';
|
|
7
|
+
const encode = getSessionSingleton(context, 'selectForUpdateSql');
|
|
8
|
+
if (!encode)
|
|
9
|
+
return '';
|
|
10
|
+
return encode(context, lock);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function tableHintSql(context, span, exclusive) {
|
|
14
|
+
const lock = spanToLock(span, exclusive);
|
|
15
|
+
if (!hasLock(lock))
|
|
16
|
+
return '';
|
|
17
|
+
const encode = getSessionSingleton(context, 'selectForUpdateSql');
|
|
18
|
+
if (!encode || !encode.tableHint)
|
|
19
|
+
return '';
|
|
20
|
+
return encode.tableHint(context, lock);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function collectSelectLock(span, alias, exclusive) {
|
|
24
|
+
const lock = {
|
|
25
|
+
aliases: [],
|
|
26
|
+
forUpdate: Boolean(exclusive),
|
|
27
|
+
skipLocked: false
|
|
28
|
+
};
|
|
29
|
+
collect(span, alias, lock);
|
|
30
|
+
if (exclusive && lock.aliases.indexOf(alias) === -1)
|
|
31
|
+
lock.aliases.unshift(alias);
|
|
32
|
+
return lock;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function collect(span, alias, lock) {
|
|
36
|
+
if (!span)
|
|
37
|
+
return;
|
|
38
|
+
if (span.forUpdate) {
|
|
39
|
+
lock.forUpdate = true;
|
|
40
|
+
lock.aliases.push(alias);
|
|
41
|
+
}
|
|
42
|
+
if (span.skipLocked)
|
|
43
|
+
lock.skipLocked = true;
|
|
44
|
+
|
|
45
|
+
if (!span.legs)
|
|
46
|
+
return;
|
|
47
|
+
const visitor = {};
|
|
48
|
+
visitor.visitJoin = visitJoinedLeg;
|
|
49
|
+
visitor.visitOne = visitJoinedLeg;
|
|
50
|
+
visitor.visitMany = function() {};
|
|
51
|
+
|
|
52
|
+
function visitJoinedLeg(leg) {
|
|
53
|
+
collect(leg.span, alias + leg.name, lock);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
span.legs.forEach(leg => leg.accept(visitor));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function spanToLock(span, exclusive) {
|
|
60
|
+
return {
|
|
61
|
+
aliases: [],
|
|
62
|
+
forUpdate: Boolean(exclusive || span?.forUpdate),
|
|
63
|
+
skipLocked: Boolean(span?.skipLocked)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function hasLock(lock) {
|
|
68
|
+
return Boolean(lock.forUpdate || lock.skipLocked);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
selectLockSql,
|
|
73
|
+
tableHintSql
|
|
74
|
+
};
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
var newPrimaryKeyFilter = require('./newPrimaryKeyFilter');
|
|
2
|
-
var
|
|
2
|
+
var getMany = require('./getMany');
|
|
3
3
|
var extractStrategy = require('./tryGetFromDbById/extractStrategy');
|
|
4
4
|
|
|
5
5
|
function tryGet(context) {
|
|
6
6
|
var filter = newPrimaryKeyFilter.apply(null, arguments);
|
|
7
7
|
var table = arguments[1];
|
|
8
8
|
var strategy = extractStrategy.apply(null, arguments);
|
|
9
|
-
return
|
|
9
|
+
return getMany(context, table, filter, strategy).then(filterRows);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
tryGet.exclusive = function tryGet(context) {
|
|
13
13
|
var filter = newPrimaryKeyFilter.apply(null, arguments);
|
|
14
14
|
var table = arguments[1];
|
|
15
15
|
var strategy = extractStrategy.apply(null, arguments);
|
|
16
|
-
return
|
|
16
|
+
return getMany.exclusive(context, table, filter, strategy).then(filterRows);
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
function filterRows(rows) {
|
|
22
|
+
if (rows.length > 0)
|
|
23
|
+
return rows[0];
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
module.exports = tryGet;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
var newColumnSql = require('./singleQuery/newShallowColumnSql');
|
|
2
2
|
var newWhereSql = require('../../../table/query/singleQuery/newWhereSql');
|
|
3
3
|
var newParameterized = require('../../../table/query/newParameterized');
|
|
4
|
+
var lockSql = require('../../../table/query/singleQuery/lockSql');
|
|
4
5
|
|
|
5
6
|
function _new(context, table, filter, span, alias, subQueries, orderBy, limit, offset) {
|
|
6
7
|
var columnSql = newColumnSql(context, table, alias, span);
|
|
7
8
|
var whereSql = newWhereSql(context, table, filter, alias);
|
|
8
9
|
if (limit)
|
|
9
10
|
limit = limit + ' ';
|
|
11
|
+
const tableHint = lockSql.tableHintSql(context, span);
|
|
10
12
|
|
|
11
13
|
let join = '';
|
|
12
14
|
const set = new Set();
|
|
@@ -21,7 +23,7 @@ function _new(context, table, filter, span, alias, subQueries, orderBy, limit, o
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
return newParameterized('select ' + limit + columnSql).append(subQueries).append(' from ' + `[${table._dbName}] [${alias}]` + join).append(whereSql).append(orderBy + offset);
|
|
26
|
+
return newParameterized('select ' + limit + columnSql).append(subQueries).append(' from ' + `[${table._dbName}] [${alias}]` + tableHint + join).append(whereSql).append(orderBy + offset);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
module.exports = _new;
|
|
29
|
+
module.exports = _new;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
function selectForUpdateSql() {
|
|
2
|
+
return '';
|
|
3
|
+
}
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
selectForUpdateSql.tableHint = function(_context, lock) {
|
|
6
|
+
const hints = [];
|
|
7
|
+
if (lock.forUpdate)
|
|
8
|
+
hints.push('UPDLOCK');
|
|
9
|
+
if (lock.skipLocked) {
|
|
10
|
+
hints.push('READPAST');
|
|
11
|
+
hints.push('ROWLOCK');
|
|
12
|
+
}
|
|
13
|
+
if (hints.length === 0)
|
|
14
|
+
return '';
|
|
15
|
+
return ' WITH (' + hints.join(', ') + ')';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = selectForUpdateSql;
|