orange-orm 4.4.2 → 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.
Files changed (266) hide show
  1. package/README.md +1 -1
  2. package/package.json +12 -6
  3. package/src/client/clientMap.js +2 -0
  4. package/src/client/createProviders.js +12 -0
  5. package/src/client/index.js +6 -3
  6. package/src/client/index.mjs +8 -3
  7. package/src/client/map.js +1 -0
  8. package/src/createDomain.js +11 -16
  9. package/src/d1/newDatabase.js +119 -0
  10. package/src/d1/newPool.js +19 -0
  11. package/src/d1/newTransaction.js +82 -0
  12. package/src/d1/pool/end.js +13 -0
  13. package/src/d1/pool/newGenericPool.js +53 -0
  14. package/src/d1/wrapQuery.js +22 -0
  15. package/src/d1test.js +35 -0
  16. package/src/emitEvent.js +6 -4
  17. package/src/emptyFilter.js +12 -12
  18. package/src/getManyDto/newQuery.js +5 -5
  19. package/src/getManyDto/query/newSingleQuery.js +5 -5
  20. package/src/getManyDto.js +25 -24
  21. package/src/hostExpress/cycle.ts +211 -0
  22. package/src/hostExpress/executePath.js +360 -357
  23. package/src/hostLocal.js +8 -8
  24. package/src/index.d.ts +2 -0
  25. package/src/index.js +19 -15
  26. package/src/map.d.ts +3 -0
  27. package/src/mssql/newDatabase.js +19 -31
  28. package/src/mssql/newPool.js +2 -2
  29. package/src/mssql/newTransaction.js +5 -4
  30. package/src/mssql/pool/newGenericPool.js +1 -1
  31. package/src/mySql/deleteFromSql.js +1 -1
  32. package/src/mySql/insert.js +5 -5
  33. package/src/mySql/insertSql.js +2 -3
  34. package/src/mySql/lastInsertedSql.js +3 -4
  35. package/src/mySql/newDatabase.js +20 -34
  36. package/src/mySql/newPool.js +10 -10
  37. package/src/mySql/newTransaction.js +3 -3
  38. package/src/mySql/pool/newGenericPool.js +2 -3
  39. package/src/mySql/quote.js +1 -0
  40. package/src/newImmutable.js +1 -2
  41. package/src/oracle/deleteFromSql.js +1 -1
  42. package/src/oracle/formatDateOut.js +1 -1
  43. package/src/oracle/insert.js +6 -6
  44. package/src/oracle/insertSql.js +6 -14
  45. package/src/oracle/lastInsertedSql.js +3 -3
  46. package/src/oracle/mergeSql.js +3 -6
  47. package/src/oracle/newDatabase.js +18 -33
  48. package/src/oracle/newInsertCommandCore.js +3 -3
  49. package/src/oracle/newPool.js +10 -10
  50. package/src/oracle/newTransaction.js +3 -2
  51. package/src/oracle/pool/newGenericPool.js +2 -2
  52. package/src/oracle/quote.js +1 -0
  53. package/src/oracle/wrapQuery.js +0 -3
  54. package/src/patchRow.js +2 -2
  55. package/src/patchTable.js +6 -5
  56. package/src/pg/deleteFromSql.js +1 -1
  57. package/src/pg/formatDateOut.js +1 -2
  58. package/src/pg/insert.js +3 -3
  59. package/src/pg/insertSql.js +2 -7
  60. package/src/pg/lastInsertedSql.js +1 -2
  61. package/src/pg/newDatabase.js +20 -37
  62. package/src/pg/newPool.js +10 -10
  63. package/src/pg/newTransaction.js +3 -2
  64. package/src/pg/pool/newPgPool.js +2 -2
  65. package/src/pg/quote.js +2 -0
  66. package/src/pg/schema.js +2 -2
  67. package/src/{mySql/pool/defaults.js → poolDefaults.js} +0 -2
  68. package/src/query.js +2 -2
  69. package/src/sap/deleteFromSql.js +1 -1
  70. package/src/sap/formatDateOut.js +1 -1
  71. package/src/sap/insert.js +5 -5
  72. package/src/sap/insertSql.js +4 -5
  73. package/src/sap/lastInsertedSql.js +3 -3
  74. package/src/sap/mergeSql.js +1 -2
  75. package/src/sap/newDatabase.js +23 -34
  76. package/src/sap/newPool.js +2 -2
  77. package/src/sap/newTransaction.js +3 -2
  78. package/src/sap/quote.js +1 -0
  79. package/src/sqlite/deleteFromSql.js +1 -1
  80. package/src/sqlite/insert.js +5 -5
  81. package/src/sqlite/insertSql.js +2 -2
  82. package/src/sqlite/lastInsertedSql.js +2 -2
  83. package/src/sqlite/newDatabase.js +16 -32
  84. package/src/sqlite/newPool.js +10 -10
  85. package/src/sqlite/newTransaction.js +3 -2
  86. package/src/sqlite/pool/newGenericPool.js +2 -1
  87. package/src/sqlite/quote.js +1 -0
  88. package/src/table/aggregate.js +1 -1
  89. package/src/table/begin.js +5 -5
  90. package/src/table/cascadeDelete.js +2 -2
  91. package/src/table/column/binary/newDecode.js +2 -2
  92. package/src/table/column/binary/newEncode.js +3 -4
  93. package/src/table/column/boolean/newDecode.js +1 -1
  94. package/src/table/column/boolean/newEncode.js +6 -6
  95. package/src/table/column/date/formatOut.js +3 -5
  96. package/src/table/column/date/newDecode.js +2 -2
  97. package/src/table/column/date/newEncode.js +8 -8
  98. package/src/table/column/date.js +1 -1
  99. package/src/table/column/dateWithTimeZone/newEncode.js +3 -4
  100. package/src/table/column/dateWithTimeZone.js +1 -1
  101. package/src/table/column/encodeFilterArg.js +3 -3
  102. package/src/table/column/equal.js +3 -3
  103. package/src/table/column/extractAlias.js +0 -2
  104. package/src/table/column/greaterThan.js +3 -3
  105. package/src/table/column/greaterThanOrEqual.js +3 -3
  106. package/src/table/column/guid/newDecode.js +1 -1
  107. package/src/table/column/guid/newEncode.js +3 -3
  108. package/src/table/column/in.js +3 -3
  109. package/src/table/column/json/formatOut.js +3 -3
  110. package/src/table/column/json/newDecode.js +3 -3
  111. package/src/table/column/json/newEncode.js +6 -6
  112. package/src/table/column/json.js +2 -1
  113. package/src/table/column/lessThan.js +3 -3
  114. package/src/table/column/lessThanOrEqual.js +4 -4
  115. package/src/table/column/negotiateRawSqlFilter.js +9 -9
  116. package/src/table/column/newBoolean.js +9 -9
  117. package/src/table/column/newColumn.js +21 -21
  118. package/src/table/column/newDecodeCore.js +1 -1
  119. package/src/table/column/notEqual.js +3 -3
  120. package/src/table/column/numeric/newDecode.js +2 -2
  121. package/src/table/column/numeric/newEncode.js +3 -3
  122. package/src/table/column/string/contains.js +2 -1
  123. package/src/table/column/string/containsCore.js +5 -5
  124. package/src/table/column/string/endsWith.js +1 -1
  125. package/src/table/column/string/endsWithCore.js +4 -4
  126. package/src/table/column/string/iContains.js +2 -1
  127. package/src/table/column/string/iEndsWith.js +1 -1
  128. package/src/table/column/string/iEqual.js +3 -3
  129. package/src/table/column/string/iStartsWith.js +1 -1
  130. package/src/table/column/string/newEncode.js +3 -3
  131. package/src/table/column/string/startsWith.js +1 -1
  132. package/src/table/column/string/startsWithCore.js +4 -4
  133. package/src/table/column/string.js +14 -14
  134. package/src/table/commands/beginCommand.js +2 -2
  135. package/src/table/commands/compressChanges.js +2 -2
  136. package/src/table/commands/delete/newSingleCommand.js +5 -5
  137. package/src/table/commands/delete/singleCommand/joinSql.js +12 -12
  138. package/src/table/commands/delete/singleCommand/newSingleCommandCore.js +2 -2
  139. package/src/table/commands/delete/singleCommand/selectSql.js +6 -6
  140. package/src/table/commands/delete/singleCommand/subFilter.js +11 -11
  141. package/src/table/commands/delete/singleCommand/whereSql.js +2 -2
  142. package/src/table/commands/getChangeSet.js +2 -2
  143. package/src/table/commands/insert/getSqlTemplate.js +16 -16
  144. package/src/table/commands/lastCommandMatches.js +2 -2
  145. package/src/table/commands/newDeleteCommand.js +5 -5
  146. package/src/table/commands/newGetLastInsertedCommand.js +4 -4
  147. package/src/table/commands/newGetLastInsertedCommandCore.js +5 -5
  148. package/src/table/commands/newInsertCommand.js +0 -1
  149. package/src/table/commands/newInsertCommandCore.js +3 -3
  150. package/src/table/commands/newRow.js +4 -4
  151. package/src/table/commands/newUpdateCommand.js +4 -4
  152. package/src/table/commands/newUpdateCommandCore.js +4 -4
  153. package/src/table/commands/pushCommand.js +2 -2
  154. package/src/table/commit.js +13 -11
  155. package/src/table/count.js +8 -8
  156. package/src/table/delete.js +4 -4
  157. package/src/table/deleteSessionContext.js +4 -13
  158. package/src/table/executeQueries/executeChanges.js +3 -3
  159. package/src/table/executeQueries/executeQueriesCore.js +2 -2
  160. package/src/table/executeQueries/executeQuery.js +2 -2
  161. package/src/table/executeQueries/resolveExecuteQuery.js +4 -4
  162. package/src/table/executeQueries.js +4 -4
  163. package/src/table/getFromDbById.js +1 -1
  164. package/src/table/getMany.js +7 -7
  165. package/src/table/getManyDto.js +3 -4
  166. package/src/table/getSessionContext.js +4 -4
  167. package/src/table/getSessionSingleton.js +3 -2
  168. package/src/table/groupBy/newQuery.js +4 -4
  169. package/src/table/groupBy.js +9 -9
  170. package/src/table/insert.js +10 -13
  171. package/src/table/joinRelation/getRelatives.js +6 -6
  172. package/src/table/newGetRelated.js +3 -3
  173. package/src/table/newManyRelation.js +9 -9
  174. package/src/table/newOneRelation.js +9 -9
  175. package/src/table/newPrimaryKeyFilter.js +6 -6
  176. package/src/table/newQuery.js +5 -5
  177. package/src/table/newRelatedTable.js +2 -2
  178. package/src/table/newRowCache.js +17 -17
  179. package/src/table/newThrow.js +2 -2
  180. package/src/table/oneRelation/getRelatives.js +5 -5
  181. package/src/table/popChanges.js +3 -3
  182. package/src/table/promise.js +2 -8
  183. package/src/table/query/extractLimit.js +2 -2
  184. package/src/table/query/extractOffset.js +2 -2
  185. package/src/table/query/extractOrderBy.js +2 -2
  186. package/src/table/query/newSingleQuery.js +7 -7
  187. package/src/table/query/singleQuery/columnSql/joinLegToColumnSql.js +5 -5
  188. package/src/table/query/singleQuery/columnSql/newJoinedColumnSql.js +2 -2
  189. package/src/table/query/singleQuery/columnSql/newShallowColumnSql.js +4 -4
  190. package/src/table/query/singleQuery/joinSql/joinLegToJoinSql.js +2 -2
  191. package/src/table/query/singleQuery/joinSql/joinLegToShallowJoinSql.js +2 -2
  192. package/src/table/query/singleQuery/joinSql/newDiscriminatorSql.js +2 -2
  193. package/src/table/query/singleQuery/joinSql/newShallowJoinSql.js +5 -5
  194. package/src/table/query/singleQuery/joinSql/newShallowJoinSqlCore.js +6 -5
  195. package/src/table/query/singleQuery/joinSql/oneLegToJoinSql.js +2 -2
  196. package/src/table/query/singleQuery/joinSql/oneLegToShallowJoinSql.js +2 -2
  197. package/src/table/query/singleQuery/negotiateExclusive.js +2 -2
  198. package/src/table/query/singleQuery/newColumnSql.js +3 -3
  199. package/src/table/query/singleQuery/newDiscriminatorSql.js +2 -2
  200. package/src/table/query/singleQuery/newJoinSql.js +6 -6
  201. package/src/table/query/singleQuery/newWhereSql.js +3 -3
  202. package/src/table/quote.js +4 -4
  203. package/src/table/relatedTable/aggregate.js +2 -2
  204. package/src/table/relatedTable/all.js +5 -5
  205. package/src/table/relatedTable/any.js +3 -3
  206. package/src/table/relatedTable/childColumn.js +12 -12
  207. package/src/table/relatedTable/columnAggregate.js +3 -3
  208. package/src/table/relatedTable/columnAggregateGroup.js +11 -11
  209. package/src/table/relatedTable/joinSql.js +5 -5
  210. package/src/table/relatedTable/joinSqlArray.js +3 -3
  211. package/src/table/relatedTable/none.js +3 -3
  212. package/src/table/relatedTable/relatedColumn.js +13 -13
  213. package/src/table/relatedTable/selectSql.js +2 -2
  214. package/src/table/relatedTable/subFilter.js +4 -4
  215. package/src/table/relatedTable/where.js +3 -3
  216. package/src/table/relatedTable/whereSql.js +2 -2
  217. package/src/table/relation/manyCache/synchronizeAdded.js +2 -2
  218. package/src/table/relation/manyCache/synchronizeChanged.js +3 -3
  219. package/src/table/relation/manyCache/synchronizeRemoved.js +2 -2
  220. package/src/table/relation/newForeignKeyFilter.js +2 -2
  221. package/src/table/relation/newManyCache.js +16 -16
  222. package/src/table/relation/newOneCache.js +6 -6
  223. package/src/table/releaseDbClient.js +4 -4
  224. package/src/table/resultToPromise.js +1 -3
  225. package/src/table/resultToRows/dbRowToRow.js +8 -8
  226. package/src/table/resultToRows/dbRowsToRows.js +2 -2
  227. package/src/table/resultToRows/decodeDbRow.js +2 -2
  228. package/src/table/resultToRows/delete/removeFromCache.js +6 -6
  229. package/src/table/resultToRows/delete.js +6 -6
  230. package/src/table/resultToRows/newDecodeDbRow.js +19 -18
  231. package/src/table/resultToRows/toDto.js +3 -3
  232. package/src/table/resultToRows.js +3 -3
  233. package/src/table/rollback.js +21 -11
  234. package/src/table/rowArray/negotiateNextTick.js +1 -2
  235. package/src/table/setSessionSingleton.js +6 -3
  236. package/src/table/tryGetFirstFromDb.js +4 -4
  237. package/src/table/tryGetFromCacheById.js +3 -3
  238. package/src/table/tryGetFromDbById/extractStrategy.js +2 -2
  239. package/src/table/tryGetFromDbById.js +8 -6
  240. package/src/table/tryGetSessionContext.js +5 -10
  241. package/src/table/tryReleaseDbClient.js +2 -2
  242. package/src/table/updateField.js +4 -4
  243. package/src/table/where.js +2 -2
  244. package/src/table.js +58 -51
  245. package/src/tedious/deleteFromSql.js +1 -1
  246. package/src/tedious/formatDateOut.js +1 -1
  247. package/src/tedious/getManyDto/newQueryCore.js +5 -5
  248. package/src/tedious/getManyDto/query/newSingleQuery.js +5 -5
  249. package/src/tedious/getManyDto/query/newSubQueries/joinLegToQuery.js +3 -3
  250. package/src/tedious/getManyDto/query/newSubQueries/manyLegToQuery.js +3 -3
  251. package/src/tedious/getManyDto/query/newSubQueries/oneLegToQuery.js +4 -4
  252. package/src/tedious/getManyDto/query/newSubQueries.js +8 -8
  253. package/src/tedious/getManyDto/query/singleQuery/newShallowColumnSql.js +5 -6
  254. package/src/tedious/getManyDto.js +6 -6
  255. package/src/tedious/insert.js +3 -3
  256. package/src/tedious/insertSql.js +3 -3
  257. package/src/tedious/newDatabase.js +17 -30
  258. package/src/tedious/newPool.js +10 -10
  259. package/src/tedious/newTransaction.js +4 -5
  260. package/src/tedious/pool/newGenericPool.js +1 -1
  261. package/src/tedious/quote.js +1 -0
  262. package/src/mssql/pool/defaults.js +0 -45
  263. package/src/oracle/pool/defaults.js +0 -45
  264. package/src/pg/pool/defaults.js +0 -45
  265. package/src/sqlite/pool/defaults.js +0 -45
  266. 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)
