orange-orm 4.5.0-beta.4 → 4.5.1-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 (54) hide show
  1. package/README.md +12 -12
  2. package/{src/client/index.mjs → dist/index.browser.mjs} +30 -9
  3. package/dist/index.mjs +20001 -0
  4. package/docs/docs.md +1 -0
  5. package/package.json +14 -4
  6. package/src/bunPg/newDatabase.js +137 -0
  7. package/src/bunPg/newPool.js +19 -0
  8. package/src/bunPg/pool/end.js +13 -0
  9. package/src/bunPg/pool/newPgPool.js +98 -0
  10. package/src/bunPg/wrapQuery.js +33 -0
  11. package/src/bunSqlite/newPool.js +19 -0
  12. package/src/bunSqlite/newTransaction.js +83 -0
  13. package/src/bunSqlite/pool/newGenericPool.js +55 -0
  14. package/src/bunSqlite/wrapQuery.js +23 -0
  15. package/src/index.js +16 -3
  16. package/src/merge-browser.js +9 -0
  17. package/src/merge-server.js +9 -0
  18. package/src/mssql/pool/newGenericPool.js +9 -2
  19. package/src/mySql/pool/newGenericPool.js +11 -2
  20. package/src/nodeSqlite/decodeBinary.js +9 -0
  21. package/src/nodeSqlite/encodeBinary.js +20 -0
  22. package/src/nodeSqlite/newDatabase.js +116 -0
  23. package/src/nodeSqlite/newPool.js +19 -0
  24. package/src/nodeSqlite/newTransaction.js +87 -0
  25. package/src/nodeSqlite/pool/newGenericPool.js +50 -0
  26. package/src/nodeSqlite/wrapQuery.js +23 -0
  27. package/src/oracle/pool/newGenericPool.js +13 -5
  28. package/src/pg/newDatabase.js +0 -5
  29. package/src/pg/pool/newPgPool.js +15 -3
  30. package/src/{client/rollup.config.js → rollup.config.browser.js} +1 -1
  31. package/src/rollup.config.server.js +32 -0
  32. package/src/runtimes.js +24 -0
  33. package/src/sqlite3/deleteFromSql.js +10 -0
  34. package/src/sqlite3/encodeBoolean.js +7 -0
  35. package/src/sqlite3/encodeBuffer.js +7 -0
  36. package/src/sqlite3/insert.js +21 -0
  37. package/src/sqlite3/insertSql.js +67 -0
  38. package/src/sqlite3/lastInsertedSql.js +12 -0
  39. package/src/sqlite3/limitAndOffset.js +18 -0
  40. package/src/sqlite3/newDatabase.js +116 -0
  41. package/src/sqlite3/newTransaction.js +83 -0
  42. package/src/sqlite3/pool/end.js +13 -0
  43. package/src/{sqlite → sqlite3}/pool/newGenericPool.js +10 -2
  44. package/src/sqlite3/quote.js +1 -0
  45. package/src/sqlite3/selectForUpdateSql.js +5 -0
  46. package/src/table/column/binary/newDecode.js +13 -2
  47. package/src/table/column/binary/newEncode.js +16 -6
  48. package/src/table/resultToRows/newDecodeDbRow.js +1 -1
  49. package/src/tedious/pool/newGenericPool.js +8 -2
  50. package/src/tedious/wrapQuery.js +40 -17
  51. package/src/client/merge.js +0 -9
  52. /package/src/{sqlite → bunSqlite}/newDatabase.js +0 -0
  53. /package/src/{sqlite → sqlite3}/newPool.js +0 -0
  54. /package/src/{sqlite → sqlite3}/wrapQuery.js +0 -0
