orange-orm 4.5.1-beta.1 → 4.5.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 (69) hide show
  1. package/README.md +11 -11
  2. package/docs/changelog.md +4 -0
  3. package/package.json +4 -14
  4. package/{dist/index.browser.mjs → src/client/index.mjs} +73 -40
  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/mssql/newTransaction.js +1 -0
  10. package/src/mssql/pool/newGenericPool.js +2 -9
  11. package/src/mySql/newTransaction.js +1 -0
  12. package/src/mySql/pool/newGenericPool.js +2 -11
  13. package/src/oracle/newTransaction.js +1 -0
  14. package/src/oracle/pool/newGenericPool.js +5 -13
  15. package/src/patchTable.js +4 -1
  16. package/src/pg/newDatabase.js +5 -0
  17. package/src/pg/newTransaction.js +1 -0
  18. package/src/pg/pool/newPgPool.js +3 -15
  19. package/src/sap/newTransaction.js +1 -0
  20. package/src/sqlite/newTransaction.js +1 -0
  21. package/src/{sqlite3 → sqlite}/pool/newGenericPool.js +2 -10
  22. package/src/table/clearCache.js +7 -0
  23. package/src/table/column/binary/newDecode.js +2 -13
  24. package/src/table/column/binary/newEncode.js +6 -16
  25. package/src/table/getSessionCache.js +8 -0
  26. package/src/table/newRowCache.js +4 -4
  27. package/src/table/relation/newManyCache.js +4 -4
  28. package/src/table/resultToRows/newDecodeDbRow.js +1 -1
  29. package/src/table/setSessionCache.js +8 -0
  30. package/src/table/setSessionSingleton.js +1 -1
  31. package/src/tedious/newTransaction.js +1 -0
  32. package/src/tedious/pool/newGenericPool.js +2 -8
  33. package/src/tedious/wrapQuery.js +17 -40
  34. package/dist/index.mjs +0 -20001
  35. package/src/bunPg/newDatabase.js +0 -137
  36. package/src/bunPg/newPool.js +0 -19
  37. package/src/bunPg/pool/end.js +0 -13
  38. package/src/bunPg/pool/newPgPool.js +0 -98
  39. package/src/bunPg/wrapQuery.js +0 -33
  40. package/src/bunSqlite/newPool.js +0 -19
  41. package/src/bunSqlite/newTransaction.js +0 -83
  42. package/src/bunSqlite/pool/newGenericPool.js +0 -55
  43. package/src/bunSqlite/wrapQuery.js +0 -23
  44. package/src/merge-browser.js +0 -9
  45. package/src/merge-server.js +0 -9
  46. package/src/nodeSqlite/decodeBinary.js +0 -9
  47. package/src/nodeSqlite/encodeBinary.js +0 -20
  48. package/src/nodeSqlite/newDatabase.js +0 -116
  49. package/src/nodeSqlite/newPool.js +0 -19
  50. package/src/nodeSqlite/newTransaction.js +0 -87
  51. package/src/nodeSqlite/pool/newGenericPool.js +0 -50
  52. package/src/nodeSqlite/wrapQuery.js +0 -23
  53. package/src/rollup.config.server.js +0 -32
  54. package/src/runtimes.js +0 -24
  55. package/src/sqlite3/deleteFromSql.js +0 -10
  56. package/src/sqlite3/encodeBoolean.js +0 -7
  57. package/src/sqlite3/encodeBuffer.js +0 -7
  58. package/src/sqlite3/insert.js +0 -21
  59. package/src/sqlite3/insertSql.js +0 -67
  60. package/src/sqlite3/lastInsertedSql.js +0 -12
  61. package/src/sqlite3/limitAndOffset.js +0 -18
  62. package/src/sqlite3/newDatabase.js +0 -116
  63. package/src/sqlite3/newTransaction.js +0 -83
  64. package/src/sqlite3/pool/end.js +0 -13
  65. package/src/sqlite3/quote.js +0 -1
  66. package/src/sqlite3/selectForUpdateSql.js +0 -5
  67. /package/src/{bunSqlite → sqlite}/newDatabase.js +0 -0
  68. /package/src/{sqlite3 → sqlite}/newPool.js +0 -0
  69. /package/src/{sqlite3 → sqlite}/wrapQuery.js +0 -0
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="./docs/orange.svg" alt="Orange ORM Logo" width="250"/>
3
3
  </div>