@@ -1,8 +1,6 @@
1
1
 
2
- var deferred = require('deferred');
3
-
4
2
  function resultToPromise(result) {
5
- return deferred.resolve(result);
3
+ return Promise.resolve(result);
6
4
  }
7
5
 
8
6
  module.exports = resultToPromise;
@@ -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 context = tryGetSessionContext();
8
- let ignoreSerializable = context && context.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++) {
@@ -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 rollback(e) {
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.indexOf('ORA-01476: divisor is equal to zero') > -1)
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
- module.exports = function(e) {
30
- return Promise.resolve().then(() => rollback(e));
31
- };
37
+ function rollback(context, e) {
38
+ return Promise.resolve().then(() => _rollback(context, e));
39
+ }
40
+
41
+ module.exports = rollback;
@@ -1,10 +1,9 @@
1
- var promise = require('promise/domains');
2
1
 
3
2
  function negotiateNextTick(i) {
4
3
  if (i === 0)
5
4
  return;
6
5
  if (i % 1000 === 0)
7
- return promise.resolve();
6
+ return Promise.resolve();
8
7
  return;
9
8
  }
10
9
 
@@ -1,5 +1,8 @@
1
1
  var getSessionContext = require('./getSessionContext');
2
2
 
3
- module.exports = function(name, value) {
4
- getSessionContext()[name] = value;
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 + 1];
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;