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
|
@@ -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
|
}
|
|
@@ -4,8 +4,8 @@ let tryGetSessionContext = require('../tryGetSessionContext');
|
|
|
4
4
|
|
|
5
5
|
function newWhere(_relations, _depth) {
|
|
6
6
|
|
|
7
|
-
function where(fn) {
|
|
8
|
-
const includeMany = tryGetSessionContext()?.engine === 'mssql';
|
|
7
|
+
function where(context, fn) {
|
|
8
|
+
const includeMany = tryGetSessionContext(context)?.engine === 'mssql';
|
|
9
9
|
let { relations, alias } = extract(includeMany, _relations);
|
|
10
10
|
const table = relations[relations.length - 1].childTable;
|
|
11
11
|
if (!relations[0].isMany || includeMany)
|
|
@@ -13,7 +13,7 @@ function newWhere(_relations, _depth) {
|
|
|
13
13
|
|
|
14
14
|
try {
|
|
15
15
|
let arg = typeof fn === 'function' ? fn(table) : fn;
|
|
16
|
-
let anyFilter = negotiateRawSqlFilter(arg);
|
|
16
|
+
let anyFilter = negotiateRawSqlFilter(context, arg);
|
|
17
17
|
delete table._rootAlias;
|
|
18
18
|
return anyFilter;
|
|
19
19
|
}
|
|
@@ -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
|
}
|
|
@@ -11,41 +11,41 @@ function newManyCache(joinRelation) {
|
|
|
11
11
|
var c = {};
|
|
12
12
|
var key = newId();
|
|
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
|
-
var cache = getSessionSingleton(key);
|
|
27
|
+
c.getInnerCache = function(context) {
|
|
28
|
+
var cache = getSessionSingleton(context, key);
|
|
29
29
|
if (!cache) {
|
|
30
30
|
cache = newCacheCore(joinRelation);
|
|
31
|
-
setSessionSingleton(key, cache);
|
|
32
|
-
fillCache();
|
|
33
|
-
synchronizeAdded(c.tryAdd, joinRelation);
|
|
34
|
-
synchronizeRemoved(c.tryRemove, joinRelation);
|
|
31
|
+
setSessionSingleton(context, key, cache);
|
|
32
|
+
fillCache(context);
|
|
33
|
+
synchronizeAdded(context, c.tryAdd.bind(null, context), joinRelation);
|
|
34
|
+
synchronizeRemoved(context, c.tryRemove.bind(null, context), joinRelation);
|
|
35
35
|
}
|
|
36
36
|
return cache;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
function fillCache() {
|
|
40
|
+
function fillCache(context) {
|
|
41
41
|
var childTable = joinRelation.parentTable;
|
|
42
42
|
var childCache = childTable._cache;
|
|
43
|
-
var children = childCache.getAll();
|
|
43
|
+
var children = childCache.getAll(context);
|
|
44
44
|
children.forEach(addToCache);
|
|
45
45
|
|
|
46
46
|
function addToCache(child) {
|
|
47
47
|
var parent = extractParentKey(joinRelation, child);
|
|
48
|
-
c.tryAdd(parent, child);
|
|
48
|
+
c.tryAdd(context, parent, child);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -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)
|
|
@@ -3,11 +3,11 @@ var decodeDbRow = require('./decodeDbRow');
|
|
|
3
3
|
var nextDbRowToRow = _nextDbRowToRow;
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
function dbRowToRow(span, dbRow) {
|
|
6
|
+
function dbRowToRow(context, span, dbRow) {
|
|
7
7
|
var table = span.table;
|
|
8
|
-
var row = decodeDbRow(span, table, dbRow);
|
|
8
|
+
var row = decodeDbRow(context, span, table, dbRow);
|
|
9
9
|
var cache = table._cache;
|
|
10
|
-
if (!cache.tryGet(row)) {
|
|
10
|
+
if (!cache.tryGet(context, row)) {
|
|
11
11
|
var queryContext = span.queryContext;
|
|
12
12
|
negotiateQueryContext(queryContext, row);
|
|
13
13
|
Object.defineProperty(row, 'queryContext', {
|
|
@@ -17,17 +17,17 @@ function dbRowToRow(span, dbRow) {
|
|
|
17
17
|
});
|
|
18
18
|
row.queryContext = queryContext;
|
|
19
19
|
}
|
|
20
|
-
row = cache.tryAdd(row);
|
|
20
|
+
row = cache.tryAdd(context, row);
|
|
21
21
|
|
|
22
22
|
var c = {};
|
|
23
23
|
|
|
24
24
|
c.visitOne = function(leg) {
|
|
25
|
-
nextDbRowToRow(leg.span, dbRow);
|
|
25
|
+
nextDbRowToRow(context, leg.span, dbRow);
|
|
26
26
|
leg.expand(row);
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
c.visitJoin = function(leg) {
|
|
30
|
-
nextDbRowToRow(leg.span, dbRow);
|
|
30
|
+
nextDbRowToRow(context, leg.span, dbRow);
|
|
31
31
|
leg.expand(row);
|
|
32
32
|
};
|
|
33
33
|
|
|
@@ -43,9 +43,9 @@ function dbRowToRow(span, dbRow) {
|
|
|
43
43
|
return row;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function _nextDbRowToRow(span, dbRow) {
|
|
46
|
+
function _nextDbRowToRow(context, span, dbRow) {
|
|
47
47
|
nextDbRowToRow = require('./dbRowToRow');
|
|
48
|
-
nextDbRowToRow(span, dbRow);
|
|
48
|
+
nextDbRowToRow(context, span, dbRow);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
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,6 @@
|
|
|
1
1
|
var nextRemoveFromCache = _nextRemoveFromCache;
|
|
2
2
|
|
|
3
|
-
function removeFromCache(row, strategy, table) {
|
|
3
|
+
function removeFromCache(context, row, strategy, table) {
|
|
4
4
|
if (Array.isArray(row)) {
|
|
5
5
|
removeManyRows();
|
|
6
6
|
return;
|
|
@@ -10,7 +10,7 @@ function removeFromCache(row, strategy, table) {
|
|
|
10
10
|
|
|
11
11
|
function removeManyRows() {
|
|
12
12
|
row.forEach( function(rowToRemove) {
|
|
13
|
-
nextRemoveFromCache(rowToRemove, strategy, table);
|
|
13
|
+
nextRemoveFromCache(context, rowToRemove, strategy, table);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -19,15 +19,15 @@ function removeFromCache(row, strategy, table) {
|
|
|
19
19
|
for (var relationName in strategy) {
|
|
20
20
|
var relation = relations[relationName];
|
|
21
21
|
var rows = relation.getRowsSync(row);
|
|
22
|
-
nextRemoveFromCache(rows, strategy[relationName], relation.childTable);
|
|
22
|
+
nextRemoveFromCache(context, rows, strategy[relationName], relation.childTable);
|
|
23
23
|
}
|
|
24
|
-
table._cache.tryRemove(row);
|
|
24
|
+
table._cache.tryRemove(context, row);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function _nextRemoveFromCache(row, strategy, table) {
|
|
28
|
+
function _nextRemoveFromCache(context, row, strategy, table) {
|
|
29
29
|
nextRemoveFromCache = require('./removeFromCache');
|
|
30
|
-
nextRemoveFromCache(row, strategy, table);
|
|
30
|
+
nextRemoveFromCache(context, row, strategy, table);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
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
|
}
|
|
@@ -51,7 +51,7 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
51
51
|
this._dbRow[key] = value;
|
|
52
52
|
if (column.validate)
|
|
53
53
|
column.validate(value, this._dbRow);
|
|
54
|
-
updateField(table, column, this);
|
|
54
|
+
updateField(this._context, table, column, this);
|
|
55
55
|
let emit = this._emitColumnChanged[name];
|
|
56
56
|
if (emit)
|
|
57
57
|
emit(this, column, value, oldValue);
|
|
@@ -114,8 +114,8 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
114
114
|
let get = row._related[alias];
|
|
115
115
|
if (!get) {
|
|
116
116
|
let relation = table._relations[alias];
|
|
117
|
-
get = relation.toGetRelated(row);
|
|
118
|
-
row._relationCacheMap.set(relation, relation.getInnerCache());
|
|
117
|
+
get = relation.toGetRelated(row._context, row);
|
|
118
|
+
row._relationCacheMap.set(relation, relation.getInnerCache(row._context));
|
|
119
119
|
row._related[alias] = get;
|
|
120
120
|
}
|
|
121
121
|
return get;
|
|
@@ -144,8 +144,8 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
144
144
|
};
|
|
145
145
|
|
|
146
146
|
|
|
147
|
-
Row.prototype.hydrate = function(dbRow) {
|
|
148
|
-
const engine = tryGetSessionContext()?.engine;
|
|
147
|
+
Row.prototype.hydrate = function(context, dbRow) {
|
|
148
|
+
const engine = tryGetSessionContext(context)?.engine;
|
|
149
149
|
let i = offset;
|
|
150
150
|
if (engine === 'sqlite') {
|
|
151
151
|
const errorSeparator = '12345678-1234-1234-1234-123456789012';
|
|
@@ -153,14 +153,14 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
153
153
|
if (typeof dbRow[p] === 'string' && dbRow[p].indexOf(errorSeparator) === 0)
|
|
154
154
|
throw new Error(dbRow[p].split(errorSeparator)[1]);
|
|
155
155
|
let key = keys[i];
|
|
156
|
-
this._dbRow[key] = columns[i].decode(dbRow[p]);
|
|
156
|
+
this._dbRow[key] = columns[i].decode(context, dbRow[p]);
|
|
157
157
|
i++;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
else {
|
|
161
161
|
for (let p in dbRow) {
|
|
162
162
|
let key = keys[i];
|
|
163
|
-
this._dbRow[key] = columns[i].decode(dbRow[p]);
|
|
163
|
+
this._dbRow[key] = columns[i].decode(context, dbRow[p]);
|
|
164
164
|
i++;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
@@ -171,10 +171,10 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
171
171
|
strategy = extractStrategy(table);
|
|
172
172
|
}
|
|
173
173
|
strategy = purifyStrategy(table, strategy);
|
|
174
|
-
if (!tryGetSessionContext()) {
|
|
175
|
-
return toDto(strategy, table, this, new Set());
|
|
174
|
+
if (!tryGetSessionContext(this._context)) {
|
|
175
|
+
return toDto(this._context, strategy, table, this, new Set());
|
|
176
176
|
}
|
|
177
|
-
let p = toDto(strategy, table, this);
|
|
177
|
+
let p = toDto(this._context, strategy, table, this);
|
|
178
178
|
return Promise.resolve().then(() => p);
|
|
179
179
|
};
|
|
180
180
|
|
|
@@ -189,18 +189,18 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
189
189
|
|
|
190
190
|
Row.prototype.delete = function(strategy) {
|
|
191
191
|
strategy = extractDeleteStrategy(strategy);
|
|
192
|
-
_delete(this, strategy, table);
|
|
192
|
+
_delete(this._context, this, strategy, table);
|
|
193
193
|
};
|
|
194
194
|
|
|
195
195
|
Row.prototype.cascadeDelete = function() {
|
|
196
196
|
let strategy = newCascadeDeleteStrategy(newObject(), table);
|
|
197
|
-
_delete(this, strategy, table);
|
|
197
|
+
_delete(this._context, this, strategy, table);
|
|
198
198
|
};
|
|
199
199
|
|
|
200
200
|
Row.prototype.deleteCascade = Row.prototype.cascadeDelete;
|
|
201
201
|
|
|
202
202
|
Row.prototype.patch = async function(patches, options) {
|
|
203
|
-
await patchRow(table, this, patches, options);
|
|
203
|
+
await patchRow(this._context, table, this, patches, options);
|
|
204
204
|
return this;
|
|
205
205
|
};
|
|
206
206
|
|
|
@@ -210,16 +210,16 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
210
210
|
return util.inspect(dtos, { compact: false, colors: true });
|
|
211
211
|
};
|
|
212
212
|
|
|
213
|
-
function decodeDbRow(row) {
|
|
213
|
+
function decodeDbRow(context, row) {
|
|
214
214
|
for (let i = 0; i < numberOfColumns; i++) {
|
|
215
215
|
let index = offset + i;
|
|
216
216
|
let key = keys[index];
|
|
217
217
|
if (row[key] !== undefined)
|
|
218
|
-
row[key] = columns[i].decode(row[key]);
|
|
218
|
+
row[key] = columns[i].decode(context, row[key]);
|
|
219
219
|
if (shouldValidate && columns[i].validate)
|
|
220
220
|
columns[i].validate(row[key], row, isInsert);
|
|
221
221
|
}
|
|
222
|
-
let target = new Row(row);
|
|
222
|
+
let target = new Row(context, row);
|
|
223
223
|
const p = new Proxy(target, {
|
|
224
224
|
ownKeys: function() {
|
|
225
225
|
return Array.from(aliases).concat(Object.keys(target._related).filter(alias => {
|
|
@@ -245,9 +245,10 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
245
245
|
return value;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
function Row(dbRow) {
|
|
248
|
+
function Row(context, dbRow) {
|
|
249
|
+
this._context = context;
|
|
249
250
|
this._relationCacheMap = new Map();
|
|
250
|
-
this._cache = table._cache.getInnerCache();
|
|
251
|
+
this._cache = table._cache.getInnerCache(context);
|
|
251
252
|
this._dbRow = dbRow;
|
|
252
253
|
this._related = {};
|
|
253
254
|
this._emitColumnChanged = {};
|
|
@@ -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++) {
|
package/src/table/rollback.js
CHANGED
|
@@ -5,27 +5,37 @@ const popChanges = require('./popChanges');
|
|
|
5
5
|
const newThrow = require('./newThrow');
|
|
6
6
|
const resultToPromise = require('./resultToPromise');
|
|
7
7
|
const conflictId = '12345678-1234-1234-1234-123456789012';
|
|
8
|
+
const getSessionSingleton = require('./getSessionSingleton');
|
|
8
9
|
|
|
9
|
-
function
|
|
10
|
-
var executeRollback = executeQuery.bind(null, rollbackCommand);
|
|
10
|
+
function _rollback(context, e) {
|
|
11
11
|
var chain = resultToPromise()
|
|
12
|
-
.then(popChanges)
|
|
12
|
+
.then(() => popChanges(context))
|
|
13
13
|
.then(executeRollback)
|
|
14
|
-
.then(releaseDbClient);
|
|
14
|
+
.then(() => releaseDbClient(context));
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
function executeRollback() {
|
|
18
|
+
const transactionLess = getSessionSingleton(context, 'transactionLess');
|
|
19
|
+
if (transactionLess)
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
return executeQuery(context, rollbackCommand);
|
|
22
|
+
}
|
|
15
23
|
|
|
16
24
|
if (e) {
|
|
17
|
-
if (e.message
|
|
18
|
-
return newThrow(new Error('Conflict when updating a column'), chain);
|
|
25
|
+
if (e.message?.indexOf('ORA-01476: divisor is equal to zero') > -1)
|
|
26
|
+
return newThrow(context, new Error('Conflict when updating a column'), chain);
|
|
19
27
|
let errors = e.message && e.message.split(conflictId) || [];
|
|
20
28
|
if (errors.length > 1) {
|
|
21
|
-
return newThrow(new Error(errors[1]), chain);
|
|
29
|
+
return newThrow(context, new Error(errors[1]), chain);
|
|
22
30
|
}
|
|
23
31
|
else
|
|
24
|
-
return newThrow(e, chain);
|
|
32
|
+
return newThrow(context, e, chain);
|
|
25
33
|
}
|
|
26
34
|
return chain;
|
|
27
35
|
}
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
return Promise.resolve().then(() =>
|
|
31
|
-
}
|
|
37
|
+
function rollback(context, e) {
|
|
38
|
+
return Promise.resolve().then(() => _rollback(context, e));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = rollback;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
var getSessionContext = require('./getSessionContext');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
getSessionContext()
|
|
5
|
-
|
|
3
|
+
function setSessionSingleton(context, name, value) {
|
|
4
|
+
const rdb = getSessionContext(context);
|
|
5
|
+
rdb[name] = value;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
module.exports = setSessionSingleton;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var getMany = require('./getMany');
|
|
2
2
|
|
|
3
|
-
function tryGet(table, filter, strategy) {
|
|
3
|
+
function tryGet(context, table, filter, strategy) {
|
|
4
4
|
strategy = setLimit(strategy);
|
|
5
|
-
return getMany(table, filter, strategy).then(filterRows);
|
|
5
|
+
return getMany(context, table, filter, strategy).then(filterRows);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
function filterRows(rows) {
|
|
@@ -11,9 +11,9 @@ function filterRows(rows) {
|
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
tryGet.exclusive = function(table, filter, strategy) {
|
|
14
|
+
tryGet.exclusive = function(context, table, filter, strategy) {
|
|
15
15
|
strategy = setLimit(strategy);
|
|
16
|
-
return getMany.exclusive(table, filter, strategy).then(filterRows);
|
|
16
|
+
return getMany.exclusive(context, table, filter, strategy).then(filterRows);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
function setLimit(strategy) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function tryGet(table) {
|
|
1
|
+
function tryGet(context, table) {
|
|
2
2
|
var fakeRow = {};
|
|
3
3
|
var args = arguments;
|
|
4
4
|
table._primaryColumns.forEach(addPkValue);
|
|
5
5
|
|
|
6
6
|
function addPkValue(pkColumn, index){
|
|
7
|
-
fakeRow[pkColumn.alias] = args[index +
|
|
7
|
+
fakeRow[pkColumn.alias] = args[index + 2];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
return table._cache.tryGet(fakeRow);
|
|
10
|
+
return table._cache.tryGet(context, fakeRow);
|
|
11
11
|
}
|
|
12
12
|
module.exports = tryGet;
|