4
4
 
5
- The ultimate Object Relational Mapper for Node.js and Typescript, offering seamless integration with a variety of popular databases. Whether you're building applications in TypeScript or JavaScript, including both CommonJS and ECMAScript, Orange ORM has got you covered.
5
+ The ultimate Object Relational Mapper for Node.js and Typescript, offering seamless integration with a variety of popular databases. Orange ORM supports both TypeScript and JavaScript, including both CommonJS and ECMAScript.
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/orange-orm.svg?style=flat-square)](https://www.npmjs.org/package/orange-orm)
8
8
  [![Build status](https://github.com/alfateam/orange-orm/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/alfateam/orange-orm/actions)
@@ -22,16 +22,16 @@ The ultimate Object Relational Mapper for Node.js and Typescript, offering seaml
22
22
  - **TypeScript and JavaScript Support**: Orange fully supports both TypeScript and JavaScript, allowing you to leverage the benefits of static typing and modern ECMAScript features.
23
23
  - **Works in the Browser**: You can securely use Orange in the browser by utilizing the Express.js plugin, which serves to safeguard sensitive database credentials from exposure at the client level and protect against SQL injection. This method mirrors a traditional REST API, augmented with advanced TypeScript tooling for enhanced functionality.
24
24
 
25
- ## Supported Databases and Runtimes
26
- | | Node | Deno | Bun |Cloudflare |
27
- | ------------- | :-----: | :-----: | :-----: | :-----: |
28
- | Postgres | | ✅ | ✅ | ✅
29
- | MS SQL | | | ✅ |
30
- | MySQL | | ✅ | ✅ |
31
- | Oracle | | ✅ | ✅ |
32
- | SAP ASE | | | |
33
- | SQLite | | ✅ | ✅ |
34
- | Cloudflare D1 | | | | ✅
25
+ ## Supported Databases
26
+
27
+ Postgres
28
+ MS SQL
29
+ MySQL
30
+ Oracle
31
+ SAP ASE
32
+ SQLite
33
+ Cloudflare D1
34
+
35
35
 
36
36
  This is the _Modern Typescript Documentation_. Are you looking for the [_Classic Documentation_](https://github.com/alfateam/orange-orm/blob/master/docs/docs.md) ?
37
37
 
package/docs/changelog.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## Changelog
2
+ __4.5.1__
3
+ Bugfix: "Changed by Other User" Error Triggered by Precision Mismatch in Numeric Column. See [#120](https://github.com/alfateam/orange-orm/issues/120)
2
4
  __4.5.0__
3
5
  Support for Cloudflare D1.
4
6
  __4.4.2__
@@ -26,6 +28,8 @@ __4.0.1__
26
28
  Inhouse definitions of ajv to avoid trouble with nestjs.
27
29
  __4.0.0__
28
30
  Changed the behaviour of `update` to accept a `where` filter and only update passed in columns and relations. The previous behaviour of `update` has moved to `replace` method.
31
+ __3.10.4__
32
+ Bugfix: "Changed by Other User" Error Triggered by Precision Mismatch in Numeric Column. See [#120](https://github.com/alfateam/orange-orm/issues/120)
29
33
  __3.10.3__
30
34
  Fix duplicate method signatures for those still using code generation
31
35
  __3.10.2__
package/package.json CHANGED
@@ -1,16 +1,8 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.5.1-beta.1",
3
+ "version": "4.5.1",
4
4
  "main": "./src/index.js",
5
- "module": "./dist/index.mjs",
6
- "browser": "./dist/index.browser.mjs",
7
- "exports": {
8
- ".": {
9
- "require": "./src/index.js",
10
- "import": "./dist/index.mjs",
11
- "browser": "./dist/index.browser.mjs"
12
- }
13
- },
5
+ "browser": "./src/client/index.mjs",
14
6
  "bin": {
15
7
  "orange-orm": "bin/rdb.js"
16
8
  },
@@ -51,10 +43,8 @@
51
43
  "coverage": "vitest run --coverage.enabled --coverage.reporter='text-summary' --threads=false",
52
44
  "testw": "vitest --threads=false update",
53
45
  "tscheck": "tsc ./src/index.d.ts --module commonjs --target es2022 --noEmit true --strict true --esModuleInterop true",
54
- "concat-server": "node ./src/merge-server.js",
55
- "concat-browser": "node ./src/merge-browser.js",
56
- "build-server": "rollup -c ./src/rollup.config.server.js && npm run concat-server",
57
- "build-browser": "rollup -c ./src/rollup.config.browser.js && npm run concat-browser",
46
+ "concat": "node ./src/client/merge.js",
47
+ "build": "rollup -c ./src/client/rollup.config.js && npm run concat",
58
48
  "lint": "eslint ./",
59
49
  "fix": "eslint ./ --fix",
60
50
  "owasp": "owasp-dependency-check --project \"MY_PROJECT\" --scan \"package-lock.json\" --exclude \"dependency-check-bin\" --out \"owasp\" --format HTML",
@@ -1758,7 +1758,7 @@ var hasRequiredSetSessionSingleton;
1758
1758
  function requireSetSessionSingleton () {
1759
1759
  if (hasRequiredSetSessionSingleton) return setSessionSingleton_1;
1760
1760
  hasRequiredSetSessionSingleton = 1;
1761
- var getSessionContext = requireGetSessionContext();
1761
+ const getSessionContext = requireGetSessionContext();
1762
1762
 
1763
1763
  function setSessionSingleton(context, name, value) {
1764
1764
  const rdb = getSessionContext(context);
@@ -5137,39 +5137,29 @@ function requireNewEncode () {
5137
5137
  hasRequiredNewEncode = 1;
5138
5138
  var purify = requirePurify();
5139
5139
  var newParam = requireNewParameterized();
5140
- var getSessionSingleton = requireGetSessionSingleton();
5141
5140
 
5142
5141
  function _new(_column) {
5143
5142
 
5144
- function encode(context, value) {
5143
+ function encode(_context, value) {
5145
5144
  value = purify(value);
5146
5145
  if (value === null)
5147
5146
  return newParam('null');
5148
-
5149
- var encodeCore = getSessionSingleton(context, 'encodeBinary') || encodeDefault;
5150
- const enc = encodeCore(value);
5151
- return newParam('?', [enc]);
5147
+ return newParam('?', [Buffer.from(value, 'base64')]);
5152
5148
  }
5153
- encode.unsafe = function(context, value) {
5149
+ encode.unsafe = function(_context, value) {
5154
5150
  value = purify(value);
5155
5151
  if (value === null)
5156
5152
  return 'null';
5157
- var encodeCore = getSessionSingleton(context, 'encodeBinary') || encodeDefault;
5158
- return encodeCore(value);
5153
+ return Buffer.from(value, 'base64');
5159
5154
  };
5160
5155
 
5161
- encode.direct = function(context, value) {
5162
- var encodeCore = getSessionSingleton(context, 'encodeBinary') || encodeDefault;
5163
- return encodeCore(value);
5156
+ encode.direct = function(_context, value) {
5157
+ return Buffer.from(value, 'base64');
5164
5158
  };
5165
5159
 
5166
5160
  return encode;
5167
5161
  }
5168
5162
 
5169
- function encodeDefault(base64) {
5170
- return Buffer.from(base64, 'base64');
5171
- }
5172
-
5173
5163
  newEncode = _new;
5174
5164
  return newEncode;
5175
5165
  }
@@ -5181,30 +5171,19 @@ function requireNewDecode () {
5181
5171
  if (hasRequiredNewDecode) return newDecode;
5182
5172
  hasRequiredNewDecode = 1;
5183
5173
  var newDecodeCore = requireNewDecodeCore();
5184
- var getSessionSingleton = requireGetSessionSingleton();
5185
5174
 
5186
5175
  function _new(column) {
5187
5176
  var decodeCore = newDecodeCore(column);
5188
5177
 
5189
5178
  return function(context, value) {
5190
-
5191
- var toBase64 = getSessionSingleton(context, 'decodeBinary') || toBase64Default;
5192
-
5193
5179
  value = decodeCore(context, value);
5194
5180
  if (value === null)
5195
5181
  return value;
5196
- else {
5197
- const ret = toBase64(value);
5198
- return ret;
5199
- }
5182
+ else
5183
+ return value.toString('base64');
5200
5184
  };
5201
5185
  }
5202
5186
 
5203
- function toBase64Default(buffer) {
5204
- return buffer.toString('base64');
5205
-
5206
- }
5207
-
5208
5187
  newDecode = _new;
5209
5188
  return newDecode;
5210
5189
  }
@@ -7393,6 +7372,22 @@ function requireValidateDeleteAllowed () {
7393
7372
  return validateDeleteAllowed_1;
7394
7373
  }
7395
7374
 
7375
+ var clearCache_1;
7376
+ var hasRequiredClearCache;
7377
+
7378
+ function requireClearCache () {
7379
+ if (hasRequiredClearCache) return clearCache_1;
7380
+ hasRequiredClearCache = 1;
7381
+ var setSessionSingleton = requireSetSessionSingleton();
7382
+
7383
+ function clearCache(context) {
7384
+ setSessionSingleton(context, 'cache', {});
7385
+ }
7386
+
7387
+ clearCache_1 = clearCache;
7388
+ return clearCache_1;
7389
+ }
7390
+
7396
7391
  /* eslint-disable require-atomic-updates */
7397
7392
 
7398
7393
  var patchTable_1;
@@ -7405,13 +7400,16 @@ function requirePatchTable () {
7405
7400
  let fromCompareObject = requireFromCompareObject();
7406
7401
  let validateDeleteConflict = requireValidateDeleteConflict();
7407
7402
  let validateDeleteAllowed = requireValidateDeleteAllowed();
7403
+ let clearCache = requireClearCache();
7408
7404
 
7409
7405
  async function patchTable() {
7410
7406
  // const dryrun = true;
7411
7407
  //traverse all rows you want to update before updatinng or inserting anything.
7412
7408
  //this is to avoid page locks in ms sql
7413
7409
  // await patchTableCore.apply(null, [...arguments, dryrun]);
7414
- return patchTableCore.apply(null, arguments);
7410
+ const result = await patchTableCore.apply(null, arguments);
7411
+ clearCache(arguments[0]);
7412
+ return result;
7415
7413
  }
7416
7414
 
7417
7415
  async function patchTableCore(context, table, patches, { strategy = undefined, deduceStrategy = false, ...options } = {}, dryrun) {
@@ -8014,7 +8012,7 @@ function requireNewDecodeDbRow () {
8014
8012
  for (let i = 0; i < numberOfColumns; i++) {
8015
8013
  let index = offset + i;
8016
8014
  let key = keys[index];
8017
- if (row[key] !== undefined && !isInsert)
8015
+ if (row[key] !== undefined)
8018
8016
  row[key] = columns[i].decode(context, row[key]);
8019
8017
  if (shouldValidate && columns[i].validate)
8020
8018
  columns[i].validate(row[key], row, isInsert);
@@ -10074,6 +10072,40 @@ function requireNewId () {
10074
10072
  return newId;
10075
10073
  }
10076
10074
 
10075
+ var getSessionCache_1;
10076
+ var hasRequiredGetSessionCache;
10077
+
10078
+ function requireGetSessionCache () {
10079
+ if (hasRequiredGetSessionCache) return getSessionCache_1;
10080
+ hasRequiredGetSessionCache = 1;
10081
+ const getSessionSingleton = requireGetSessionSingleton();
10082
+
10083
+ function getSessionCache(context, id) {
10084
+ const cache = getSessionSingleton(context, 'cache');
10085
+ return cache[id];
10086
+ }
10087
+
10088
+ getSessionCache_1 = getSessionCache;
10089
+ return getSessionCache_1;
10090
+ }
10091
+
10092
+ var setSessionCache_1;
10093
+ var hasRequiredSetSessionCache;
10094
+
10095
+ function requireSetSessionCache () {
10096
+ if (hasRequiredSetSessionCache) return setSessionCache_1;
10097
+ hasRequiredSetSessionCache = 1;
10098
+ const getSessionSingleton = requireGetSessionSingleton();
10099
+
10100
+ function setSessionCache(context, id, value) {
10101
+ const cache = getSessionSingleton(context, 'cache');
10102
+ cache[id] = value;
10103
+ }
10104
+
10105
+ setSessionCache_1 = setSessionCache;
10106
+ return setSessionCache_1;
10107
+ }
10108
+
10077
10109
  var newManyCache_1;
10078
10110
  var hasRequiredNewManyCache;
10079
10111
 
@@ -10086,8 +10118,8 @@ function requireNewManyCache () {
10086
10118
  var extractParentKey = requireExtractParentKey();
10087
10119
  var newCacheCore = requireNewManyCacheCore();
10088
10120
  var newId = requireNewId();
10089
- var getSessionSingleton = requireGetSessionSingleton();
10090
- var setSessionSingleton = requireSetSessionSingleton();
10121
+ var getSessionCache = requireGetSessionCache();
10122
+ var setSessionCache = requireSetSessionCache();
10091
10123
 
10092
10124
  function newManyCache(joinRelation) {
10093
10125
  var c = {};
@@ -10108,10 +10140,10 @@ function requireNewManyCache () {
10108
10140
 
10109
10141
  c.getInnerCache = function(context) {
10110
10142
  const theKey = negotiateKey();
10111
- var cache = getSessionSingleton(context, theKey);
10143
+ var cache = getSessionCache(context, theKey);
10112
10144
  if (!cache) {
10113
10145
  cache = newCacheCore(joinRelation);
10114
- setSessionSingleton(context, theKey, cache);
10146
+ setSessionCache(context, theKey, cache);
10115
10147
  fillCache(context);
10116
10148
  synchronizeAdded(context, c.tryAdd.bind(null, context), joinRelation);
10117
10149
  synchronizeRemoved(context, c.tryRemove.bind(null, context), joinRelation);
@@ -11061,8 +11093,8 @@ function requireNewRowCache () {
11061
11093
  if (hasRequiredNewRowCache) return newRowCache_1;
11062
11094
  hasRequiredNewRowCache = 1;
11063
11095
  let newCache = requireNewCache();
11064
- let getSessionSingleton = requireGetSessionSingleton();
11065
- let setSessionSingleton = requireSetSessionSingleton();
11096
+ let getSessionCache = requireGetSessionCache();
11097
+ let setSessionCache = requireSetSessionCache();
11066
11098
 
11067
11099
  function newRowCache(table) {
11068
11100
  let id = Symbol();
@@ -11100,11 +11132,11 @@ function requireNewRowCache () {
11100
11132
 
11101
11133
 
11102
11134
  function getCache(context, table, id) {
11103
- let cache = getSessionSingleton(context, id);
11135
+ let cache = getSessionCache(context, id);
11104
11136
  if (cache)
11105
11137
  return cache;
11106
11138
  cache = _newRowCache(table);
11107
- setSessionSingleton(context, id, cache);
11139
+ setSessionCache(context, id, cache);
11108
11140
  return cache;
11109
11141
  }
11110
11142
 
@@ -12965,6 +12997,7 @@ function requireNewTransaction () {
12965
12997
  };
12966
12998
  rdb.aggregateCount = 0;
12967
12999
  rdb.quote = (name) => `"${name}"`;
13000
+ rdb.cache = {};
12968
13001
 
12969
13002
  if (readonly) {
12970
13003
  rdb.dbClient = {
@@ -0,0 +1,9 @@
1
+ const fs = require('fs').promises;
2
+
3
+ async function merge() {
4
+ let data1 = await fs.readFile('./src/client/self.js', 'utf8');
5
+ let data2 = await fs.readFile('./src/client/index.mjs', 'utf8');
6
+ await fs.writeFile('./src/client/index.mjs', data1 + data2);
7
+ }
8
+
9
+ merge();
@@ -5,7 +5,7 @@ import nodeResolve from '@rollup/plugin-node-resolve';
5
5
  export default {
6
6
  input: './src/indexBrowser.js',
7
7
  output: {
8
- file: './dist/index.browser.mjs',
8
+ file: './src/client/index.mjs',
9
9
  format: 'esm',
10
10
  interop: 'auto'
11
11
  },
@@ -31,6 +31,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
31
31
  };
32
32
  rdb.aggregateCount = 0;
33
33
  rdb.quote = (name) => `"${name}"`;
34
+ rdb.cache = {};
34
35
 
35
36
  if (readonly) {
36
37
  rdb.dbClient = {
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
  });
@@ -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;