package/docs/docs.md CHANGED
@@ -1,4 +1,5 @@
1
1
  All examples below are found at [npmjs.org/package/rdb-demo](https://npmjs.org/package/rdb-demo).
2
+ The _Classic mode_ is only available below version 4.5.0.
2
3
  This is the _Classic Documentation_. Are you looking for the [_Modern Typescript Documentation_](https://github.com/alfateam/orange-orm/blob/master/README.md) ?
3
4
  ---------------
4
5
  __Connecting__
package/package.json CHANGED
@@ -1,8 +1,16 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.5.0-beta.4",
3
+ "version": "4.5.1-beta.1",
4
4
  "main": "./src/index.js",
5
- "browser": "./src/client/index.mjs",
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
+ },
6
14
  "bin": {
7
15
  "orange-orm": "bin/rdb.js"
8
16
  },
@@ -43,8 +51,10 @@
43
51
  "coverage": "vitest run --coverage.enabled --coverage.reporter='text-summary' --threads=false",
44
52
  "testw": "vitest --threads=false update",
45
53
  "tscheck": "tsc ./src/index.d.ts --module commonjs --target es2022 --noEmit true --strict true --esModuleInterop true",
46
- "concat": "node ./src/client/merge.js",
47
- "build": "rollup -c ./src/client/rollup.config.js && npm run concat",
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",
48
58
  "lint": "eslint ./",
49
59
  "fix": "eslint ./ --fix",
50
60
  "owasp": "owasp-dependency-check --project \"MY_PROJECT\" --scan \"package-lock.json\" --exclude \"dependency-check-bin\" --out \"owasp\" --format HTML",
@@ -0,0 +1,137 @@
1
+ let createDomain = require('../createDomain');
2
+ let newTransaction = require('../pg/newTransaction');
3
+ let _begin = require('../table/begin');
4
+ let commit = require('../table/commit');
5
+ let rollback = require('../table/rollback');
6
+ let newPool = require('./newPool');
7
+ let lock = require('../lock');
8
+ let executeSchema = require('../pg/schema');
9
+ let express = require('../hostExpress');
10
+ let hostLocal = require('../hostLocal');
11
+ let doQuery = require('../query');
12
+ let releaseDbClient = require('../table/releaseDbClient');
13
+ let setSessionSingleton = require('../table/setSessionSingleton');
14
+
15
+ function newDatabase(connectionString, poolOptions) {
16
+ if (!connectionString)
17
+ throw new Error('Connection string cannot be empty');
18
+ var pool;
19
+ if (!poolOptions)
20
+ pool = newPool.bind(null, connectionString, poolOptions);
21
+ else
22
+ pool = newPool(connectionString, poolOptions);
23
+
24
+ let c = { poolFactory: pool, hostLocal, express };
25
+
26
+ c.transaction = function(options, fn) {
27
+ if ((arguments.length === 1) && (typeof options === 'function')) {
28
+ fn = options;
29
+ options = undefined;
30
+ }
31
+ let domain = createDomain();
32
+
33
+ if (fn)
34
+ return domain.run(runInTransaction);
35
+ else
36
+ return domain.run(run);
37
+
38
+ async function runInTransaction() {
39
+ let result;
40
+ let transaction = newTransaction(domain, pool, options);
41
+ await new Promise(transaction)
42
+ .then(begin)
43
+ .then(negotiateSchema)
44
+ .then(() => fn(domain))
45
+ .then((res) => result = res)
46
+ .then(() => commit(domain))
47
+ .then(null, (e) => rollback(domain,e));
48
+ return result;
49
+ }
50
+
51
+ function begin() {
52
+ return _begin(domain, options);
53
+ }
54
+
55
+ function run() {
56
+ let p;
57
+ let transaction = newTransaction(domain, pool, options);
58
+ p = new Promise(transaction);
59
+
60
+ return p.then(begin)
61
+ .then(negotiateSchema);
62
+ }
63
+
64
+ function negotiateSchema(previous) {
65
+ let schema = options && options.schema;
66
+ if (!schema)
67
+ return previous;
68
+ return executeSchema(domain, schema);
69
+ }
70
+ };
71
+
72
+ c.createTransaction = function(options) {
73
+ let domain = createDomain();
74
+ let transaction = newTransaction(domain, pool, options);
75
+ let p = domain.run(() => new Promise(transaction)
76
+ .then(begin).then(negotiateSchema));
77
+
78
+ function run(fn) {
79
+ return p.then(domain.run.bind(domain, fn));
80
+ }
81
+
82
+ function begin() {
83
+ return _begin(domain, options);
84
+ }
85
+
86
+ function negotiateSchema(previous) {
87
+ let schema = options && options.schema;
88
+ if (!schema)
89
+ return previous;
90
+ return executeSchema(domain,schema);
91
+ }
92
+
93
+ run.rollback = rollback.bind(null, domain);
94
+ run.commit = commit.bind(null, domain);
95
+
96
+ return run;
97
+ };
98
+
99
+ c.query = function(query) {
100
+ let domain = createDomain();
101
+ let transaction = newTransaction(domain, pool);
102
+ let p = domain.run(() => new Promise(transaction)
103
+ .then(() => setSessionSingleton(domain, 'changes', []))
104
+ .then(() => doQuery(domain, query).then(onResult, onError)));
105
+ return p;
106
+
107
+ function onResult(result) {
108
+ releaseDbClient(domain);
109
+ return result;
110
+ }
111
+
112
+ function onError(e) {
113
+ releaseDbClient(domain);
114
+ throw e;
115
+ }
116
+ };
117
+
118
+ c.rollback = rollback;
119
+ c.commit = commit;
120
+ c.lock = lock;
121
+ c.schema = executeSchema;
122
+
123
+ c.end = function() {
124
+ if (poolOptions)
125
+ return pool.end();
126
+ else
127
+ return Promise.resolve();
128
+ };
129
+
130
+ c.accept = function(caller) {
131
+ caller.visitPg();
132
+ };
133
+
134
+ return c;
135
+ }
136
+
137
+ module.exports = newDatabase;
@@ -0,0 +1,19 @@
1
+ const promisify = require('../promisify');
2
+ const pools = require('../pools');
3
+ const end = require('./pool/end');
4
+ const newPgPool = require('./pool/newPgPool');
5
+ const newId = require('../newId');
6
+
7
+ function newPool(connectionString, poolOptions) {
8
+ let pool = newPgPool(connectionString, poolOptions);
9
+ let id = newId();
10
+ let boundEnd = end.bind(null, pool, id);
11
+ let c = {};
12
+
13
+ c.connect = pool.connect;
14
+ c.end = promisify(boundEnd);
15
+ pools[id] = c;
16
+ return c;
17
+ }
18
+
19
+ module.exports = newPool;
@@ -0,0 +1,13 @@
1
+ var pools = require('../../pools');
2
+
3
+ function endPool(pgPool, id, done) {
4
+ pgPool.drain(onDrained);
5
+
6
+ function onDrained() {
7
+ pgPool.destroyAllNow();
8
+ delete pools[id];
9
+ done();
10
+ }
11
+ }
12
+
13
+ module.exports = endPool;
@@ -0,0 +1,98 @@
1
+ /* eslint-disable no-prototype-builtins */
2
+ //slightly modified code from github.com/brianc/node-postgres
3
+ var log = require('../../table/log');
4
+
5
+ var defaults = require('../../poolDefaults');
6
+ var genericPool = require('../../generic-pool');
7
+ var pg;
8
+ var parseSearchPathParam = require('../../pg/pool/parseSearchPathParam');
9
+
10
+ function newPgPool(connectionString, poolOptions) {
11
+ poolOptions = poolOptions || {};
12
+
13
+ // @ts-ignore
14
+ var pool = genericPool.Pool({
15
+ max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
16
+ idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
17
+ reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
18
+ log: poolOptions.log,
19
+ create: async function(cb) {
20
+ try {
21
+ if (!pg) {
22
+ const bunImport = await import('bun');
23
+ const { sql } = bunImport.default || bunImport;
24
+ pg = sql;
25
+ }
26
+ }
27
+ catch(e) {
28
+ return cb(e, null);
29
+ }
30
+ var client = new pg.Client(connectionString);
31
+ client.connect(function(err) {
32
+ if (err) return cb(err, null);
33
+
34
+ //handle connected client background errors by emitting event
35
+ //via the pg object and then removing errored client from the pool
36
+ client.on('error', function(e) {
37
+ pool.emit('error', e, client);
38
+
39
+ // If the client is already being destroyed, the error
40
+ // occurred during stream ending. Do not attempt to destroy
41
+ // the client again.
42
+ if (!client._destroying) {
43
+ pool.destroy(client);
44
+ }
45
+ });
46
+
47
+ // Remove connection from pool on disconnect
48
+ client.on('end', function(_e) {
49
+ // Do not enter infinite loop between pool.destroy
50
+ // and client 'end' event...
51
+ if (!client._destroying) {
52
+ pool.destroy(client);
53
+ }
54
+ });
55
+ client.poolCount = 0;
56
+ negotiateSearchPath(client, connectionString, (err) => cb(err, client));
57
+
58
+ });
59
+ },
60
+ destroy: function(client) {
61
+ client._destroying = true;
62
+ client.poolCount = undefined;
63
+ client.end();
64
+ }
65
+ });
66
+ //monkey-patch with connect method
67
+ pool.connect = function(cb) {
68
+ pool.acquire(function(err, client) {
69
+ if (err) return cb(err, null, function() {
70
+ /*NOOP*/
71
+ });
72
+ client.poolCount++;
73
+ cb(null, client, function(err) {
74
+ if (err) {
75
+ pool.destroy(client);
76
+ } else {
77
+ pool.release(client);
78
+ }
79
+ });
80
+ });
81
+ };
82
+ return pool;
83
+ }
84
+
85
+ function negotiateSearchPath(client, connectionString, cb) {
86
+ const searchPath = parseSearchPathParam(connectionString);
87
+ if (searchPath) {
88
+ const sql = `set search_path to ${searchPath}`;
89
+ log.emitQuery({sql, parameters: []});
90
+ return client.query(sql, cb);
91
+ }
92
+ else
93
+ cb();
94
+
95
+
96
+ }
97
+
98
+ module.exports = newPgPool;
@@ -0,0 +1,33 @@
1
+ var log = require('../table/log');
2
+ var replaceParamChar = require('../pg/replaceParamChar');
3
+
4
+ function wrapQuery(connection) {
5
+ var runOriginalQuery = connection.query;
6
+ return runQuery;
7
+
8
+ function runQuery(query, onCompleted) {
9
+ var params = query.parameters;
10
+ var sql = replaceParamChar(query, params);
11
+ query = {
12
+ text: sql,
13
+ values: params,
14
+ types: query.types
15
+ };
16
+ log.emitQuery({sql, parameters: params});
17
+
18
+ runOriginalQuery.call(connection, query, onInnerCompleted);
19
+
20
+ function onInnerCompleted(err, result) {
21
+ if (err)
22
+ onCompleted(err);
23
+ else {
24
+ if (Array.isArray(result))
25
+ result = result[result.length-1];
26
+ onCompleted(null, result.rows);
27
+ }
28
+ }
29
+ }
30
+
31
+ }
32
+
33
+ module.exports = wrapQuery;
@@ -0,0 +1,19 @@
1
+ const promisify = require('../promisify');
2
+ const pools = require('../pools');
3
+ const end = require('../sqlite/pool/end');
4
+ const newGenericPool = require('./pool/newGenericPool');
5
+ const newId = require('../newId');
6
+
7
+ function newPool(connectionString, poolOptions) {
8
+ let pool = newGenericPool(connectionString, poolOptions);
9
+ let id = newId();
10
+ let boundEnd = end.bind(null, pool, id);
11
+ let c = {};
12
+
13
+ c.connect = pool.connect;
14
+ c.end = promisify(boundEnd);
15
+ pools[id] = c;
16
+ return c;
17
+ }
18
+
19
+ module.exports = newPool;
@@ -0,0 +1,83 @@
1
+ const wrapQuery = require('./wrapQuery');
2
+ const encodeBoolean = require('../sqlite/encodeBoolean');
3
+ const deleteFromSql = require('../sqlite/deleteFromSql');
4
+ const selectForUpdateSql = require('../sqlite/selectForUpdateSql');
5
+ const lastInsertedSql = require('../sqlite/lastInsertedSql');
6
+ const limitAndOffset = require('../sqlite/limitAndOffset');
7
+ const insertSql = require('../sqlite/insertSql');
8
+ const insert = require('../sqlite/insert');
9
+ const quote = require('../sqlite/quote');
10
+
11
+ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
12
+ var rdb = {poolFactory: pool};
13
+ if (!pool.connect) {
14
+ pool = pool();
15
+ rdb.pool = pool;
16
+ }
17
+ rdb.engine = 'sqlite';
18
+ rdb.encodeBoolean = encodeBoolean;
19
+ rdb.decodeJSON = decodeJSON;
20
+ rdb.encodeJSON = JSON.stringify;
21
+ rdb.deleteFromSql = deleteFromSql;
22
+ rdb.selectForUpdateSql = selectForUpdateSql;
23
+ rdb.lastInsertedSql = lastInsertedSql;
24
+ rdb.insertSql = insertSql;
25
+ rdb.insert = insert;
26
+ rdb.lastInsertedIsSeparate = true;
27
+ rdb.multipleStatements = false;
28
+ rdb.limitAndOffset = limitAndOffset;
29
+ rdb.accept = function(caller) {
30
+ caller.visitSqlite();
31
+ };
32
+ rdb.aggregateCount = 0;
33
+ rdb.quote = quote;
34
+
35
+ if (readonly) {
36
+ rdb.dbClient = {
37
+ executeQuery: function(query, callback) {
38
+ pool.connect((err, client, done) => {
39
+ if (err) {
40
+ return callback(err);
41
+ }
42
+ try {
43
+ wrapQuery(client)(query, (err, res) => {
44
+ done();
45
+ callback(err, res);
46
+ });
47
+ } catch (e) {
48
+ done();
49
+ callback(e);
50
+ }
51
+ });
52
+ }
53
+ };
54
+ domain.rdb = rdb;
55
+ return (onSuccess) => onSuccess();
56
+ }
57
+
58
+ return function(onSuccess, onError) {
59
+ pool.connect(onConnected);
60
+
61
+ function onConnected(err, client, done) {
62
+ try {
63
+ if (err) {
64
+ onError(err);
65
+ return;
66
+ }
67
+ client.executeQuery = wrapQuery(client);
68
+ rdb.dbClient = client;
69
+ rdb.dbClientDone = done;
70
+ domain.rdb = rdb;
71
+ onSuccess();
72
+ } catch (e) {
73
+ onError(e);
74
+ }
75
+ }
76
+ };
77
+ }
78
+
79
+ function decodeJSON(value) {
80
+ return JSON.parse(value);
81
+ }
82
+
83
+ module.exports = newResolveTransaction;
@@ -0,0 +1,55 @@
1
+ /* eslint-disable no-prototype-builtins */
2
+ var defaults = require('../../poolDefaults');
3
+
4
+ var genericPool = require('../../generic-pool');
5
+ var sqlite;
6
+
7
+ function newGenericPool(connectionString, poolOptions) {
8
+ poolOptions = poolOptions || {};
9
+ var pool = genericPool.Pool({
10
+ max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
11
+ idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
12
+ reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
13
+ log: poolOptions.log || defaults.poolLog,
14
+ create: async function(cb) {
15
+ try {
16
+ try {
17
+ if (!sqlite)
18
+ sqlite = await import('bun:sqlite');
19
+ }
20
+ catch (err) {
21
+ return cb(err, null);
22
+ }
23
+
24
+ var client = new sqlite.DatabaseSync(connectionString);
25
+ client.poolCount = 0;
26
+ cb(null, client);
27
+ }
28
+ catch(err) {
29
+ return cb(err, null);
30
+ }
31
+ },
32
+
33
+ destroy: function(client) {
34
+ client.poolCount = undefined;
35
+ client.close();
36
+ }
37
+ });
38
+ //monkey-patch with connect method
39
+ pool.connect = function(cb) {
40
+ pool.acquire(function(err, client) {
41
+ if(err) return cb(err, null, function() {/*NOOP*/});
42
+ client.poolCount++;
43
+ cb(null, client, function(err) {
44
+ if(err) {
45
+ pool.destroy(client);
46
+ } else {
47
+ pool.release(client);
48
+ }
49
+ });
50
+ });
51
+ };
52
+ return pool;
53
+ }
54
+
55
+ module.exports = newGenericPool;
@@ -0,0 +1,23 @@
1
+ var log = require('../table/log');
2
+
3
+ function wrapQuery(connection) {
4
+ return runQuery;
5
+
6
+ function runQuery(query, onCompleted) {
7
+ try {
8
+ var params = query.parameters;
9
+ var sql = query.sql();
10
+ log.emitQuery({ sql, parameters: params });
11
+
12
+ var statement = connection.prepare(sql);
13
+ const rows = statement.all.apply(statement, params);
14
+ onCompleted(null, rows);
15
+ }
16
+ catch (e) {
17
+ onCompleted(e);
18
+ }
19
+ }
20
+
21
+ }
22
+
23
+ module.exports = wrapQuery;
package/src/index.js CHANGED
@@ -2,6 +2,8 @@ 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
+
5
7
  let _mySql;
