orange-orm 4.5.1-beta.3 → 4.5.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.
Files changed (74) hide show
  1. package/README.md +11 -11
  2. package/docs/changelog.md +6 -0
  3. package/package.json +4 -15
  4. package/{dist/index.browser.mjs → src/client/index.mjs} +259 -145
  5. package/src/client/merge.js +9 -0
  6. package/src/{rollup.config.browser.js → client/rollup.config.js} +1 -1
  7. package/src/d1/newTransaction.js +1 -0
  8. package/src/index.js +3 -16
  9. package/src/map.d.ts +2 -12
  10. package/src/mssql/newTransaction.js +1 -0
  11. package/src/mssql/pool/newGenericPool.js +2 -9
  12. package/src/mySql/newTransaction.js +1 -0
  13. package/src/mySql/pool/newGenericPool.js +2 -11
  14. package/src/oracle/newTransaction.js +1 -0
  15. package/src/oracle/pool/newGenericPool.js +5 -13
  16. package/src/patchTable.js +4 -1
  17. package/src/pg/newDatabase.js +5 -0
  18. package/src/pg/newTransaction.js +1 -0
  19. package/src/pg/pool/newPgPool.js +3 -15
  20. package/src/sap/newTransaction.js +1 -0
  21. package/src/sqlite/newTransaction.js +1 -0
  22. package/src/{sqlite3 → sqlite}/pool/newGenericPool.js +2 -10
  23. package/src/table/clearCache.js +7 -0
  24. package/src/table/column/binary/newDecode.js +2 -13
  25. package/src/table/column/binary/newEncode.js +6 -16
  26. package/src/table/column/columnAggregate.js +15 -0
  27. package/src/table/column/columnAggregateGroup.js +35 -0
  28. package/src/table/column/newColumn.js +13 -0
  29. package/src/table/getSessionCache.js +8 -0
  30. package/src/table/newRowCache.js +4 -4
  31. package/src/table/relatedTable/columnAggregate.js +1 -1
  32. package/src/table/relation/newManyCache.js +4 -4
  33. package/src/table/resultToRows/newDecodeDbRow.js +1 -1
  34. package/src/table/setSessionCache.js +8 -0
  35. package/src/table/setSessionSingleton.js +1 -1
  36. package/src/tedious/newTransaction.js +1 -0
  37. package/src/tedious/pool/newGenericPool.js +2 -8
  38. package/src/tedious/wrapQuery.js +17 -40
  39. package/dist/index.mjs +0 -20002
  40. package/src/bunPg/newDatabase.js +0 -137
  41. package/src/bunPg/newPool.js +0 -19
  42. package/src/bunPg/pool/end.js +0 -13
  43. package/src/bunPg/pool/newPgPool.js +0 -98
  44. package/src/bunPg/wrapQuery.js +0 -33
  45. package/src/bunSqlite/newPool.js +0 -19
  46. package/src/bunSqlite/newTransaction.js +0 -87
  47. package/src/bunSqlite/pool/newGenericPool.js +0 -55
  48. package/src/bunSqlite/wrapQuery.js +0 -23
  49. package/src/merge-browser.js +0 -9
  50. package/src/merge-server.js +0 -9
  51. package/src/nodeSqlite/decodeBinary.js +0 -9
  52. package/src/nodeSqlite/encodeBinary.js +0 -17
  53. package/src/nodeSqlite/newDatabase.js +0 -116
  54. package/src/nodeSqlite/newPool.js +0 -19
  55. package/src/nodeSqlite/newTransaction.js +0 -87
  56. package/src/nodeSqlite/pool/newGenericPool.js +0 -50
  57. package/src/nodeSqlite/wrapQuery.js +0 -23
  58. package/src/rollup.config.server.js +0 -32
  59. package/src/runtimes.js +0 -24
  60. package/src/sqlite3/deleteFromSql.js +0 -10
  61. package/src/sqlite3/encodeBoolean.js +0 -7
  62. package/src/sqlite3/encodeBuffer.js +0 -7
  63. package/src/sqlite3/insert.js +0 -21
  64. package/src/sqlite3/insertSql.js +0 -67
  65. package/src/sqlite3/lastInsertedSql.js +0 -12
  66. package/src/sqlite3/limitAndOffset.js +0 -18
  67. package/src/sqlite3/newDatabase.js +0 -116
  68. package/src/sqlite3/newTransaction.js +0 -83
  69. package/src/sqlite3/pool/end.js +0 -13
  70. package/src/sqlite3/quote.js +0 -1
  71. package/src/sqlite3/selectForUpdateSql.js +0 -5
  72. /package/src/{bunSqlite → sqlite}/newDatabase.js +0 -0
  73. /package/src/{sqlite3 → sqlite}/newPool.js +0 -0
  74. /package/src/{sqlite3 → sqlite}/wrapQuery.js +0 -0
