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
package/src/d1/newDatabase.js
CHANGED
|
@@ -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,85 +30,75 @@ function newDatabase(d1Database, 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
|
|
|
44
|
-
function begin() {
|
|
45
|
-
const transactionLess = true;
|
|
46
|
-
return _begin(transactionLess);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
36
|
async function runInTransaction() {
|
|
50
37
|
let result;
|
|
51
38
|
let transaction = newTransaction(domain, pool, options);
|
|
52
39
|
await new Promise(transaction)
|
|
53
40
|
.then(begin)
|
|
54
|
-
.then(fn)
|
|
41
|
+
.then(() => fn(domain))
|
|
55
42
|
.then((res) => result = res)
|
|
56
|
-
.then(c.commit)
|
|
57
|
-
.then(null, c.rollback);
|
|
43
|
+
.then(() => c.commit(domain))
|
|
44
|
+
.then(null, (e) => c.rollback(domain,e));
|
|
58
45
|
return result;
|
|
59
46
|
}
|
|
60
47
|
|
|
48
|
+
function begin() {
|
|
49
|
+
const transactionLess = true;
|
|
50
|
+
return _begin(domain, transactionLess);
|
|
51
|
+
}
|
|
52
|
+
|
|
61
53
|
function run() {
|
|
62
54
|
let p;
|
|
63
55
|
let transaction = newTransaction(domain, pool, options);
|
|
64
|
-
|
|
65
|
-
p = new Promise(transaction);
|
|
66
|
-
else
|
|
67
|
-
p = new promise(transaction);
|
|
56
|
+
p = new Promise(transaction);
|
|
68
57
|
|
|
69
58
|
return p.then(begin);
|
|
70
59
|
}
|
|
71
60
|
|
|
72
61
|
};
|
|
73
62
|
|
|
74
|
-
c.createTransaction = function() {
|
|
63
|
+
c.createTransaction = function(options) {
|
|
75
64
|
let domain = createDomain();
|
|
76
|
-
let transaction = newTransaction(domain, pool);
|
|
77
|
-
let p = domain.run(() => new Promise(transaction).then(
|
|
65
|
+
let transaction = newTransaction(domain, pool, options);
|
|
66
|
+
let p = domain.run(() => new Promise(transaction).then(begin));
|
|
78
67
|
|
|
79
68
|
function run(fn) {
|
|
80
69
|
return p.then(domain.run.bind(domain, fn));
|
|
81
70
|
}
|
|
82
|
-
return run;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
c.bindTransaction = function() {
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
var domain = process.domain;
|
|
88
|
-
let p = domain.run(() => true);
|
|
89
71
|
|
|
90
|
-
function
|
|
91
|
-
return
|
|
72
|
+
function begin() {
|
|
73
|
+
return _begin(domain, options);
|
|
92
74
|
}
|
|
75
|
+
|
|
76
|
+
run.rollback = rollback.bind(null, domain);
|
|
77
|
+
run.commit = commit.bind(null, domain);
|
|
78
|
+
|
|
93
79
|
return run;
|
|
80
|
+
|
|
94
81
|
};
|
|
95
82
|
|
|
96
83
|
c.query = function(query) {
|
|
97
84
|
let domain = createDomain();
|
|
98
85
|
let transaction = newTransaction(domain, pool);
|
|
99
86
|
let p = domain.run(() => new Promise(transaction)
|
|
100
|
-
.then(() => setSessionSingleton('changes', []))
|
|
101
|
-
.then(() => doQuery(query).then(onResult, onError)));
|
|
87
|
+
.then(() => setSessionSingleton(domain, 'changes', []))
|
|
88
|
+
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
102
89
|
return p;
|
|
103
90
|
|
|
104
91
|
function onResult(result) {
|
|
105
|
-
releaseDbClient();
|
|
92
|
+
releaseDbClient(domain);
|
|
106
93
|
return result;
|
|
107
94
|
}
|
|
108
95
|
|
|
109
96
|
function onError(e) {
|
|
110
|
-
releaseDbClient();
|
|
97
|
+
releaseDbClient(domain);
|
|
111
98
|
throw e;
|
|
112
99
|
}
|
|
113
100
|
};
|
|
114
101
|
|
|
115
|
-
|
|
116
102
|
c.rollback = rollback;
|
|
117
103
|
c.commit = commit;
|
|
118
104
|
|
package/src/d1/newPool.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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(d1Database, poolOptions) {
|
|
8
8
|
var pool = newGenericPool(d1Database, poolOptions);
|
|
@@ -11,7 +11,7 @@ function newPool(d1Database, poolOptions) {
|
|
|
11
11
|
var 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
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-prototype-builtins */
|
|
2
2
|
var EventEmitter = require('events').EventEmitter;
|
|
3
3
|
|
|
4
|
-
var defaults = require('
|
|
4
|
+
var defaults = require('../../poolDefaults');
|
|
5
5
|
var genericPool = require('../../generic-pool');
|
|
6
|
+
var process = require('node:process');
|
|
6
7
|
|
|
7
8
|
function newGenericPool(d1Database, poolOptions) {
|
|
8
9
|
poolOptions = poolOptions || {};
|
package/src/emitEvent.js
CHANGED
|
@@ -6,12 +6,14 @@ function emitEvent() {
|
|
|
6
6
|
var result = [];
|
|
7
7
|
for (var i = 0; i < copy.length; i++) {
|
|
8
8
|
var callback = copy[i];
|
|
9
|
-
result.push(callback.apply(null,arguments));
|
|
9
|
+
result.push(callback.apply(null, arguments));
|
|
10
10
|
}
|
|
11
11
|
return result;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
emit.add = function(callback) {
|
|
15
|
+
if (!callback)
|
|
16
|
+
throw new Error('missing callback');
|
|
15
17
|
callbacks.push(callback);
|
|
16
18
|
};
|
|
17
19
|
|
|
@@ -22,15 +24,15 @@ function emitEvent() {
|
|
|
22
24
|
|
|
23
25
|
emit.remove = function(callback) {
|
|
24
26
|
for (var i = 0; i < callbacks.length; i++) {
|
|
25
|
-
if(callbacks[i] === callback){
|
|
26
|
-
callbacks.splice(i,1);
|
|
27
|
+
if (callbacks[i] === callback) {
|
|
28
|
+
callbacks.splice(i, 1);
|
|
27
29
|
return;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
emit.tryRemove = function(callback) {
|
|
33
|
-
if(callback)
|
|
35
|
+
if (callback)
|
|
34
36
|
emit.remove(callback);
|
|
35
37
|
};
|
|
36
38
|
|
package/src/emptyFilter.js
CHANGED
|
@@ -7,26 +7,26 @@ function emptyFilter() {
|
|
|
7
7
|
emptyFilter.sql = parameterized.sql;
|
|
8
8
|
emptyFilter.parameters = parameterized.parameters;
|
|
9
9
|
|
|
10
|
-
emptyFilter.and = function(other) {
|
|
11
|
-
other = negotiateRawSqlFilter(other);
|
|
12
|
-
for (var i =
|
|
13
|
-
other = other.and(arguments[i]);
|
|
10
|
+
emptyFilter.and = function(context, other) {
|
|
11
|
+
other = negotiateRawSqlFilter(context, other);
|
|
12
|
+
for (var i = 2; i < arguments.length; i++) {
|
|
13
|
+
other = other.and(context, arguments[i]);
|
|
14
14
|
}
|
|
15
15
|
return other;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
emptyFilter.or = function(other) {
|
|
19
|
-
other = negotiateRawSqlFilter(other);
|
|
20
|
-
for (var i =
|
|
21
|
-
other = other.or(arguments[i]);
|
|
18
|
+
emptyFilter.or = function(context, other) {
|
|
19
|
+
other = negotiateRawSqlFilter(context, other);
|
|
20
|
+
for (var i = 2; i < arguments.length; i++) {
|
|
21
|
+
other = other.or(context, arguments[i]);
|
|
22
22
|
}
|
|
23
23
|
return other;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
emptyFilter.not = function(other) {
|
|
27
|
-
other = negotiateRawSqlFilter(other).not();
|
|
28
|
-
for (var i =
|
|
29
|
-
other = other.and(arguments[i]);
|
|
26
|
+
emptyFilter.not = function(context, other) {
|
|
27
|
+
other = negotiateRawSqlFilter(context, other).not(context);
|
|
28
|
+
for (var i = 2; i < arguments.length; i++) {
|
|
29
|
+
other = other.and(context, arguments[i]);
|
|
30
30
|
}
|
|
31
31
|
return other;
|
|
32
32
|
|
|
@@ -5,13 +5,13 @@ var extractLimit = require('../table/query/extractLimit');
|
|
|
5
5
|
var newParameterized = require('../table/query/newParameterized');
|
|
6
6
|
var extractOffset = require('../table/query/extractOffset');
|
|
7
7
|
|
|
8
|
-
function newQuery(table,filter,span,alias) {
|
|
8
|
+
function newQuery(context,table,filter,span,alias) {
|
|
9
9
|
filter = extractFilter(filter);
|
|
10
|
-
var orderBy = extractOrderBy(table,alias,span.orderBy);
|
|
11
|
-
var limit = extractLimit(span);
|
|
12
|
-
var offset = extractOffset(span);
|
|
10
|
+
var orderBy = extractOrderBy(context,table,alias,span.orderBy);
|
|
11
|
+
var limit = extractLimit(context, span);
|
|
12
|
+
var offset = extractOffset(context, span);
|
|
13
13
|
|
|
14
|
-
var query = newSingleQuery(table,filter,span,alias,orderBy,limit,offset);
|
|
14
|
+
var query = newSingleQuery(context,table,filter,span,alias,orderBy,limit,offset);
|
|
15
15
|
return newParameterized(query.sql(), query.parameters);
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -4,12 +4,12 @@ var newJoinSql = require('../../table/query/singleQuery/newJoinSql');
|
|
|
4
4
|
var newParameterized = require('../../table/query/newParameterized');
|
|
5
5
|
var getSessionSingleton = require('../../table/getSessionSingleton');
|
|
6
6
|
|
|
7
|
-
function _new(table,filter,span, alias,orderBy,limit,offset) {
|
|
8
|
-
var quote = getSessionSingleton('quote');
|
|
7
|
+
function _new(context,table,filter,span, alias,orderBy,limit,offset) {
|
|
8
|
+
var quote = getSessionSingleton(context, 'quote');
|
|
9
9
|
var name = quote(table._dbName);
|
|
10
|
-
var columnSql = newColumnSql(table,span,alias,true);
|
|
11
|
-
var joinSql = newJoinSql(span, alias);
|
|
12
|
-
var whereSql = newWhereSql(table,filter,alias);
|
|
10
|
+
var columnSql = newColumnSql(context,table,span,alias,true);
|
|
11
|
+
var joinSql = newJoinSql(context, span, alias);
|
|
12
|
+
var whereSql = newWhereSql(context,table,filter,alias);
|
|
13
13
|
if (limit)
|
|
14
14
|
limit = limit + ' ';
|
|
15
15
|
|
package/src/getManyDto.js
CHANGED
|
@@ -4,19 +4,19 @@ const negotiateRawSqlFilter = require('./table/column/negotiateRawSqlFilter');
|
|
|
4
4
|
const strategyToSpan = require('./table/strategyToSpan');
|
|
5
5
|
const executeQueries = require('./table/executeQueries');
|
|
6
6
|
|
|
7
|
-
async function getManyDto(table, filter, strategy, spanFromParent, updateParent) {
|
|
8
|
-
filter = negotiateRawSqlFilter(filter, table);
|
|
7
|
+
async function getManyDto(context, table, filter, strategy, spanFromParent, updateParent) {
|
|
8
|
+
filter = negotiateRawSqlFilter(context, filter, table);
|
|
9
9
|
if (strategy && strategy.where) {
|
|
10
|
-
let arg = typeof strategy.where === 'function' ? strategy.where(table) : strategy.where
|
|
11
|
-
filter = filter.and(arg);
|
|
10
|
+
let arg = typeof strategy.where === 'function' ? strategy.where(context, table) : strategy.where;//todo
|
|
11
|
+
filter = filter.and(context, arg);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
let span = spanFromParent || strategyToSpan(table, strategy);
|
|
15
15
|
let alias = table._dbName;
|
|
16
16
|
|
|
17
|
-
const query = newQuery(table, filter, span, alias);
|
|
18
|
-
const res = await executeQueries([query]);
|
|
19
|
-
return decode(strategy, span, await res[0], undefined, updateParent);
|
|
17
|
+
const query = newQuery(context, table, filter, span, alias);
|
|
18
|
+
const res = await executeQueries(context, [query]);
|
|
19
|
+
return decode(context, strategy, span, await res[0], undefined, updateParent);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function newCreateRow(span) {
|
|
@@ -149,7 +149,7 @@ function hasManyRelations(span) {
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys(rows[0]) : [], updateParent) {
|
|
152
|
+
async function decode(context, strategy, span, rows, keys = rows.length > 0 ? Object.keys(rows[0]) : [], updateParent) {
|
|
153
153
|
const table = span.table;
|
|
154
154
|
let columnsMap = span.columns;
|
|
155
155
|
const columns = table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
@@ -179,13 +179,14 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
const column = columns[j];
|
|
182
|
-
|
|
182
|
+
//todo
|
|
183
|
+
outRow[column.alias] = column.decode(context, row[keys[j]]);
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
for (let j = 0; j < aggregateKeys.length; j++) {
|
|
186
187
|
const key = aggregateKeys[j];
|
|
187
|
-
const parse = span.aggregates[key].column?.decode || Number.parseFloat;
|
|
188
|
-
outRow[key] = parse(row[keys[j + columnsLength]]);
|
|
188
|
+
const parse = span.aggregates[key].column?.decode || ((context, arg) => Number.parseFloat(arg));
|
|
189
|
+
outRow[key] = parse(context, row[keys[j + columnsLength]]);
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
outRows[i] = outRow;
|
|
@@ -208,13 +209,13 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
208
209
|
const all = [];
|
|
209
210
|
|
|
210
211
|
if (shouldCreateMap) {
|
|
211
|
-
all.push(decodeManyRelations(strategy, span));
|
|
212
|
-
all.push(decodeRelations2(strategy, span, rows, outRows, keys));
|
|
212
|
+
all.push(decodeManyRelations(context, strategy, span));
|
|
213
|
+
all.push(decodeRelations2(context, strategy, span, rows, outRows, keys));
|
|
213
214
|
}
|
|
214
215
|
// decodeRelations2(strategy, span, rows, outRows, keys);
|
|
215
216
|
// }
|
|
216
217
|
else
|
|
217
|
-
all.push(decodeRelations2(strategy, span, rows, outRows, keys));
|
|
218
|
+
all.push(decodeRelations2(context, strategy, span, rows, outRows, keys));
|
|
218
219
|
|
|
219
220
|
await Promise.all(all);
|
|
220
221
|
|
|
@@ -240,7 +241,7 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
240
241
|
|
|
241
242
|
}
|
|
242
243
|
|
|
243
|
-
async function decodeManyRelations(strategy, span) {
|
|
244
|
+
async function decodeManyRelations(context, strategy, span) {
|
|
244
245
|
const promises = [];
|
|
245
246
|
const c = {};
|
|
246
247
|
c.visitJoin = () => { };
|
|
@@ -252,11 +253,11 @@ async function decodeManyRelations(strategy, span) {
|
|
|
252
253
|
const relation = table._relations[name];
|
|
253
254
|
const rowsMap = span._rowsMap;
|
|
254
255
|
|
|
255
|
-
const filter = createOneFilter(relation, span._ids);
|
|
256
|
+
const filter = createOneFilter(context, relation, span._ids);
|
|
256
257
|
const extractKey = createExtractKey(leg);
|
|
257
258
|
const extractFromMap = createExtractFromMap(rowsMap, table._primaryColumns);
|
|
258
259
|
|
|
259
|
-
const p = getManyDto(relation.childTable, filter, strategy[name], leg.span, updateParent);
|
|
260
|
+
const p = getManyDto(context, relation.childTable, filter, strategy[name], leg.span, updateParent);
|
|
260
261
|
// .then(subRows => {
|
|
261
262
|
// for (let i = 0; i < subRows.length; i++) {
|
|
262
263
|
// const key = extractKey(subRows[i]);
|
|
@@ -299,11 +300,11 @@ async function decodeManyRelations(strategy, span) {
|
|
|
299
300
|
|
|
300
301
|
await Promise.all(promises);
|
|
301
302
|
}
|
|
302
|
-
async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
|
|
303
|
+
async function decodeRelations2(context, strategy, span, rawRows, resultRows, keys) {
|
|
303
304
|
const c = {};
|
|
304
305
|
c.visitJoin = function(leg) {
|
|
305
306
|
const name = leg.name;
|
|
306
|
-
return decode(strategy[name], leg.span, rawRows, keys, updateParent);
|
|
307
|
+
return decode(context, strategy[name], leg.span, rawRows, keys, updateParent);
|
|
307
308
|
|
|
308
309
|
function updateParent(subRow, i) {
|
|
309
310
|
resultRows[i][name] = subRow;
|
|
@@ -323,11 +324,11 @@ async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
|
|
|
323
324
|
await processLegsSequentially(span.legs);
|
|
324
325
|
}
|
|
325
326
|
|
|
326
|
-
function createOneFilter(relation, ids) {
|
|
327
|
+
function createOneFilter(context, relation, ids) {
|
|
327
328
|
const columns = relation.joinRelation.columns;
|
|
328
329
|
|
|
329
330
|
if (columns.length === 1)
|
|
330
|
-
return columns[0].in(ids);
|
|
331
|
+
return columns[0].in(context, ids);
|
|
331
332
|
|
|
332
333
|
else
|
|
333
334
|
return createCompositeFilter();
|
|
@@ -338,11 +339,11 @@ function createOneFilter(relation, ids) {
|
|
|
338
339
|
let nextFilter;
|
|
339
340
|
for (let i = 0; i < columns.length; i++) {
|
|
340
341
|
if (nextFilter)
|
|
341
|
-
nextFilter = nextFilter.and(columns[i].eq(id[i]));
|
|
342
|
+
nextFilter = nextFilter.and(context, columns[i].eq(context, id[i]));
|
|
342
343
|
else
|
|
343
|
-
nextFilter = columns[i].eq(id[i]);
|
|
344
|
+
nextFilter = columns[i].eq(context, id[i]);
|
|
344
345
|
}
|
|
345
|
-
filter = filter.or(nextFilter);
|
|
346
|
+
filter = filter.or(context, nextFilter);
|
|
346
347
|
}
|
|
347
348
|
return filter;
|
|
348
349
|
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Utility to decrement recursion depth
|
|
2
|
+
type DecrementDepth<D extends any[]> = D extends [any, ...infer Rest] ? Rest : never;
|
|
3
|
+
|
|
4
|
+
// Define the structure of each node's definition within NodeTypeMap
|
|
5
|
+
// NodeKey is a string (or a type union of strings) that identifies a node.
|
|
6
|
+
type NodeDefinition = {
|
|
7
|
+
base: {}; // Base type of the node
|
|
8
|
+
children?: Record<string, string>; // childPropName -> childNodeKey
|
|
9
|
+
parent?: { prop: string; node: string }; // parentPropName, parentNodeKey
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// A map of node keys to their definitions
|
|
13
|
+
type NodeTypeMap = {
|
|
14
|
+
[NodeKey: string]: NodeDefinition;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// The RecursiveNode type:
|
|
18
|
+
// D: depth array
|
|
19
|
+
// M: the NodeTypeMap
|
|
20
|
+
// K: the NodeKey for the current node
|
|
21
|
+
//
|
|
22
|
+
// If D is empty, we return just the base type.
|
|
23
|
+
// If not empty, we return the base type plus recursively expanded children and parent.
|
|
24
|
+
type RecursiveNode<
|
|
25
|
+
D extends any[],
|
|
26
|
+
M extends Record<string, NodeDefinition>,
|
|
27
|
+
K extends keyof M
|
|
28
|
+
> = D extends []
|
|
29
|
+
? // At zero depth, just return the base type of this node
|
|
30
|
+
M[K]['base']
|
|
31
|
+
: // Non-zero depth:
|
|
32
|
+
// Start with the base type
|
|
33
|
+
M[K]['base']
|
|
34
|
+
// Add recursively expanded children, if any
|
|
35
|
+
& (M[K]['children'] extends Record<string, string>
|
|
36
|
+
? { [ChildProp in keyof M[K]['children']]:
|
|
37
|
+
RecursiveNode<DecrementDepth<D>, M, M[K]['children'][ChildProp]> }
|
|
38
|
+
: {})
|
|
39
|
+
// Add recursively expanded parent, if defined
|
|
40
|
+
& (M[K]['parent'] extends { prop: string; node: string }
|
|
41
|
+
? { [P in M[K]['parent']['prop']]:
|
|
42
|
+
RecursiveNode<DecrementDepth<D>, M, M[K]['parent']['node']> }
|
|
43
|
+
: {});
|
|
44
|
+
|
|
45
|
+
// ================== EXAMPLE USAGE ==================
|
|
46
|
+
|
|
47
|
+
// Define your base types (clean, no recursion)
|
|
48
|
+
type ABase = { name: string; foo: number };
|
|
49
|
+
type BBase = { title: string; bar: number };
|
|
50
|
+
type CBase = { label: string; baz: boolean };
|
|
51
|
+
type DBase = { tag: string; qux: string };
|
|
52
|
+
|
|
53
|
+
// Now define a NodeTypeMap describing the structure:
|
|
54
|
+
// Let's say we have a graph like before, but arbitrary children.
|
|
55
|
+
// A has three children: bChild -> B, cChild -> C, dChild -> D
|
|
56
|
+
// B, C, D each have a parent going back to A
|
|
57
|
+
// D also has a cLink -> C
|
|
58
|
+
|
|
59
|
+
type MyNodeTypeMap = {
|
|
60
|
+
A: {
|
|
61
|
+
base: ABase;
|
|
62
|
+
children: {
|
|
63
|
+
bChild: 'B';
|
|
64
|
+
cChild: 'C';
|
|
65
|
+
dChild: 'D';
|
|
66
|
+
};
|
|
67
|
+
// No parent defined for A (root)
|
|
68
|
+
};
|
|
69
|
+
B: {
|
|
70
|
+
base: BBase;
|
|
71
|
+
children: {
|
|
72
|
+
fooLink: 'C'; // D links to C as well
|
|
73
|
+
};
|
|
74
|
+
parent: { prop: 'aParent'; node: 'A' };
|
|
75
|
+
};
|
|
76
|
+
C: {
|
|
77
|
+
base: CBase;
|
|
78
|
+
// C has no children defined here
|
|
79
|
+
parent: { prop: 'aParent'; node: 'A' };
|
|
80
|
+
};
|
|
81
|
+
D: {
|
|
82
|
+
base: DBase;
|
|
83
|
+
children: {
|
|
84
|
+
cLink: 'C'; // D links to C as well
|
|
85
|
+
};
|
|
86
|
+
parent: { prop: 'aParent'; node: 'A' };
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Limit recursion to depth 2
|
|
91
|
+
type Depth2 = [unknown, unknown, unknown, unknown];
|
|
92
|
+
|
|
93
|
+
// Now we can create a type for each node expanded to Depth2:
|
|
94
|
+
type MyA = RecursiveNode<Depth2, MyNodeTypeMap, 'A'>;
|
|
95
|
+
type MyB = RecursiveNode<Depth2, MyNodeTypeMap, 'B'>;
|
|
96
|
+
type MyC = RecursiveNode<Depth2, MyNodeTypeMap, 'C'>;
|
|
97
|
+
type MyD = RecursiveNode<Depth2, MyNodeTypeMap, 'D'>;
|
|
98
|
+
|
|
99
|
+
// Create an instance of MyA:
|
|
100
|
+
const aInstance: MyA = {
|
|
101
|
+
name: "Root A",
|
|
102
|
+
foo: 1,
|
|
103
|
+
bChild: {
|
|
104
|
+
title: "B Node",
|
|
105
|
+
bar: 100,
|
|
106
|
+
aParent: {
|
|
107
|
+
name: "A Level 2",
|
|
108
|
+
foo: 2,
|
|
109
|
+
bChild: { title: "B2", bar: 200, aParent: { name: "A Terminal", foo: 3 } },
|
|
110
|
+
cChild: { label: "C2", baz: true, aParent: { name: "A Terminal", foo: 4 } },
|
|
111
|
+
dChild: {
|
|
112
|
+
tag: "D2",
|
|
113
|
+
qux: "XYZ",
|
|
114
|
+
aParent: { name: "A Terminal", foo: 5 },
|
|
115
|
+
cLink: { label: "C-Terminal", baz: false }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
cChild: {
|
|
120
|
+
label: "C Node",
|
|
121
|
+
baz: true,
|
|
122
|
+
aParent: {
|
|
123
|
+
name: "A Level 2C",
|
|
124
|
+
foo: 10,
|
|
125
|
+
bChild: { title: "B3", bar: 300, aParent: { name: "A Terminal", foo: 6 } },
|
|
126
|
+
cChild: { label: "C3", baz: false, aParent: { name: "A Terminal", foo: 7 } },
|
|
127
|
+
dChild: {
|
|
128
|
+
tag: "D3",
|
|
129
|
+
qux: "ABC",
|
|
130
|
+
aParent: { name: "A Terminal", foo: 8 },
|
|
131
|
+
cLink: { label: "C-Terminal2", baz: true }
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
dChild: {
|
|
136
|
+
tag: "D Node",
|
|
137
|
+
qux: "QWE",
|
|
138
|
+
aParent: {
|
|
139
|
+
name: "A Level 2D",
|
|
140
|
+
foo: 20,
|
|
141
|
+
bChild: { title: "B4", bar: 400, aParent: { name: "A Terminal", foo: 9 } },
|
|
142
|
+
cChild: { label: "C4", baz: true, aParent: { name: "A Terminal", foo: 11 } },
|
|
143
|
+
dChild: {
|
|
144
|
+
tag: "D4",
|
|
145
|
+
qux: "DEF",
|
|
146
|
+
aParent: { name: "A Terminal", foo: 12 },
|
|
147
|
+
cLink: { label: "C-Terminal3", baz: false }
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
cLink: {
|
|
151
|
+
label: "C Link Node",
|
|
152
|
+
baz: false
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
console.log(aInstance.name); // "Root A"
|
|
158
|
+
console.log(aInstance.bChild.title); // "B Node"
|
|
159
|
+
console.log(aInstance.bChild.aParent.cChild.label); // "C2"
|
|
160
|
+
console.log(aInstance.dChild.aParent.dChild.cLink.baz); // true
|
|
161
|
+
|
|
162
|
+
// interface HasChild<C> {
|
|
163
|
+
// child: C;
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
// interface HasParent<P> {
|
|
167
|
+
// parent: P;
|
|
168
|
+
// }
|
|
169
|
+
|
|
170
|
+
// interface AType<C> extends HasChild<C> {
|
|
171
|
+
// name: string;
|
|
172
|
+
// }
|
|
173
|
+
|
|
174
|
+
// interface BType<P> extends HasParent<P> {
|
|
175
|
+
// title: string;
|
|
176
|
+
// }
|
|
177
|
+
|
|
178
|
+
// // Here is the key part: By using a circular type definition, we create a
|
|
179
|
+
// // specific pair (CyclicA, CyclicB) that point to each other generically.
|
|
180
|
+
// // 'CyclicA' extends 'AType' and expects a child of type 'CyclicB'.
|
|
181
|
+
// // 'CyclicB' extends 'BType' and expects a parent of type 'CyclicA'.
|
|
182
|
+
|
|
183
|
+
// // Note: TypeScript allows this pattern as long as the interfaces are defined first.
|
|
184
|
+
// // The cycle is established by the subsequent type definitions.
|
|
185
|
+
|
|
186
|
+
// type CyclicA = AType<CyclicB>;
|
|
187
|
+
// type CyclicB = BType<CyclicA>;
|
|
188
|
+
|
|
189
|
+
// // Now 'CyclicA' and 'CyclicB' are fully defined, with a cyclical reference:
|
|
190
|
+
// // CyclicA -> child: CyclicB
|
|
191
|
+
// // CyclicB -> parent: CyclicA
|
|
192
|
+
|
|
193
|
+
// // Example usage:
|
|
194
|
+
// const aInstance: CyclicA ;
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
// // Establish the cycle at runtime.
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
// // We can now traverse back and forth:
|
|
201
|
+
// console.log(aInstance.name); // "Node A"
|
|
202
|
+
// console.log(aInstance.child.title); // "Node B"
|
|
203
|
+
// console.log(aInstance.child.parent.name); // "Node A" (cycle complete)
|
|
204
|
+
|
|
205
|
+
// // This pattern is generic. If you want another pair of cyclical types,
|
|
206
|
+
// // say X and Y, you can do:
|
|
207
|
+
|
|
208
|
+
// type CyclicX = XType<CyclicY>; // define similarly using HasChild/HasParent
|
|
209
|
+
// type CyclicY = YType<CyclicX>;
|
|
210
|
+
// // ...and so forth, using the same building blocks.
|
|
211
|
+
|