orange-orm 4.5.5 → 4.6.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 (59) hide show
  1. package/README.md +18 -16
  2. package/{src/client/index.mjs → dist/index.browser.mjs} +33 -12
  3. package/dist/index.mjs +20127 -0
  4. package/docs/changelog.md +3 -0
  5. package/package.json +15 -4
  6. package/src/bunPg/newDatabase.js +137 -0
  7. package/src/bunPg/newPool.js +19 -0
  8. package/src/bunPg/newTransaction.js +87 -0
  9. package/src/bunPg/pool/end.js +13 -0
  10. package/src/bunPg/pool/newPgPool.js +77 -0
  11. package/src/bunPg/wrapQuery.js +97 -0
  12. package/src/bunSqlite/newPool.js +19 -0
  13. package/src/bunSqlite/newTransaction.js +88 -0
  14. package/src/bunSqlite/pool/newGenericPool.js +55 -0
  15. package/src/bunSqlite/wrapQuery.js +23 -0
  16. package/src/d1/newTransaction.js +2 -2
  17. package/src/d1/wrapQuery.js +1 -1
  18. package/src/index.js +20 -4
  19. package/src/merge-browser.js +9 -0
  20. package/src/merge-server.js +9 -0
  21. package/src/mssql/newTransaction.js +2 -2
  22. package/src/mssql/pool/newGenericPool.js +9 -2
  23. package/src/mssql/wrapQuery.js +1 -1
  24. package/src/mySql/newTransaction.js +2 -2
  25. package/src/mySql/pool/newGenericPool.js +11 -2
  26. package/src/mySql/wrapQuery.js +1 -1
  27. package/src/nodeSqlite/decodeBinary.js +9 -0
  28. package/src/nodeSqlite/encodeBinary.js +17 -0
  29. package/src/nodeSqlite/newDatabase.js +116 -0
  30. package/src/nodeSqlite/newPool.js +19 -0
  31. package/src/nodeSqlite/newTransaction.js +88 -0
  32. package/src/nodeSqlite/pool/newGenericPool.js +50 -0
  33. package/src/nodeSqlite/wrapQuery.js +23 -0
  34. package/src/oracle/newTransaction.js +2 -2
  35. package/src/oracle/pool/newGenericPool.js +13 -5
  36. package/src/oracle/wrapQuery.js +1 -1
  37. package/src/pg/newDatabase.js +0 -5
  38. package/src/pg/newTransaction.js +2 -2
  39. package/src/pg/pool/newPgPool.js +15 -3
  40. package/src/pg/wrapQuery.js +1 -1
  41. package/src/{client/rollup.config.js → rollup.config.browser.js} +1 -1
  42. package/src/rollup.config.server.js +32 -0
  43. package/src/runtimes.js +24 -0
  44. package/src/sap/newTransaction.js +2 -2
  45. package/src/sqlite3/encodeBuffer.js +7 -0
  46. package/src/sqlite3/newDatabase.js +116 -0
  47. package/src/{sqlite → sqlite3}/newTransaction.js +10 -10
  48. package/src/sqlite3/pool/end.js +13 -0
  49. package/src/{sqlite → sqlite3}/pool/newGenericPool.js +10 -2
  50. package/src/{sqlite → sqlite3}/wrapQuery.js +1 -1
  51. package/src/table/column/binary/newDecode.js +13 -2
  52. package/src/table/column/binary/newEncode.js +16 -6
  53. package/src/table/resultToRows/newDecodeDbRow.js +1 -1
  54. package/src/tedious/newTransaction.js +2 -2
  55. package/src/tedious/pool/newGenericPool.js +8 -2
  56. package/src/tedious/wrapQuery.js +41 -18
  57. package/src/client/merge.js +0 -9
  58. /package/src/{sqlite → bunSqlite}/newDatabase.js +0 -0
  59. /package/src/{sqlite → sqlite3}/newPool.js +0 -0
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;
@@ -55,7 +57,10 @@ Object.defineProperty(connectViaPool, 'mySql', {
55
57
  Object.defineProperty(connectViaPool, 'postgres', {
56
58
  get: function() {
57
59
  if (!_pg)
58
- _pg = require('./pg/newDatabase');
60
+ if (runtimes.bun)
61
+ _pg = require('./bunPg/newDatabase');
62
+ else
63
+ _pg = require('./pg/newDatabase');
59
64
  return _pg;
60
65
  }
61
66
  });
@@ -63,15 +68,26 @@ Object.defineProperty(connectViaPool, 'postgres', {
63
68
  Object.defineProperty(connectViaPool, 'pg', {
64
69
  get: function() {
65
70
  if (!_pg)
66
- _pg = require('./pg/newDatabase');
71
+ if (runtimes.bun)
72
+ _pg = require('./bunPg/newDatabase');
73
+ else
74
+ _pg = require('./pg/newDatabase');
67
75
  return _pg;
68
76
  }
69
77
  });
70
78
 
71
79
  Object.defineProperty(connectViaPool, 'sqlite', {
72
80
  get: function() {
73
- if (!_sqlite)
74
- _sqlite = require('./sqlite/newDatabase');
81
+ if (!_sqlite) {
82
+ if (runtimes.deno || (runtimes.node && runtimes.node.major >= 22))
83
+ _sqlite = require('./nodeSqlite/newDatabase');
84
+ else if (runtimes.bun)
85
+ _sqlite = require('./bunSqlite/newDatabase');
86
+ else if (runtimes.node)
87
+ _sqlite = require('./sqlite3/newDatabase');
88
+ else
89
+ throw new Error('SQLite is not supported in this environment');
90
+ }
75
91
  return _sqlite;
76
92
  }
77
93
  });
@@ -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();
@@ -53,7 +53,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
53
53
  }
54
54
  try {
55
55
  client.setUseUTC(false);
56
- wrapQuery(client)(query, (err, res) => {
56
+ wrapQuery(domain, client)(query, (err, res) => {
57
57
  done();
58
58
  callback(err, res);
59
59
  });
@@ -78,7 +78,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
78
78
  return;
79
79
  }
80
80
  client.setUseUTC(false);
81
- client.executeQuery = wrapQuery(client);
81
+ client.executeQuery = wrapQuery(domain, client);
82
82
  rdb.dbClient = client;
83
83
  rdb.dbClientDone = done;
84
84
  domain.rdb = rdb;
@@ -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
 
@@ -1,6 +1,6 @@
1
1
  var log = require('../table/log');
2
2
 
3
- function wrapQuery(connection) {
3
+ function wrapQuery(_context, connection) {
4
4
  var runOriginalQuery = connection.query;
5
5
  return runQuery;
6
6
 
@@ -40,7 +40,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
40
40
  return callback(err);
41
41
  }
42
42
  try {
43
- wrapQuery(client)(query, (err, res) => {
43
+ wrapQuery(domain, client)(query, (err, res) => {
44
44
  done();
45
45
  callback(err, res);
46
46
  });
@@ -64,7 +64,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
64
64
  onError(err);
65
65
  return;
66
66
  }
67
- client.executeQuery = wrapQuery(client);
67
+ client.executeQuery = wrapQuery(domain, client);
68
68
  rdb.dbClient = client;
69
69
  rdb.dbClientDone = done;
70
70
  domain.rdb = rdb;
@@ -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);
@@ -1,6 +1,6 @@
1
1
  var log = require('../table/log');
2
2
 
3
- function wrapQuery(connection) {
3
+ function wrapQuery(_context, connection) {
4
4
  var runOriginalQuery = connection.query;
5
5
  return runQuery;
6
6
 
@@ -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,17 @@
1
+ function encodeBinary(base64) {
2
+ // Decode base64 to a binary string
3
+ const binaryString = atob(base64);
4
+
5
+ // Create a new Uint8Array with the same length as the binary string
6
+ const len = binaryString.length;
7
+ const bytes = new Uint8Array(len);
8
+
9
+ // Populate the Uint8Array with numeric character codes
10
+ for (let i = 0; i < len; i++) {
11
+ bytes[i] = binaryString.charCodeAt(i);
12
+ }
13
+
14
+ return bytes;
15
+ }
16
+
17
+ module.exports = encodeBinary;
@@ -0,0 +1,116 @@
1
+ let createDomain = require('../createDomain');
2
+ let newTransaction = require('./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 express = require('../hostExpress');
8
+ let hostLocal = require('../hostLocal');
9
+ let doQuery = require('../query');
10
+ let releaseDbClient = require('../table/releaseDbClient');
11
+ let setSessionSingleton = require('../table/setSessionSingleton');
12
+
13
+ function newDatabase(connectionString, poolOptions) {
14
+ if (!connectionString)
15
+ throw new Error('Connection string cannot be empty');
16
+ var pool;
17
+ if (!poolOptions)
18
+ pool = newPool.bind(null,connectionString, poolOptions);
19
+ else
20
+ pool = newPool(connectionString, poolOptions);
21
+
22
+ let c = {poolFactory: pool, hostLocal, express};
23
+
24
+ c.transaction = function(options, fn) {
25
+ if ((arguments.length === 1) && (typeof options === 'function')) {
26
+ fn = options;
27
+ options = undefined;
28
+ }
29
+ let domain = createDomain();
30
+
31
+ if (fn)
32
+ return domain.run(runInTransaction);
33
+ else
34
+ return domain.run(run);
35
+
36
+ function begin() {
37
+ return _begin(domain, options);
38
+ }
39
+
40
+ async function runInTransaction() {
41
+ let result;
42
+ let transaction = newTransaction(domain, pool, options);
43
+ await new Promise(transaction)
44
+ .then(begin)
45
+ .then(() => fn(domain))
46
+ .then((res) => result = res)
47
+ .then(() => commit(domain))
48
+ .then(null, (e) => rollback(domain, e));
49
+ return result;
50
+ }
51
+
52
+ function run() {
53
+ let p;
54
+ let transaction = newTransaction(domain, pool, options);
55
+ p = new Promise(transaction);
56
+
57
+ return p.then(begin);
58
+ }
59
+
60
+ };
61
+
62
+ c.createTransaction = function(options) {
63
+ let domain = createDomain();
64
+ let transaction = newTransaction(domain, pool);
65
+ let p = domain.run(() => new Promise(transaction).then(begin));
66
+
67
+ function run(fn) {
68
+ return p.then(() => fn(domain));
69
+ }
70
+ run.rollback = rollback.bind(null, domain);
71
+ run.commit = commit.bind(null, domain);
72
+ return run;
73
+
74
+ function begin() {
75
+ return _begin(domain, options);
76
+ }
77
+ };
78
+
79
+ c.query = function(query) {
80
+ let domain = createDomain();
81
+ let transaction = newTransaction(domain, pool);
82
+ let p = domain.run(() => new Promise(transaction)
83
+ .then(() => setSessionSingleton(domain, 'changes', []))
84
+ .then(() => doQuery(domain, query).then(onResult, onError)));
85
+ return p;
86
+
87
+ function onResult(result) {
88
+ releaseDbClient(domain);
89
+ return result;
90
+ }
91
+
92
+ function onError(e) {
93
+ releaseDbClient(domain);
94
+ throw e;
95
+ }
96
+ };
97
+
98
+
99
+ c.rollback = rollback;
100
+ c.commit = commit;
101
+
102
+ c.end = function() {
103
+ if (poolOptions)
104
+ return pool.end();
105
+ else
106
+ return Promise.resolve();
107
+ };
108
+
109
+ c.accept = function(caller) {
110
+ caller.visitSqlite();
111
+ };
112
+
113
+ return c;
114
+ }
115
+
116
+ module.exports = newDatabase;
@@ -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,88 @@
1
+ const wrapQuery = require('./wrapQuery');
2
+ const encodeBoolean = require('../sqlite/encodeBoolean');
3
+ const encodeBinary = require('./encodeBinary');
4
+ const decodeBinary = require('./decodeBinary');
5
+ const deleteFromSql = require('../sqlite/deleteFromSql');
6
+ const selectForUpdateSql = require('../sqlite/selectForUpdateSql');
7
+ const lastInsertedSql = require('../sqlite/lastInsertedSql');
8
+ const limitAndOffset = require('../sqlite/limitAndOffset');
9
+ const insertSql = require('../sqlite/insertSql');
10
+ const insert = require('../sqlite/insert');
11
+ const quote = require('../sqlite/quote');
12
+
13
+ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
14
+ var rdb = {poolFactory: pool};
15
+ if (!pool.connect) {
16
+ pool = pool();
17
+ rdb.pool = pool;
18
+ }
19
+ rdb.engine = 'sqlite';
20
+ rdb.encodeBoolean = encodeBoolean;
21
+ rdb.encodeBinary = encodeBinary;
22
+ rdb.decodeBinary = decodeBinary;
23
+ rdb.decodeJSON = decodeJSON;
24
+ rdb.encodeJSON = JSON.stringify;
25
+ rdb.deleteFromSql = deleteFromSql;
26
+ rdb.selectForUpdateSql = selectForUpdateSql;
27
+ rdb.lastInsertedSql = lastInsertedSql;
28
+ rdb.insertSql = insertSql;
29
+ rdb.insert = insert;
30
+ rdb.lastInsertedIsSeparate = true;
31
+ rdb.multipleStatements = false;
32
+ rdb.limitAndOffset = limitAndOffset;
33
+ rdb.accept = function(caller) {
34
+ caller.visitSqlite();
35
+ };
36
+ rdb.aggregateCount = 0;
37
+ rdb.quote = quote;
38
+ rdb.cache = {};
39
+
40
+ if (readonly) {
41
+ rdb.dbClient = {
42
+ executeQuery: function(query, callback) {
43
+ pool.connect((err, client, done) => {
44
+ if (err) {
45
+ return callback(err);
46
+ }
47
+ try {
48
+ wrapQuery(domain, client)(query, (err, res) => {
49
+ done();
50
+ callback(err, res);
51
+ });
52
+ } catch (e) {
53
+ done();
54
+ callback(e);
55
+ }
56
+ });
57
+ }
58
+ };
59
+ domain.rdb = rdb;
60
+ return (onSuccess) => onSuccess();
61
+ }
62
+
63
+ return function(onSuccess, onError) {
64
+ pool.connect(onConnected);
65
+
66
+ function onConnected(err, client, done) {
67
+ try {
68
+ if (err) {
69
+ onError(err);
70
+ return;
71
+ }
72
+ client.executeQuery = wrapQuery(domain, client);
73
+ rdb.dbClient = client;
74
+ rdb.dbClientDone = done;
75
+ domain.rdb = rdb;
76
+ onSuccess();
77
+ } catch (e) {
78
+ onError(e);
79
+ }
80
+ }
81
+ };
82
+ }
83
+
84
+ function decodeJSON(value) {
85
+ return JSON.parse(value);
86
+ }
87
+
88
+ module.exports = newResolveTransaction;
@@ -0,0 +1,50 @@
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
+
9
+ poolOptions = poolOptions || {};
10
+ var pool = genericPool.Pool({
11
+ max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
12
+ idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
13
+ reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
14
+ log: poolOptions.log || defaults.poolLog,
15
+ create: async function(cb) {
16
+ try {
17
+ if (!sqlite)
18
+ sqlite = await import('node:sqlite');
19
+ var client = new sqlite.DatabaseSync(connectionString);
20
+ client.poolCount = 0;
21
+ cb(null, client);
22
+ }
23
+ catch(err) {
24
+ return cb(err, null);
25
+ }
26
+ },
27
+
28
+ destroy: function(client) {
29
+ client.poolCount = undefined;
30
+ client.close();
31
+ }
32
+ });
33
+ //monkey-patch with connect method
34
+ pool.connect = function(cb) {
35
+ pool.acquire(function(err, client) {
36
+ if(err) return cb(err, null, function() {/*NOOP*/});
37
+ client.poolCount++;
38
+ cb(null, client, function(err) {
39
+ if(err) {
40
+ pool.destroy(client);
41
+ } else {
42
+ pool.release(client);
43
+ }
44
+ });
45
+ });
46
+ };
47
+ return pool;
48
+ }
49
+
50
+ module.exports = newGenericPool;
@@ -0,0 +1,23 @@
1
+ var log = require('../table/log');
2
+
3
+ function wrapQuery(_context, 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;
@@ -47,7 +47,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
47
47
  return callback(err);
48
48
  }
49
49
  try {
50
- wrapQuery(client)(query, (err, res) => {
50
+ wrapQuery(domain, client)(query, (err, res) => {
51
51
  done();
52
52
  callback(err, res);
53
53
  });
@@ -72,7 +72,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
72
72
  onError(err);
73
73
  return;
74
74
  }
75
- client.executeQuery = wrapQuery(client);
75
+ client.executeQuery = wrapQuery(domain, client);
76
76
  rdb.dbClient = client;
77
77
  rdb.dbClientDone = done;
78
78
  domain.rdb = rdb;
@@ -3,10 +3,7 @@
3
3
 
4
4
  var defaults = require('../../poolDefaults');
5
5
  var genericPool = require('../../generic-pool');
6
- var oracle = require('oracledb');
7
-
8
- oracle.outFormat = oracle.OUT_FORMAT_OBJECT;
9
- oracle.fetchAsBuffer = [ oracle.BLOB ];
6
+ var oracle;
10
7
 
11
8
  function newGenericPool(connectionString, poolOptions) {
12
9
  poolOptions = poolOptions || {};
@@ -15,8 +12,19 @@ function newGenericPool(connectionString, poolOptions) {
15
12
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
16
13
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
17
14
  log: poolOptions.log,
18
- create: function(cb) {
15
+ create: async function(cb) {
19
16
  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
+ }
20
28
  oracle.getConnection(connectionString, onConnected);
21
29
  function onConnected(err, _client) {
22
30
  client = _client;
@@ -1,7 +1,7 @@
1
1
  var log = require('../table/log');
2
2
  var replaceParamChar = require('./replaceParamChar');
3
3
 
4
- function wrapQuery(connection) {
4
+ function wrapQuery(_context, connection) {
5
5
  var runOriginalQuery = connection.execute;
6
6
  return runQuery;
7
7
 
@@ -11,11 +11,6 @@ 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
- });
19
14
 
20
15
  function newDatabase(connectionString, poolOptions) {
21
16
  if (!connectionString)
@@ -44,7 +44,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
44
44
  return callback(err);
45
45
  }
46
46
  try {
47
- wrapQuery(client)(query, (err, res) => {
47
+ wrapQuery(domain, client)(query, (err, res) => {
48
48
  done();
49
49
  callback(err, res);
50
50
  });
@@ -68,7 +68,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
68
68
  onError(err);
69
69
  return;
70
70
  }
71
- client.executeQuery = wrapQuery(client);
71
+ client.executeQuery = wrapQuery(domain, client);
72
72
  rdb.dbClient = client;
73
73
  rdb.dbClientDone = done;
74
74
  domain.rdb = rdb;
@@ -4,12 +4,11 @@ var log = require('../../table/log');
4
4
 
5
5
  var defaults = require('../../poolDefaults');
6
6
  var genericPool = require('../../generic-pool');
7
- var _pg = require('pg');
7
+ var 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;
13
12
 
14
13
  // @ts-ignore
15
14
  var pool = genericPool.Pool({
@@ -17,7 +16,20 @@ function newPgPool(connectionString, poolOptions) {
17
16
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
18
17
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
19
18
  log: poolOptions.log,
20
- create: function(cb) {
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
+ }
21
33
  var client = new pg.Client(connectionString);
22
34
  client.connect(function(err) {
23
35
  if (err) return cb(err, null);
@@ -1,7 +1,7 @@
1
1
  var log = require('../table/log');
2
2
  var replaceParamChar = require('./replaceParamChar');
3
3
 
4
- function wrapQuery(connection) {
4
+ function wrapQuery(_context, connection) {
5
5
  var runOriginalQuery = connection.query;
6
6
  return runQuery;
7
7
 
@@ -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: './src/client/index.mjs',
8
+ file: './dist/index.browser.mjs',
9
9
  format: 'esm',
10
10
  interop: 'auto'
11
11
  },