package/src/index.js CHANGED
@@ -2,8 +2,6 @@ const hostExpress = require('./hostExpress');
2
2
  const hostLocal = require('./hostLocal');
3
3
  const client = require('./client/index.js');
4
4
  const map = require('./client/map');
5
- const runtimes = require('./runtimes');
6
-
7
5
  let _mySql;
8
6
  let _pg;
9
7
  let _sqlite;
@@ -65,26 +63,15 @@ Object.defineProperty(connectViaPool, 'postgres', {
65
63
  Object.defineProperty(connectViaPool, 'pg', {
66
64
  get: function() {
67
65
  if (!_pg)
68
- if (runtimes.bun)
69
- _sqlite = require('./bunPg/newDatabase');
70
- else
71
- _pg = require('./pg/newDatabase');
66
+ _pg = require('./pg/newDatabase');
72
67
  return _pg;
73
68
  }
74
69
  });
75
70
 
76
71
  Object.defineProperty(connectViaPool, 'sqlite', {
77
72
  get: function() {
78
- if (!_sqlite) {
79
- if (runtimes.deno || (runtimes.node && runtimes.node.major >= 22))
80
- _sqlite = require('./nodeSqlite/newDatabase');
81
- else if (runtimes.bun)
82
- _sqlite = require('./bunSqlite/newDatabase');
83
- else if (runtimes.node)
84
- _sqlite = require('./sqlite3/newDatabase');
85
- else
86
- throw new Error('SQLite is not supported in this environment');
87
- }
73
+ if (!_sqlite)
74
+ _sqlite = require('./sqlite/newDatabase');
88
75
  return _sqlite;
89
76
  }
90
77
  });
package/src/map.d.ts CHANGED
@@ -664,23 +664,13 @@ type RelatedColumns<T> = RemoveNeverFlat<{
664
664
  : never;
665
665
  }>;
666
666
 
667
-
668
667
  type AggregateColumns<T> = RemoveNeverFlat<{
669
- [K in keyof T]:
670
- T[K] extends ManyRelation
671
- ? AggregateColumns2<T[K]>
672
- : T[K] extends RelatedTable
673
- ? AggregateColumns2<T[K]>
674
- : never;
675
- }>;
676
-
677
- type AggregateColumns2<T> = RemoveNeverFlat<{
678
668
  [K in keyof T]:
679
669
  T[K] extends NumericColumnTypeDef<infer M> ? NumericColumnSymbol
680
670
  : T[K] extends ManyRelation
681
- ? AggregateColumns2<T[K]>
671
+ ? AggregateColumns<T[K]>
682
672
  : T[K] extends RelatedTable
683
- ? AggregateColumns2<T[K]>
673
+ ? AggregateColumns<T[K]>
684
674
  : never;
685
675
  }>;
686
676
 
@@ -42,6 +42,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
42
42
  };
43
43
  rdb.aggregateCount = 0;
44
44
  rdb.quote = quote;
45
+ rdb.cache = {};
45
46
 
46
47
  if (readonly) {
47
48
  rdb.dbClient = {
@@ -3,7 +3,7 @@
3
3
 
4
4
  var defaults = require('../../poolDefaults');
5
5
  var genericPool = require('../../generic-pool');
6
- var mssql;
6
+ var mssql = require('msnodesqlv8');
7
7
 
8
8
  function newGenericPool(connectionString, poolOptions) {
9
9
  poolOptions = poolOptions || {};
@@ -12,14 +12,7 @@ function newGenericPool(connectionString, poolOptions) {
12
12
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
13
13
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
14
14
  log: poolOptions.log || defaults.poolLog,
15
- create: async function(cb) {
16
- try {
17
- if (!mssql)
18
- mssql = await import('msnodesqlv8');
19
- }
20
- catch (err) {
21
- return cb(err, null);
22
- }
15
+ create: function(cb) {
23
16
  var client;
24
17
  mssql.open(connectionString, onConnected);
25
18
 
@@ -30,6 +30,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
30
30
  };
31
31
  rdb.aggregateCount = 0;
32
32
  rdb.quote = quote;
33
+ rdb.cache = {};
33
34
 
34
35
  if (readonly) {
35
36
  rdb.dbClient = {
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable no-prototype-builtins */
3
3
  var defaults = require('../../poolDefaults');
4
4
  var genericPool = require('../../generic-pool');
5
- var mysql;
5
+ var mysql = require('mysql2');
6
6
 
7
7
  function newGenericPool(connectionString, poolOptions) {
8
8
  if (typeof connectionString === 'string')
@@ -15,16 +15,7 @@ function newGenericPool(connectionString, poolOptions) {
15
15
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
16
16
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
17
17
  log: poolOptions.log,
18
- create: async function(cb) {
19
- try {
20
- if(!mysql) {
21
- mysql = await import('mysql2');
22
- mysql = mysql.default || mysql;
23
- }
24
- }
25
- catch(err) {
26
- return cb(err, null);
27
- }
18
+ create: function(cb) {
28
19
  var innerPool = mysql.createPool(connectionString);
29
20
  return cb(null, innerPool);
30
21
  // innerPool.getConnection(onConnected);
@@ -37,6 +37,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
37
37
  };
38
38
  rdb.aggregateCount = 0;
39
39
  rdb.quote = quote;
40
+ rdb.cache = {};
40
41
 
41
42
  if (readonly) {
42
43
  rdb.dbClient = {
@@ -3,7 +3,10 @@
3
3
 
4
4
  var defaults = require('../../poolDefaults');
5
5
  var genericPool = require('../../generic-pool');
6
- var oracle;
6
+ var oracle = require('oracledb');
7
+
8
+ oracle.outFormat = oracle.OUT_FORMAT_OBJECT;
9
+ oracle.fetchAsBuffer = [ oracle.BLOB ];
7
10
 
8
11
  function newGenericPool(connectionString, poolOptions) {
9
12
  poolOptions = poolOptions || {};
@@ -12,19 +15,8 @@ function newGenericPool(connectionString, poolOptions) {
12
15
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
13
16
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
14
17
  log: poolOptions.log,
15
- create: async function(cb) {
18
+ create: function(cb) {
16
19
  var client;
17
- try {
18
- if (!oracle) {
19
- oracle = await import('oracledb');
20
- oracle = oracle.default || oracle;
21
- oracle.outFormat = oracle.OUT_FORMAT_OBJECT;
22
- oracle.fetchAsBuffer = [ oracle.BLOB ];
23
- }
24
- }
25
- catch (err) {
26
- return cb(err, null);
27
- }
28
20
  oracle.getConnection(connectionString, onConnected);
29
21
  function onConnected(err, _client) {
30
22
  client = _client;
package/src/patchTable.js CHANGED
@@ -3,13 +3,16 @@ let applyPatch = require('./applyPatch');
3
3
  let fromCompareObject = require('./fromCompareObject');
4
4
  let validateDeleteConflict = require('./validateDeleteConflict');
5
5
  let validateDeleteAllowed = require('./validateDeleteAllowed');
6
+ let clearCache = require('./table/clearCache');
6
7
 
7
8
  async function patchTable() {
8
9
  // const dryrun = true;
9
10
  //traverse all rows you want to update before updatinng or inserting anything.
10
11
  //this is to avoid page locks in ms sql
11
12
  // await patchTableCore.apply(null, [...arguments, dryrun]);
12
- return patchTableCore.apply(null, arguments);
13
+ const result = await patchTableCore.apply(null, arguments);
14
+ clearCache(arguments[0]);
15
+ return result;
13
16
  }
14
17
 
15
18
  async function patchTableCore(context, table, patches, { strategy = undefined, deduceStrategy = false, ...options } = {}, dryrun) {
@@ -11,6 +11,11 @@ let hostLocal = require('../hostLocal');
11
11
  let doQuery = require('../query');
12
12
  let releaseDbClient = require('../table/releaseDbClient');
13
13
  let setSessionSingleton = require('../table/setSessionSingleton');
14
+ let types = require('pg').types;
15
+
16
+ types.setTypeParser(1700, function(val) {
17
+ return parseFloat(val);
18
+ });
14
19
 
15
20
  function newDatabase(connectionString, poolOptions) {
16
21
  if (!connectionString)
@@ -34,6 +34,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
34
34
  };
35
35
  rdb.aggregateCount = 0;
36
36
  rdb.quote = quote;
37
+ rdb.cache = {};
37
38
 
38
39
  if (readonly) {
39
40
  rdb.dbClient = {
@@ -4,11 +4,12 @@ var log = require('../../table/log');
4
4
 
5
5
  var defaults = require('../../poolDefaults');
6
6
  var genericPool = require('../../generic-pool');
7
- var pg;
7
+ var _pg = require('pg');
8
8
  var parseSearchPathParam = require('./parseSearchPathParam');
9
9
 
10
10
  function newPgPool(connectionString, poolOptions) {
11
11
  poolOptions = poolOptions || {};
12
+ let pg = poolOptions.native ? _pg.native : _pg;
12
13
 
13
14
  // @ts-ignore
14
15
  var pool = genericPool.Pool({
@@ -16,20 +17,7 @@ function newPgPool(connectionString, poolOptions) {
16
17
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
17
18
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
18
19
  log: poolOptions.log,
19
- create: async function(cb) {
20
- try {
21
- if (!pg) {
22
- pg = await import('pg');
23
- pg = pg.default || pg;
24
- let types = pg.types || pg.types;
25
- types.setTypeParser(1700, function(val) {
26
- return parseFloat(val);
27
- });
28
- }
29
- }
30
- catch(e) {
31
- return cb(e, null);
32
- }
20
+ create: function(cb) {
33
21
  var client = new pg.Client(connectionString);
34
22
  client.connect(function(err) {
35
23
  if (err) return cb(err, null);
@@ -42,6 +42,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
42
42
  };
43
43
  rdb.aggregateCount = 0;
44
44
  rdb.quote = quote;
45
+ rdb.cache = {};
45
46
 
46
47
  if (readonly) {
47
48
  rdb.dbClient = {
@@ -31,6 +31,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
31
31
  };
32
32
  rdb.aggregateCount = 0;
33
33
  rdb.quote = quote;
34
+ rdb.cache = {};
34
35
 
35
36
  if (readonly) {
36
37
  rdb.dbClient = {
@@ -2,7 +2,7 @@
2
2
  var defaults = require('../../poolDefaults');
3
3
 
4
4
  var genericPool = require('../../generic-pool');
5
- var sqlite;
5
+ var sqlite = require('sqlite3');
6
6
 
7
7
  function newGenericPool(connectionString, poolOptions) {
8
8
  poolOptions = poolOptions || {};
@@ -11,15 +11,7 @@ function newGenericPool(connectionString, poolOptions) {
11
11
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
12
12
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
13
13
  log: poolOptions.log || defaults.poolLog,
14
- create: async function(cb) {
15
- try {
16
- if (!sqlite)
17
- sqlite = await import('sqlite3');
18
- sqlite = sqlite.default || sqlite;
19
- }
20
- catch (err) {
21
- return cb(err, null);
22
- }
14
+ create: function(cb) {
23
15
  var client = new sqlite.Database(connectionString, onConnected);
24
16
 
25
17
  function onConnected(err) {
@@ -0,0 +1,7 @@
1
+ var setSessionSingleton = require('./setSessionSingleton');
2
+
3
+ function clearCache(context) {
4
+ setSessionSingleton(context, 'cache', {});
5
+ }
6
+
7
+ module.exports = clearCache;
@@ -1,26 +1,15 @@
1
1
  var newDecodeCore = require('../newDecodeCore');
2
- var getSessionSingleton = require('../../getSessionSingleton');
3
2
 
4
3
  function _new(column) {
5
4
  var decodeCore = newDecodeCore(column);
6
5
 
7
6
  return function(context, value) {
8
-
9
- var toBase64 = getSessionSingleton(context, 'decodeBinary') || toBase64Default;
10
-
11
7
  value = decodeCore(context, value);
12
8
  if (value === null)
13
9
  return value;
14
- else {
15
- const ret = toBase64(value);
16
- return ret;
17
- }
10
+ else
11
+ return value.toString('base64');
18
12
  };
19
13
  }
20
14
 
21
- function toBase64Default(buffer) {
22
- return buffer.toString('base64');
23
-
24
- }
25
-
26
15
  module.exports = _new;
@@ -1,36 +1,26 @@
1
1
  var purify = require('./purify');
2
2
  var newParam = require('../../query/newParameterized');
3
- var getSessionSingleton = require('../../getSessionSingleton');
4
3
 
5
4
  function _new(_column) {
6
5
 
7
- function encode(context, value) {
6
+ function encode(_context, value) {
8
7
  value = purify(value);
9
8
  if (value === null)
10
9
  return newParam('null');
11
-
12
- var encodeCore = getSessionSingleton(context, 'encodeBinary') || encodeDefault;
13
- const enc = encodeCore(value);
14
- return newParam('?', [enc]);
10
+ return newParam('?', [Buffer.from(value, 'base64')]);
15
11
  }
16
- encode.unsafe = function(context, value) {
12
+ encode.unsafe = function(_context, value) {
17
13
  value = purify(value);
18
14
  if (value === null)
19
15
  return 'null';
20
- var encodeCore = getSessionSingleton(context, 'encodeBinary') || encodeDefault;
21
- return encodeCore(value);
16
+ return Buffer.from(value, 'base64');
22
17
  };
23
18
 
24
- encode.direct = function(context, value) {
25
- var encodeCore = getSessionSingleton(context, 'encodeBinary') || encodeDefault;
26
- return encodeCore(value);
19
+ encode.direct = function(_context, value) {
20
+ return Buffer.from(value, 'base64');
27
21
  };
28
22
 
29
23
  return encode;
30
24
  }
31
25
 
32
- function encodeDefault(base64) {
33
- return Buffer.from(base64, 'base64');
34
- }
35
-
36
26
  module.exports = _new;
@@ -0,0 +1,15 @@
1
+ const getSessionSingleton = require('../getSessionSingleton');
2
+
3
+ function columnAggregate(context, operator, column, table, coalesce = true) {
4
+ const quote = getSessionSingleton(context, 'quote');
5
+
6
+ const tableAlias = quote(table._rootAlias || table._dbName);
7
+ const columnName = quote(column._dbName);
8
+
9
+ return {
10
+ expression: (alias) => coalesce ? `COALESCE(${operator}(${tableAlias}.${columnName}), 0) as ${quote(alias)}` : `${operator}(${tableAlias}.${columnName}) as ${quote(alias)}`,
11
+ joins: ['']
12
+ };
13
+ }
14
+
15
+ module.exports = columnAggregate;
@@ -0,0 +1,35 @@
1
+ var getSessionContext = require('../getSessionContext');
2
+ var newJoinCore = require('../query/singleQuery/joinSql/newShallowJoinSqlCore');
3
+ const getSessionSingleton = require('../getSessionSingleton');
4
+
5
+ function columnAggregate(context, operator, column, table, coalesce = true) {
6
+ const quote = getSessionSingleton(context, 'quote');
7
+ const rdb = getSessionContext(context);
8
+ const outerAlias = 'y' + rdb.aggregateCount++;
9
+ const outerAliasQuoted = quote(outerAlias);
10
+ const alias = quote('x');
11
+ const foreignKeys = getForeignKeys(table);
12
+ const select = ` LEFT JOIN (SELECT ${foreignKeys},${operator}(${alias}.${quote(column._dbName)}) as amount`;
13
+ const onClause = createOnClause(context, table, outerAlias);
14
+ const from = ` FROM ${quote(table._dbName)} ${alias} GROUP BY ${foreignKeys}) ${outerAliasQuoted} ON (${onClause})`;
15
+ const join = select + from;
16
+
17
+ return {
18
+ expression: (alias) => coalesce ? `COALESCE(${outerAliasQuoted}.amount, 0) as ${quote(alias)}` : `${outerAliasQuoted}.amount as ${alias}`,
19
+ joins: [join]
20
+ };
21
+
22
+ function getForeignKeys(table) {
23
+ return table._primaryColumns.map(x => `${alias}.${quote(x._dbName)}`).join(',');
24
+ }
25
+ }
26
+
27
+ function createOnClause(context, table, rightAlias) {
28
+ let leftAlias = table._rootAlias || table._dbName;
29
+ const columns = table._primaryColumns;
30
+ return newJoinCore(context, table, columns, columns, leftAlias, rightAlias).sql();
31
+ }
32
+
33
+
34
+
35
+ module.exports = columnAggregate;
@@ -7,6 +7,8 @@ const greaterThanOrEqual = require('./greaterThanOrEqual');
7
7
  const _in = require('./in');
8
8
  const _extractAlias = require('./extractAlias');
9
9
  const quote = require('../../table/quote');
10
+ const aggregate = require('./columnAggregate');
11
+ const aggregateGroup = require('./columnAggregateGroup');
10
12
 
11
13
  module.exports = function(table, name) {
12
14
  var c = {};
@@ -76,6 +78,17 @@ module.exports = function(table, name) {
76
78
  c.IN = c.in;
77
79
  c.self = self;
78
80
 
81
+ c.groupSum = (context, ...rest) => aggregateGroup.apply(null, [context, 'sum', c, table, ...rest]);
82
+ c.groupAvg = (context, ...rest) => aggregateGroup.apply(null, [context, 'avg', c, table, ...rest]);
83
+ c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', c, table, ...rest]);
84
+ c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', c, table, ...rest]);
85
+ c.groupCount = (context, ...rest) => aggregateGroup.apply(null, [context, 'count', c, table, false, ...rest]);
86
+ c.sum = (context, ...rest) => aggregate.apply(null, [context, 'sum', c, table, ...rest]);
87
+ c.avg = (context, ...rest) => aggregate.apply(null, [context, 'avg', c, table, ...rest]);
88
+ c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', c, table, ...rest]);
89
+ c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', c, table, ...rest]);
90
+ c.count = (context, ...rest) => aggregate.apply(null, [context, 'count', c, table, false, ...rest]);
91
+
79
92
  function self(context) {
80
93
  const tableAlias = quote(context,table._rootAlias || table._dbName);
81
94
  const columnName = quote(context, c._dbName);
@@ -0,0 +1,8 @@
1
+ const getSessionSingleton = require('./getSessionSingleton');
2
+
3
+ function getSessionCache(context, id) {
4
+ const cache = getSessionSingleton(context, 'cache');
5
+ return cache[id];
6
+ }
7
+
8
+ module.exports = getSessionCache;
@@ -1,6 +1,6 @@
1
1
  let newCache = require('./newCache');
2
- let getSessionSingleton = require('./getSessionSingleton');
3
- let setSessionSingleton = require('./setSessionSingleton');
2
+ let getSessionCache = require('./getSessionCache');
3
+ let setSessionCache = require('./setSessionCache');
4
4
 
5
5
  function newRowCache(table) {
6
6
  let id = Symbol();
@@ -38,11 +38,11 @@ function newRowCache(table) {
38
38
 
39
39
 
40
40
  function getCache(context, table, id) {
41
- let cache = getSessionSingleton(context, id);
41
+ let cache = getSessionCache(context, id);
42
42
  if (cache)
43
43
  return cache;
44
44
  cache = _newRowCache(table);
45
- setSessionSingleton(context, id, cache);
45
+ setSessionCache(context, id, cache);
46
46
  return cache;
47
47
  }
48
48
 
@@ -11,7 +11,7 @@ function columnAggregate(context, operator, column, relations, coalesce = true)
11
11
  const columnName = quote(column._dbName);
12
12
 
13
13
  return {
14
- expression: (alias) => coalesce ? `COALESCE(${operator}(${tableAlias}.${columnName}), 0) as ${quote(alias)}` : `${operator}(${tableAlias}.${columnName}) as ${alias}`,
14
+ expression: (alias) => coalesce ? `COALESCE(${operator}(${tableAlias}.${columnName}), 0) as ${quote(alias)}` : `${operator}(${tableAlias}.${columnName}) as ${quote(alias)}`,
15
15
 
16
16
  joins: newJoinArray(context, relations)
17
17
  };
@@ -4,8 +4,8 @@ var synchronizeRemoved = require('./manyCache/synchronizeRemoved');
4
4
  var extractParentKey = require('./manyCache/extractParentKey');
5
5
  var newCacheCore = require('./newManyCacheCore');
6
6
  var newId = require('../../newId');
7
- var getSessionSingleton = require('../getSessionSingleton');
8
- var setSessionSingleton = require('../setSessionSingleton');
7
+ var getSessionCache = require('../getSessionCache');
8
+ var setSessionCache = require('../setSessionCache');
9
9
 
10
10
  function newManyCache(joinRelation) {
11
11
  var c = {};
@@ -26,10 +26,10 @@ function newManyCache(joinRelation) {
26
26
 
27
27
  c.getInnerCache = function(context) {
28
28
  const theKey = negotiateKey();
29
- var cache = getSessionSingleton(context, theKey);
29
+ var cache = getSessionCache(context, theKey);
30
30
  if (!cache) {
31
31
  cache = newCacheCore(joinRelation);
32
- setSessionSingleton(context, theKey, cache);
32
+ setSessionCache(context, theKey, cache);
33
33
  fillCache(context);
34
34
  synchronizeAdded(context, c.tryAdd.bind(null, context), joinRelation);
35
35
  synchronizeRemoved(context, c.tryRemove.bind(null, context), joinRelation);
@@ -207,7 +207,7 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
207
207
  for (let i = 0; i < numberOfColumns; i++) {
208
208
  let index = offset + i;
209
209
  let key = keys[index];
210
- if (row[key] !== undefined && !isInsert)
210
+ if (row[key] !== undefined)
211
211
  row[key] = columns[i].decode(context, row[key]);
212
212
  if (shouldValidate && columns[i].validate)
213
213
  columns[i].validate(row[key], row, isInsert);
@@ -0,0 +1,8 @@
1
+ const getSessionSingleton = require('./getSessionSingleton');
2
+
3
+ function setSessionCache(context, id, value) {
4
+ const cache = getSessionSingleton(context, 'cache');
5
+ cache[id] = value;
6
+ }
7
+
8
+ module.exports = setSessionCache;
@@ -1,4 +1,4 @@
1
- var getSessionContext = require('./getSessionContext');
1
+ const getSessionContext = require('./getSessionContext');
2
2
 
3
3
  function setSessionSingleton(context, name, value) {
4
4
  const rdb = getSessionContext(context);
@@ -44,6 +44,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
44
44
  };
45
45
  rdb.aggregateCount = 0;
46
46
  rdb.quote = quote;
47
+ rdb.cache = {};
47
48
 
48
49
  if (readonly) {
49
50
  rdb.dbClient = {
@@ -3,7 +3,7 @@
3
3
 
4
4
  var defaults = require('../../poolDefaults');
5
5
  var genericPool = require('../../generic-pool');
6
- var tedious;
6
+ var tedious = require('tedious');
7
7
  var parseConnectionString = require('./parseConnectionString');
8
8
 
9
9
  function newGenericPool(connectionString, poolOptions) {
@@ -17,13 +17,7 @@ function newGenericPool(connectionString, poolOptions) {
17
17
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
18
18
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
19
19
  log: poolOptions.log || defaults.poolLog,
20
- create: async function(cb) {
21
- try {
22
- if (!tedious)
23
- tedious = await import('tedious');
24
- } catch (err) {
25
- return cb(err, null);
26
- }
20
+ create: function(cb) {
27
21
  var client = new tedious.Connection(connectionString);
28
22
  client.on('connect', onConnected);
29
23
  client.connect();