6
8
  let _pg;
7
9
  let _sqlite;
@@ -63,15 +65,26 @@ Object.defineProperty(connectViaPool, 'postgres', {
63
65
  Object.defineProperty(connectViaPool, 'pg', {
64
66
  get: function() {
65
67
  if (!_pg)
66
- _pg = require('./pg/newDatabase');
68
+ if (runtimes.bun)
69
+ _sqlite = require('./bunPg/newDatabase');
70
+ else
71
+ _pg = require('./pg/newDatabase');
67
72
  return _pg;
68
73
  }
69
74
  });
70
75
 
71
76
  Object.defineProperty(connectViaPool, 'sqlite', {
72
77
  get: function() {
73
- if (!_sqlite)
74
- _sqlite = require('./sqlite/newDatabase');
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
+ }
75
88
  return _sqlite;
76
89
  }
77
90
  });
@@ -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('./dist/index.browser.mjs', 'utf8');
6
+ await fs.writeFile('./dist/index.browser.mjs', data1 + data2);
7
+ }
8
+
9
+ merge();
@@ -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('./dist/index.mjs', 'utf8');
6
+ await fs.writeFile('./dist/index.mjs', data1 + data2);
7
+ }
8
+
9
+ merge();
@@ -3,7 +3,7 @@
3
3
 
