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
|
@@ -14,24 +14,24 @@ function newRelatedColumn(column, relations, isShallow, depth) {
|
|
|
14
14
|
c[propName] = wrapFilter(prop);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
c.groupSum = aggregateGroup.
|
|
18
|
-
c.groupAvg = aggregateGroup.
|
|
19
|
-
c.groupMin = aggregateGroup.
|
|
20
|
-
c.groupMax = aggregateGroup.
|
|
21
|
-
c.groupCount = aggregateGroup.
|
|
22
|
-
c.sum = aggregate.
|
|
23
|
-
c.avg = aggregate.
|
|
24
|
-
c.min = aggregate.
|
|
25
|
-
c.max = aggregate.
|
|
26
|
-
c.count = aggregate.
|
|
27
|
-
c.self = childColumn.
|
|
17
|
+
c.groupSum = (context, ...rest) => aggregateGroup.apply(null, [context, 'sum', column, relations, ...rest]);
|
|
18
|
+
c.groupAvg = (context, ...rest) => aggregateGroup.apply(null, [context, 'avg', column, relations, ...rest]);
|
|
19
|
+
c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', column, relations, ...rest]);
|
|
20
|
+
c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', column, relations, ...rest]);
|
|
21
|
+
c.groupCount = (context, ...rest) => aggregateGroup.apply(null, [context, 'count', column, relations, false, ...rest]);
|
|
22
|
+
c.sum = (context, ...rest) => aggregate.apply(null, [context, 'sum', column, relations, ...rest]);
|
|
23
|
+
c.avg = (context, ...rest) => aggregate.apply(null, [context, 'avg', column, relations, ...rest]);
|
|
24
|
+
c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', column, relations, ...rest]);
|
|
25
|
+
c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', column, relations, ...rest]);
|
|
26
|
+
c.count = (context, ...rest) => aggregate.apply(null, [context, 'count', column, relations, false, ...rest]);
|
|
27
|
+
c.self = (context, ...rest) => childColumn.apply(null, [context, column, relations, ...rest]);
|
|
28
28
|
|
|
29
29
|
return c;
|
|
30
30
|
|
|
31
31
|
function wrapFilter(filter) {
|
|
32
32
|
return runFilter;
|
|
33
33
|
|
|
34
|
-
function runFilter() {
|
|
34
|
+
function runFilter(context) {
|
|
35
35
|
var args = [];
|
|
36
36
|
for (var i = 0; i < arguments.length; i++) {
|
|
37
37
|
args.push(arguments[i]);
|
|
@@ -40,7 +40,7 @@ function newRelatedColumn(column, relations, isShallow, depth) {
|
|
|
40
40
|
var shallowFilter = filter.apply(null, args);
|
|
41
41
|
if (isShallow)
|
|
42
42
|
return shallowFilter;
|
|
43
|
-
return newSubFilter(relations, shallowFilter, depth);
|
|
43
|
+
return newSubFilter(context, relations, shallowFilter, depth);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -2,8 +2,8 @@ var newParameterized = require('../query/newParameterized');
|
|
|
2
2
|
var newBoolean = require('../column/newBoolean');
|
|
3
3
|
const getSessionSingleton = require('../getSessionSingleton');
|
|
4
4
|
|
|
5
|
-
function newSelectSql(table, alias) {
|
|
6
|
-
const quote = getSessionSingleton('quote');
|
|
5
|
+
function newSelectSql(context, table, alias) {
|
|
6
|
+
const quote = getSessionSingleton(context, 'quote');
|
|
7
7
|
const quotedAlias = quote(alias);
|
|
8
8
|
const colName = quote(table._primaryColumns[0]._dbName);
|
|
9
9
|
const sql = 'SELECT ' + quotedAlias + '.' + colName + ' FROM ' + quote(table._dbName) + ' ' + quotedAlias;
|
|
@@ -2,13 +2,13 @@ var newSelect = require('./selectSql');
|
|
|
2
2
|
var newJoin = require('./joinSql');
|
|
3
3
|
var newWhere = require('./whereSql');
|
|
4
4
|
|
|
5
|
-
function newSubFilter(relations, shallowFilter, depth) {
|
|
5
|
+
function newSubFilter(context, relations, shallowFilter, depth) {
|
|
6
6
|
var relationCount = relations.length;
|
|
7
7
|
var alias = 'x' + relationCount;
|
|
8
8
|
var table = relations[relationCount-1].childTable;
|
|
9
|
-
var exists = newSelect(table,alias).prepend('EXISTS (');
|
|
10
|
-
var join = newJoin(relations, depth);
|
|
11
|
-
var where = newWhere(relations,shallowFilter, depth);
|
|
9
|
+
var exists = newSelect(context, table,alias).prepend('EXISTS (');
|
|
10
|
+
var join = newJoin(context, relations, depth);
|
|
11
|
+
var where = newWhere(context, relations,shallowFilter, depth);
|
|
12
12
|
return exists.append(join).append(where).append(')');
|
|
13
13
|
|
|
14
14
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
let newRelatedTable = _newRelatedTable;
|
|
2
1
|
const negotiateRawSqlFilter = require('../column/negotiateRawSqlFilter');
|
|
3
2
|
let tryGetSessionContext = require('../tryGetSessionContext');
|
|
4
3
|
|
|
5
4
|
function newWhere(_relations, _depth) {
|
|
6
5
|
|
|
7
|
-
function where(fn) {
|
|
8
|
-
const includeMany = tryGetSessionContext()?.engine === 'mssql';
|
|
6
|
+
function where(context, fn) {
|
|
7
|
+
const includeMany = tryGetSessionContext(context)?.engine === 'mssql';
|
|
9
8
|
let { relations, alias } = extract(includeMany, _relations);
|
|
10
9
|
const table = relations[relations.length - 1].childTable;
|
|
11
10
|
if (!relations[0].isMany || includeMany)
|
|
@@ -13,7 +12,7 @@ function newWhere(_relations, _depth) {
|
|
|
13
12
|
|
|
14
13
|
try {
|
|
15
14
|
let arg = typeof fn === 'function' ? fn(table) : fn;
|
|
16
|
-
let anyFilter = negotiateRawSqlFilter(arg);
|
|
15
|
+
let anyFilter = negotiateRawSqlFilter(context, arg);
|
|
17
16
|
delete table._rootAlias;
|
|
18
17
|
return anyFilter;
|
|
19
18
|
}
|
|
@@ -42,9 +41,4 @@ function newWhere(_relations, _depth) {
|
|
|
42
41
|
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
function _newRelatedTable() {
|
|
46
|
-
newRelatedTable = require('../newRelatedTable');
|
|
47
|
-
return newRelatedTable.apply(null, arguments);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
44
|
module.exports = newWhere;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var newShallowJoinSql = require('../query/singleQuery/joinSql/newShallowJoinSqlCore');
|
|
2
2
|
|
|
3
|
-
function newWhereSql(relations, shallowFilter, depth = 0) {
|
|
3
|
+
function newWhereSql(context, relations, shallowFilter, depth = 0) {
|
|
4
4
|
let relation = relations[depth];
|
|
5
5
|
var c = {};
|
|
6
6
|
var sql;
|
|
@@ -29,7 +29,7 @@ function newWhereSql(relations, shallowFilter, depth = 0) {
|
|
|
29
29
|
|
|
30
30
|
function where(alias, leftColumns, rightColumns) {
|
|
31
31
|
var table = relation.childTable;
|
|
32
|
-
var joinCore = newShallowJoinSql(table, leftColumns, rightColumns, alias, 'x' + (depth + 1));
|
|
32
|
+
var joinCore = newShallowJoinSql(context, table, leftColumns, rightColumns, alias, 'x' + (depth + 1));
|
|
33
33
|
if (shallowFilter && shallowFilter.sql()) {
|
|
34
34
|
sql = joinCore.prepend(' WHERE ').append(' AND ').append(shallowFilter);
|
|
35
35
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var extractParentKey = require('./extractParentKey');
|
|
2
2
|
|
|
3
|
-
function synchronizeAdded(action, joinRelation) {
|
|
3
|
+
function synchronizeAdded(context, action, joinRelation) {
|
|
4
4
|
var cache = joinRelation.parentTable._cache;
|
|
5
|
-
cache.subscribeAdded(onAdded);
|
|
5
|
+
cache.subscribeAdded(context, onAdded);
|
|
6
6
|
|
|
7
7
|
function onAdded(child) {
|
|
8
8
|
var parent = extractParentKey(joinRelation, child);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var extractParentKey = require('./extractParentKey');
|
|
2
2
|
|
|
3
|
-
function synchronizeChanged(manyCache, joinRelation, parent, child) {
|
|
3
|
+
function synchronizeChanged(context, manyCache, joinRelation, parent, child) {
|
|
4
4
|
var columns = joinRelation.columns;
|
|
5
5
|
columns.forEach(subscribeColumn);
|
|
6
6
|
child = null;
|
|
@@ -19,9 +19,9 @@ function synchronizeChanged(manyCache, joinRelation, parent, child) {
|
|
|
19
19
|
|
|
20
20
|
function onChanged(child) {
|
|
21
21
|
unsubscribe(child);
|
|
22
|
-
manyCache.tryRemove(parent, child);
|
|
22
|
+
manyCache.tryRemove(context, parent, child);
|
|
23
23
|
var newParent = extractParentKey(joinRelation, child);
|
|
24
|
-
manyCache.tryAdd(newParent, child);
|
|
24
|
+
manyCache.tryAdd(context, newParent, child);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var extractParentKey = require('./extractParentKey');
|
|
2
2
|
|
|
3
|
-
function synchronizeRemoved(action, joinRelation) {
|
|
3
|
+
function synchronizeRemoved(context, action, joinRelation) {
|
|
4
4
|
var cache = joinRelation.parentTable._cache;
|
|
5
|
-
cache.subscribeRemoved(onRemoved);
|
|
5
|
+
cache.subscribeRemoved(context, onRemoved);
|
|
6
6
|
|
|
7
7
|
function onRemoved(child) {
|
|
8
8
|
var parent = extractParentKey(joinRelation, child);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function newForeignKeyFilter(joinRelation, parentRow) {
|
|
1
|
+
function newForeignKeyFilter(context, joinRelation, parentRow) {
|
|
2
2
|
var columns = joinRelation.columns;
|
|
3
3
|
var rightTable = joinRelation.childTable;
|
|
4
4
|
|
|
@@ -12,7 +12,7 @@ function newForeignKeyFilter(joinRelation, parentRow) {
|
|
|
12
12
|
function getNextFilterPart(index) {
|
|
13
13
|
var column = columns[index];
|
|
14
14
|
var pk = rightTable._primaryColumns[index];
|
|
15
|
-
return column.eq(parentRow[pk.alias]);
|
|
15
|
+
return column.eq(context, parentRow[pk.alias]);
|
|
16
16
|
}
|
|
17
17
|
return filter;
|
|
18
18
|
}
|
|
@@ -9,46 +9,54 @@ var setSessionSingleton = require('../setSessionSingleton');
|
|
|
9
9
|
|
|
10
10
|
function newManyCache(joinRelation) {
|
|
11
11
|
var c = {};
|
|
12
|
-
var key
|
|
12
|
+
var key;
|
|
13
13
|
|
|
14
|
-
c.tryAdd = function(parent, child) {
|
|
15
|
-
c.getInnerCache().tryAdd(parent, child);
|
|
16
|
-
synchronizeChanged(c, joinRelation, parent, child);
|
|
14
|
+
c.tryAdd = function(context, parent, child) {
|
|
15
|
+
c.getInnerCache(context).tryAdd(parent, child);
|
|
16
|
+
synchronizeChanged(context, c, joinRelation, parent, child);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
c.tryRemove = function(parent, child) {
|
|
20
|
-
c.getInnerCache().tryRemove(parent, child);
|
|
19
|
+
c.tryRemove = function(context, parent, child) {
|
|
20
|
+
c.getInnerCache(context).tryRemove(parent, child);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
c.tryGet = function(parentRow) {
|
|
24
|
-
return c.getInnerCache().tryGet(parentRow);
|
|
23
|
+
c.tryGet = function(context, parentRow) {
|
|
24
|
+
return c.getInnerCache(context).tryGet(parentRow);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
c.getInnerCache = function() {
|
|
28
|
-
|
|
27
|
+
c.getInnerCache = function(context) {
|
|
28
|
+
const theKey = negotiateKey();
|
|
29
|
+
var cache = getSessionSingleton(context, theKey);
|
|
29
30
|
if (!cache) {
|
|
30
31
|
cache = newCacheCore(joinRelation);
|
|
31
|
-
setSessionSingleton(
|
|
32
|
-
fillCache();
|
|
33
|
-
synchronizeAdded(c.tryAdd, joinRelation);
|
|
34
|
-
synchronizeRemoved(c.tryRemove, joinRelation);
|
|
32
|
+
setSessionSingleton(context, theKey, cache);
|
|
33
|
+
fillCache(context);
|
|
34
|
+
synchronizeAdded(context, c.tryAdd.bind(null, context), joinRelation);
|
|
35
|
+
synchronizeRemoved(context, c.tryRemove.bind(null, context), joinRelation);
|
|
35
36
|
}
|
|
36
37
|
return cache;
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
|
|
40
|
-
function fillCache() {
|
|
41
|
+
function fillCache(context) {
|
|
41
42
|
var childTable = joinRelation.parentTable;
|
|
42
43
|
var childCache = childTable._cache;
|
|
43
|
-
var children = childCache.getAll();
|
|
44
|
+
var children = childCache.getAll(context);
|
|
44
45
|
children.forEach(addToCache);
|
|
45
46
|
|
|
46
47
|
function addToCache(child) {
|
|
47
48
|
var parent = extractParentKey(joinRelation, child);
|
|
48
|
-
c.tryAdd(parent, child);
|
|
49
|
+
c.tryAdd(context, parent, child);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
function negotiateKey() {
|
|
54
|
+
if (key)
|
|
55
|
+
return key;
|
|
56
|
+
key = newId();
|
|
57
|
+
return key;
|
|
58
|
+
|
|
59
|
+
}
|
|
52
60
|
|
|
53
61
|
|
|
54
62
|
return c;
|
|
@@ -4,18 +4,18 @@ function newOneCache(joinRelation) {
|
|
|
4
4
|
let c = {};
|
|
5
5
|
let cache = newManyCache(joinRelation);
|
|
6
6
|
|
|
7
|
-
c.tryGet = function(parent) {
|
|
8
|
-
let res = cache.tryGet(parent);
|
|
7
|
+
c.tryGet = function(context, parent) {
|
|
8
|
+
let res = cache.tryGet(context, parent);
|
|
9
9
|
if (res.length === 0)
|
|
10
10
|
return null;
|
|
11
11
|
return res[0];
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
c.getInnerCache = function() {
|
|
15
|
-
let _cache = cache.getInnerCache();
|
|
14
|
+
c.getInnerCache = function(context) {
|
|
15
|
+
let _cache = cache.getInnerCache(context);
|
|
16
16
|
let _c = {};
|
|
17
|
-
_c.tryGet = function(parent) {
|
|
18
|
-
let res = _cache.tryGet(parent);
|
|
17
|
+
_c.tryGet = function(context, parent) {
|
|
18
|
+
let res = _cache.tryGet(context, parent);
|
|
19
19
|
if (res.length === 0)
|
|
20
20
|
return null;
|
|
21
21
|
return res[0];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var getSessionSingleton = require('./getSessionSingleton');
|
|
2
2
|
var deleteSessionContext = require('./deleteSessionContext');
|
|
3
3
|
|
|
4
|
-
function release() {
|
|
5
|
-
var done = getSessionSingleton('dbClientDone');
|
|
6
|
-
var pool = getSessionSingleton('pool');
|
|
7
|
-
deleteSessionContext();
|
|
4
|
+
function release(context) {
|
|
5
|
+
var done = getSessionSingleton(context, 'dbClientDone');
|
|
6
|
+
var pool = getSessionSingleton(context, 'pool');
|
|
7
|
+
deleteSessionContext(context);
|
|
8
8
|
if (done)
|
|
9
9
|
done();
|
|
10
10
|
if (pool)
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
var negotiateQueryContext = require('./negotiateQueryContext');
|
|
2
2
|
var decodeDbRow = require('./decodeDbRow');
|
|
3
|
-
var nextDbRowToRow = _nextDbRowToRow;
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
function dbRowToRow(span, dbRow) {
|
|
4
|
+
function dbRowToRow(context, span, dbRow) {
|
|
7
5
|
var table = span.table;
|
|
8
|
-
var row = decodeDbRow(span, table, dbRow);
|
|
6
|
+
var row = decodeDbRow(context, span, table, dbRow);
|
|
9
7
|
var cache = table._cache;
|
|
10
|
-
if (!cache.tryGet(row)) {
|
|
8
|
+
if (!cache.tryGet(context, row)) {
|
|
11
9
|
var queryContext = span.queryContext;
|
|
12
10
|
negotiateQueryContext(queryContext, row);
|
|
13
11
|
Object.defineProperty(row, 'queryContext', {
|
|
@@ -17,17 +15,17 @@ function dbRowToRow(span, dbRow) {
|
|
|
17
15
|
});
|
|
18
16
|
row.queryContext = queryContext;
|
|
19
17
|
}
|
|
20
|
-
row = cache.tryAdd(row);
|
|
18
|
+
row = cache.tryAdd(context, row);
|
|
21
19
|
|
|
22
20
|
var c = {};
|
|
23
21
|
|
|
24
22
|
c.visitOne = function(leg) {
|
|
25
|
-
|
|
23
|
+
dbRowToRow(context, leg.span, dbRow);
|
|
26
24
|
leg.expand(row);
|
|
27
25
|
};
|
|
28
26
|
|
|
29
27
|
c.visitJoin = function(leg) {
|
|
30
|
-
|
|
28
|
+
dbRowToRow(context, leg.span, dbRow);
|
|
31
29
|
leg.expand(row);
|
|
32
30
|
};
|
|
33
31
|
|
|
@@ -43,9 +41,4 @@ function dbRowToRow(span, dbRow) {
|
|
|
43
41
|
return row;
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
function _nextDbRowToRow(span, dbRow) {
|
|
47
|
-
nextDbRowToRow = require('./dbRowToRow');
|
|
48
|
-
nextDbRowToRow(span, dbRow);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
44
|
module.exports = dbRowToRow;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var dbRowToRow = require('./dbRowToRow');
|
|
2
2
|
var newRowArray = require('../rowArray');
|
|
3
3
|
|
|
4
|
-
function dbRowsToRows(span, dbRows) {
|
|
4
|
+
function dbRowsToRows(context, span, dbRows) {
|
|
5
5
|
var rows = newRowArray();
|
|
6
6
|
for (var i = 0; i < dbRows.length; i++) {
|
|
7
|
-
var row = dbRowToRow(span, dbRows[i]);
|
|
7
|
+
var row = dbRowToRow(context, span, dbRows[i]);
|
|
8
8
|
rows.push(row);
|
|
9
9
|
}
|
|
10
10
|
return rows;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var newDecodeDbRow = require('./newDecodeDbRow');
|
|
2
2
|
|
|
3
|
-
function decodeDbRow(span, table, dbRow, shouldValidate, isInsert) {
|
|
3
|
+
function decodeDbRow(context, span, table, dbRow, shouldValidate, isInsert) {
|
|
4
4
|
var decode = span._decodeDbRow;
|
|
5
5
|
if (!decode) {
|
|
6
6
|
let aliases = new Set();
|
|
@@ -19,7 +19,7 @@ function decodeDbRow(span, table, dbRow, shouldValidate, isInsert) {
|
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
return decode(dbRow);
|
|
22
|
+
return decode(context, dbRow);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
module.exports = decodeDbRow;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function removeFromCache(row, strategy, table) {
|
|
1
|
+
function removeFromCache(context, row, strategy, table) {
|
|
4
2
|
if (Array.isArray(row)) {
|
|
5
3
|
removeManyRows();
|
|
6
4
|
return;
|
|
@@ -10,7 +8,7 @@ function removeFromCache(row, strategy, table) {
|
|
|
10
8
|
|
|
11
9
|
function removeManyRows() {
|
|
12
10
|
row.forEach( function(rowToRemove) {
|
|
13
|
-
|
|
11
|
+
removeFromCache(context, rowToRemove, strategy, table);
|
|
14
12
|
});
|
|
15
13
|
}
|
|
16
14
|
|
|
@@ -19,15 +17,10 @@ function removeFromCache(row, strategy, table) {
|
|
|
19
17
|
for (var relationName in strategy) {
|
|
20
18
|
var relation = relations[relationName];
|
|
21
19
|
var rows = relation.getRowsSync(row);
|
|
22
|
-
|
|
20
|
+
removeFromCache(context, rows, strategy[relationName], relation.childTable);
|
|
23
21
|
}
|
|
24
|
-
table._cache.tryRemove(row);
|
|
22
|
+
table._cache.tryRemove(context, row);
|
|
25
23
|
}
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
function _nextRemoveFromCache(row, strategy, table) {
|
|
29
|
-
nextRemoveFromCache = require('./removeFromCache');
|
|
30
|
-
nextRemoveFromCache(row, strategy, table);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
26
|
module.exports = removeFromCache;
|
|
@@ -5,25 +5,25 @@ var newPrimaryKeyFilter = require('../newPrimaryKeyFilter');
|
|
|
5
5
|
var createPatch = require('../../client/createPatch');
|
|
6
6
|
var createDto = require('./toDto/createDto');
|
|
7
7
|
|
|
8
|
-
function _delete(row, strategy, table) {
|
|
8
|
+
function _delete(context, row, strategy, table) {
|
|
9
9
|
var relations = [];
|
|
10
|
-
removeFromCache(row, strategy, table);
|
|
10
|
+
removeFromCache(context, row, strategy, table);
|
|
11
11
|
|
|
12
|
-
var args = [table];
|
|
12
|
+
var args = [context, table];
|
|
13
13
|
table._primaryColumns.forEach(function(primary) {
|
|
14
14
|
args.push(row[primary.alias]);
|
|
15
15
|
});
|
|
16
16
|
var filter = newPrimaryKeyFilter.apply(null, args);
|
|
17
|
-
var cmds = newDeleteCommand([], table, filter, strategy, relations);
|
|
17
|
+
var cmds = newDeleteCommand(context, [], table, filter, strategy, relations);
|
|
18
18
|
cmds.forEach(function(cmd) {
|
|
19
|
-
pushCommand(cmd);
|
|
19
|
+
pushCommand(context, cmd);
|
|
20
20
|
});
|
|
21
21
|
var cmd = cmds[0];
|
|
22
22
|
if (table._emitChanged.callbacks.length > 0) {
|
|
23
23
|
cmd.disallowCompress = true;
|
|
24
24
|
var dto = createDto(table, row);
|
|
25
25
|
let patch = createPatch([dto],[]);
|
|
26
|
-
cmd.emitChanged = table._emitChanged.bind(null, {row: row, patch: patch});
|
|
26
|
+
cmd.emitChanged = table._emitChanged.bind(null, {row: row, patch: patch}); //todo remove ?
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
let util = require('util');
|
|
2
1
|
let updateField = require('../updateField');
|
|
3
2
|
let newEmitEvent = require('../../emitEvent');
|
|
4
3
|
let extractStrategy = require('./toDto/extractStrategy');
|
|
@@ -51,7 +50,7 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
51
50
|
this._dbRow[key] = value;
|
|
52
51
|
if (column.validate)
|
|
53
52
|
column.validate(value, this._dbRow);
|
|
54
|
-
updateField(table, column, this);
|
|
53
|
+
updateField(this._context, table, column, this);
|
|
55
54
|
let emit = this._emitColumnChanged[name];
|
|
56
55
|
if (emit)
|
|
57
56
|
emit(this, column, value, oldValue);
|
|
@@ -114,8 +113,8 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
114
113
|
let get = row._related[alias];
|
|
115
114
|
if (!get) {
|
|
116
115
|
let relation = table._relations[alias];
|
|
117
|
-
get = relation.toGetRelated(row);
|
|
118
|
-
row._relationCacheMap.set(relation, relation.getInnerCache());
|
|
116
|
+
get = relation.toGetRelated(row._context, row);
|
|
117
|
+
row._relationCacheMap.set(relation, relation.getInnerCache(row._context));
|
|
119
118
|
row._related[alias] = get;
|
|
120
119
|
}
|
|
121
120
|
return get;
|
|
@@ -144,8 +143,8 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
144
143
|
};
|
|
145
144
|
|
|
146
145
|
|
|
147
|
-
Row.prototype.hydrate = function(dbRow) {
|
|
148
|
-
const engine = tryGetSessionContext()?.engine;
|
|
146
|
+
Row.prototype.hydrate = function(context, dbRow) {
|
|
147
|
+
const engine = tryGetSessionContext(context)?.engine;
|
|
149
148
|
let i = offset;
|
|
150
149
|
if (engine === 'sqlite') {
|
|
151
150
|
const errorSeparator = '12345678-1234-1234-1234-123456789012';
|
|
@@ -153,14 +152,14 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
153
152
|
if (typeof dbRow[p] === 'string' && dbRow[p].indexOf(errorSeparator) === 0)
|
|
154
153
|
throw new Error(dbRow[p].split(errorSeparator)[1]);
|
|
155
154
|
let key = keys[i];
|
|
156
|
-
this._dbRow[key] = columns[i].decode(dbRow[p]);
|
|
155
|
+
this._dbRow[key] = columns[i].decode(context, dbRow[p]);
|
|
157
156
|
i++;
|
|
158
157
|
}
|
|
159
158
|
}
|
|
160
159
|
else {
|
|
161
160
|
for (let p in dbRow) {
|
|
162
161
|
let key = keys[i];
|
|
163
|
-
this._dbRow[key] = columns[i].decode(dbRow[p]);
|
|
162
|
+
this._dbRow[key] = columns[i].decode(context, dbRow[p]);
|
|
164
163
|
i++;
|
|
165
164
|
}
|
|
166
165
|
}
|
|
@@ -171,10 +170,10 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
171
170
|
strategy = extractStrategy(table);
|
|
172
171
|
}
|
|
173
172
|
strategy = purifyStrategy(table, strategy);
|
|
174
|
-
if (!tryGetSessionContext()) {
|
|
175
|
-
return toDto(strategy, table, this, new Set());
|
|
173
|
+
if (!tryGetSessionContext(this._context)) {
|
|
174
|
+
return toDto(this._context, strategy, table, this, new Set());
|
|
176
175
|
}
|
|
177
|
-
let p = toDto(strategy, table, this);
|
|
176
|
+
let p = toDto(this._context, strategy, table, this);
|
|
178
177
|
return Promise.resolve().then(() => p);
|
|
179
178
|
};
|
|
180
179
|
|
|
@@ -189,37 +188,31 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
189
188
|
|
|
190
189
|
Row.prototype.delete = function(strategy) {
|
|
191
190
|
strategy = extractDeleteStrategy(strategy);
|
|
192
|
-
_delete(this, strategy, table);
|
|
191
|
+
_delete(this._context, this, strategy, table);
|
|
193
192
|
};
|
|
194
193
|
|
|
195
194
|
Row.prototype.cascadeDelete = function() {
|
|
196
195
|
let strategy = newCascadeDeleteStrategy(newObject(), table);
|
|
197
|
-
_delete(this, strategy, table);
|
|
196
|
+
_delete(this._context, this, strategy, table);
|
|
198
197
|
};
|
|
199
198
|
|
|
200
199
|
Row.prototype.deleteCascade = Row.prototype.cascadeDelete;
|
|
201
200
|
|
|
202
201
|
Row.prototype.patch = async function(patches, options) {
|
|
203
|
-
await patchRow(table, this, patches, options);
|
|
202
|
+
await patchRow(this._context, table, this, patches, options);
|
|
204
203
|
return this;
|
|
205
204
|
};
|
|
206
205
|
|
|
207
|
-
|
|
208
|
-
Row.prototype[util.inspect.custom] = function() {
|
|
209
|
-
let dtos = toDto(undefined, table, this, new Set());
|
|
210
|
-
return util.inspect(dtos, { compact: false, colors: true });
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
function decodeDbRow(row) {
|
|
206
|
+
function decodeDbRow(context, row) {
|
|
214
207
|
for (let i = 0; i < numberOfColumns; i++) {
|
|
215
208
|
let index = offset + i;
|
|
216
209
|
let key = keys[index];
|
|
217
210
|
if (row[key] !== undefined)
|
|
218
|
-
row[key] = columns[i].decode(row[key]);
|
|
211
|
+
row[key] = columns[i].decode(context, row[key]);
|
|
219
212
|
if (shouldValidate && columns[i].validate)
|
|
220
213
|
columns[i].validate(row[key], row, isInsert);
|
|
221
214
|
}
|
|
222
|
-
let target = new Row(row);
|
|
215
|
+
let target = new Row(context, row);
|
|
223
216
|
const p = new Proxy(target, {
|
|
224
217
|
ownKeys: function() {
|
|
225
218
|
return Array.from(aliases).concat(Object.keys(target._related).filter(alias => {
|
|
@@ -245,9 +238,10 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
245
238
|
return value;
|
|
246
239
|
}
|
|
247
240
|
|
|
248
|
-
function Row(dbRow) {
|
|
241
|
+
function Row(context, dbRow) {
|
|
242
|
+
this._context = context;
|
|
249
243
|
this._relationCacheMap = new Map();
|
|
250
|
-
this._cache = table._cache.getInnerCache();
|
|
244
|
+
this._cache = table._cache.getInnerCache(context);
|
|
251
245
|
this._dbRow = dbRow;
|
|
252
246
|
this._related = {};
|
|
253
247
|
this._emitColumnChanged = {};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
let extractSubStrategy = _extractSubStrategy;
|
|
2
|
-
|
|
3
1
|
//either..
|
|
4
2
|
//strategy, table
|
|
5
3
|
//or..
|
|
@@ -21,7 +19,7 @@ function extractStrategy(_strategyOrTable, _optinonalTable) {
|
|
|
21
19
|
visitor.visitJoin = function() { };
|
|
22
20
|
|
|
23
21
|
visitor.visitMany = function(relation) {
|
|
24
|
-
strategy[relationName] =
|
|
22
|
+
strategy[relationName] = extractStrategy(relation.childTable);
|
|
25
23
|
};
|
|
26
24
|
|
|
27
25
|
visitor.visitOne = visitor.visitMany;
|
|
@@ -33,9 +31,5 @@ function extractStrategy(_strategyOrTable, _optinonalTable) {
|
|
|
33
31
|
return strategy;
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
function _extractSubStrategy(table) {
|
|
37
|
-
extractSubStrategy = require('./extractStrategy');
|
|
38
|
-
return extractSubStrategy(table);
|
|
39
|
-
}
|
|
40
34
|
|
|
41
35
|
module.exports = extractStrategy;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
let flags = require('../../flags');
|
|
2
2
|
let tryGetSessionContext = require('../tryGetSessionContext');
|
|
3
3
|
|
|
4
|
-
function toDto(strategy, table, row, joinRelationSet) {
|
|
4
|
+
function toDto(context, strategy, table, row, joinRelationSet) {
|
|
5
5
|
let result;
|
|
6
6
|
flags.useProxy = false;
|
|
7
|
-
let
|
|
8
|
-
let ignoreSerializable =
|
|
7
|
+
let rdb = tryGetSessionContext(context);
|
|
8
|
+
let ignoreSerializable = rdb && rdb.ignoreSerializable;
|
|
9
9
|
if (joinRelationSet) {
|
|
10
10
|
result = toDtoSync(table, row, joinRelationSet, strategy, ignoreSerializable);
|
|
11
11
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var dbRowsToRows = require('./resultToRows/dbRowsToRows');
|
|
2
2
|
|
|
3
|
-
async function resultToRows(span,result) {
|
|
3
|
+
async function resultToRows(context, span, result) {
|
|
4
4
|
let rows = await result[0].then(onResult);
|
|
5
5
|
await expand(spanToStrategy(span), rows);
|
|
6
6
|
return rows;
|
|
7
7
|
|
|
8
8
|
function onResult(result) {
|
|
9
|
-
return dbRowsToRows(span,result);
|
|
9
|
+
return dbRowsToRows(context, span, result);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -15,7 +15,7 @@ async function expand(strategy, rows) {
|
|
|
15
15
|
return;
|
|
16
16
|
if (!Array.isArray(rows))
|
|
17
17
|
rows = [rows];
|
|
18
|
-
for(let p in strategy) {
|
|
18
|
+
for (let p in strategy) {
|
|
19
19
|
if (!(strategy[p] === null || strategy[p]))
|
|
20
20
|
continue;
|
|
21
21
|
for (let i = 0; i < rows.length; i++) {
|