4
4
  var defaults = require('../../poolDefaults');
5
5
  var genericPool = require('../../generic-pool');
6
- var mssql = require('msnodesqlv8');
6
+ var mssql;
7
7
 
8
8
  function newGenericPool(connectionString, poolOptions) {
9
9
  poolOptions = poolOptions || {};
@@ -12,7 +12,14 @@ 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: function(cb) {
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
+ }
16
23
  var client;
17
24
  mssql.open(connectionString, onConnected);
18
25
 
@@ -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 = require('mysql2');
5
+ var mysql;
6
6
 
7
7
  function newGenericPool(connectionString, poolOptions) {
8
8
  if (typeof connectionString === 'string')
@@ -15,7 +15,16 @@ 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: function(cb) {
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
+ }
19
28
  var innerPool = mysql.createPool(connectionString);
20
29
  return cb(null, innerPool);
21
30
  // innerPool.getConnection(onConnected);
@@ -0,0 +1,9 @@
1
+ function decodeBinary(u8Arr) {
2
+ let binaryString = '';
3
+ for (let i = 0; i < u8Arr.length; i++) {
4
+ binaryString += String.fromCharCode(u8Arr[i]);
5
+ }
6
+ return btoa(binaryString);
7
+ }
8
+
9
+ module.exports = decodeBinary;
@@ -0,0 +1,20 @@
1
+ function encodeBinary(base64) {
2
+ // return Buffer.from(base64, 'base64');
3
+
4
+
5
+ // Decode base64 to a binary string
6
+ const binaryString = atob(base64);
7
+
8
+ // Create a new Uint8Array with the same length as the binary string
9
+ const len = binaryString.length;
10
+ const bytes = new Uint8Array(len);
11
+
12
+ // Populate the Uint8Array with numeric character codes
13
+ for (let i = 0; i < len; i++) {
14
+ bytes[i] = binaryString.charCodeAt(i);
15
+ }
16
+
17
+ return bytes;
18
+ }
19
+
20
+ module.exports = encodeBinary;