orange-orm 4.8.2 → 4.9.0

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.
package/dist/index.mjs CHANGED
@@ -18102,27 +18102,42 @@ var hasRequiredWrapQuery$4;
18102
18102
  function requireWrapQuery$4 () {
18103
18103
  if (hasRequiredWrapQuery$4) return wrapQuery_1$4;
18104
18104
  hasRequiredWrapQuery$4 = 1;
18105
- var log = requireLog();
18105
+ const log = requireLog();
18106
+ const connectionCache = new WeakMap();
18106
18107
 
18107
18108
  function wrapQuery(_context, connection) {
18108
- var runOriginalQuery = connection.all;
18109
+ let statementCache = connectionCache.get(connection);
18110
+ if (!statementCache) {
18111
+ statementCache = new Map();
18112
+ connectionCache.set(connection, statementCache);
18113
+ }
18114
+
18109
18115
  return runQuery;
18110
18116
 
18111
18117
  function runQuery(query, onCompleted) {
18112
- var params = query.parameters;
18113
- var sql = query.sql();
18114
- log.emitQuery({sql, parameters: params});
18118
+ try {
18119
+ var params = query.parameters;
18120
+ var sql = query.sql();
18121
+ log.emitQuery({ sql, parameters: params });
18115
18122
 
18116
- runOriginalQuery.call(connection, sql, params, onInnerCompleted);
18123
+ let statement = statementCache.get(sql);
18124
+ if (!statement) {
18125
+ statement = connection.prepare(sql);
18126
+ statementCache.set(sql, statement);
18127
+ }
18117
18128
 
18118
- function onInnerCompleted(err, rows) {
18119
- if (err)
18120
- onCompleted(err);
18121
- else
18129
+ if (statement.reader) {
18130
+ const rows = statement.all.apply(statement, params);
18122
18131
  onCompleted(null, rows);
18132
+ } else {
18133
+ statement.run.apply(statement, params);
18134
+ onCompleted(null, []);
18135
+ }
18136
+ }
18137
+ catch (e) {
18138
+ onCompleted(e);
18123
18139
  }
18124
18140
  }
18125
-
18126
18141
  }
18127
18142
 
18128
18143
  wrapQuery_1$4 = wrapQuery;
@@ -18136,9 +18151,14 @@ function requireWrapCommand$4 () {
18136
18151
  if (hasRequiredWrapCommand$4) return wrapCommand_1$4;
18137
18152
  hasRequiredWrapCommand$4 = 1;
18138
18153
  var log = requireLog();
18154
+ var connectionCache = new WeakMap();
18139
18155
 
18140
18156
  function wrapCommand(_context, connection) {
18141
- var runOriginalQuery = connection.run;
18157
+ var statementCache = connectionCache.get(connection);
18158
+ if (!statementCache) {
18159
+ statementCache = new Map();
18160
+ connectionCache.set(connection, statementCache);
18161
+ }
18142
18162
  return runQuery;
18143
18163
 
18144
18164
  function runQuery(query, onCompleted) {
@@ -18146,14 +18166,23 @@ function requireWrapCommand$4 () {
18146
18166
  var sql = query.sql();
18147
18167
  log.emitQuery({ sql, parameters: params });
18148
18168
 
18149
- runOriginalQuery.call(connection, sql, params, function onInnerCompleted(err) {
18150
- if (err) {
18151
- onCompleted(err);
18152
- } else {
18153
- var affectedRows = typeof this.changes === 'number' ? this.changes : 0;
18154
- onCompleted(null, { rowsAffected: affectedRows });
18169
+ try {
18170
+ var statement = statementCache.get(sql);
18171
+ if (!statement) {
18172
+ statement = connection.prepare(sql);
18173
+ statementCache.set(sql, statement);
18155
18174
  }
18156
- });
18175
+ var info = statement.run.apply(statement, params);
18176
+ var affected = info && typeof info.changes === 'number' ? info.changes : 0;
18177
+ var insertId = info && typeof info.lastInsertRowid !== 'undefined' ? info.lastInsertRowid : undefined;
18178
+ if (typeof insertId !== 'undefined')
18179
+ onCompleted(null, { rowsAffected: affected, lastInsertRowid: insertId });
18180
+ else
18181
+ onCompleted(null, { rowsAffected: affected });
18182
+ }
18183
+ catch (e) {
18184
+ onCompleted(e);
18185
+ }
18157
18186
  }
18158
18187
  }
18159
18188
 
@@ -18320,20 +18349,20 @@ function requireNewGenericPool$4 () {
18320
18349
  create: async function(cb) {
18321
18350
  try {
18322
18351
  if (!sqlite)
18323
- sqlite = await import('sqlite3');
18352
+ sqlite = await import('better-sqlite3');
18324
18353
  sqlite = sqlite.default || sqlite;
18325
18354
  }
18326
18355
  catch (err) {
18327
18356
  return cb(err, null);
18328
18357
  }
18329
- var client = new sqlite.Database(connectionString, onConnected);
18330
-
18331
- function onConnected(err) {
18332
- if(err)
18333
- return cb(err, null);
18358
+ try {
18359
+ var client = new sqlite(connectionString);
18334
18360
  client.poolCount = 0;
18335
18361
  return cb(null, client);
18336
18362
  }
18363
+ catch (err) {
18364
+ return cb(err, null);
18365
+ }
18337
18366
  },
18338
18367
 
18339
18368
  destroy: function(client) {
package/docs/changelog.md CHANGED
@@ -1,4 +1,7 @@
1
1
  ## Changelog
2
+ __4.9.0__
3
+ Node.js 22.5+: Continues using built-in `node:sqlite` (no action needed)
4
+ Node.js 18-22.4: Now requires `better-sqlite3` instead of `sqlite3`
2
5
  __4.8.2__
3
6
  Slight performance gain on updates and removed accidental console.dir
4
7
  __4.8.1__
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.8.2",
3
+ "version": "4.9.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -93,7 +93,7 @@
93
93
  "oracledb": "^6.3.0",
94
94
  "pg": "^8.5.1",
95
95
  "pg-query-stream": "^3.3.2",
96
- "sqlite3": "^5.0.2",
96
+ "better-sqlite3": "^11.8.1",
97
97
  "tedious": "^15.1.2 || ^16.0.0 || ^18.1.0 || || ^19.0.0"
98
98
  },
99
99
  "peerDependenciesMeta": {
@@ -106,7 +106,7 @@
106
106
  "mysql2": {
107
107
  "optional": true
108
108
  },
109
- "sqlite3": {
109
+ "better-sqlite3": {
110
110
  "optional": true
111
111
  },
112
112
  "pg-native": {
@@ -144,7 +144,7 @@
144
144
  "pg": "^8.5.1",
145
145
  "pg-query-stream": "^3.3.2",
146
146
  "rollup": "^2.52.7",
147
- "sqlite3": "^5.0.2",
147
+ "better-sqlite3": "^11.8.1",
148
148
  "tedious": "^19.0.0",
149
149
  "typescript": "^5.4.5",
150
150
  "vitest": "^3.2.4"
@@ -15,20 +15,20 @@ function newGenericPool(connectionString, poolOptions) {
15
15
  create: async function(cb) {
16
16
  try {
17
17
  if (!sqlite)
18
- sqlite = await import('sqlite3');
18
+ sqlite = await import('better-sqlite3');
19
19
  sqlite = sqlite.default || sqlite;
20
20
  }
21
21
  catch (err) {
22
22
  return cb(err, null);
23
23
  }
24
- var client = new sqlite.Database(connectionString, onConnected);
25
-
26
- function onConnected(err) {
27
- if(err)
28
- return cb(err, null);
24
+ try {
25
+ var client = new sqlite(connectionString);
29
26
  client.poolCount = 0;
30
27
  return cb(null, client);
31
28
  }
29
+ catch (err) {
30
+ return cb(err, null);
31
+ }
32
32
  },
33
33
 
34
34
  destroy: function(client) {
@@ -53,4 +53,4 @@ function newGenericPool(connectionString, poolOptions) {
53
53
  return pool;
54
54
  }
55
55
 
56
- module.exports = newGenericPool;
56
+ module.exports = newGenericPool;
@@ -1,7 +1,12 @@
1
1
  var log = require('../table/log');
2
+ var connectionCache = new WeakMap();
2
3
 
3
4
  function wrapCommand(_context, connection) {
4
- var runOriginalQuery = connection.run;
5
+ var statementCache = connectionCache.get(connection);
6
+ if (!statementCache) {
7
+ statementCache = new Map();
8
+ connectionCache.set(connection, statementCache);
9
+ }
5
10
  return runQuery;
6
11
 
7
12
  function runQuery(query, onCompleted) {
@@ -9,14 +14,23 @@ function wrapCommand(_context, connection) {
9
14
  var sql = query.sql();
10
15
  log.emitQuery({ sql, parameters: params });
11
16
 
12
- runOriginalQuery.call(connection, sql, params, function onInnerCompleted(err) {
13
- if (err) {
14
- onCompleted(err);
15
- } else {
16
- var affectedRows = typeof this.changes === 'number' ? this.changes : 0;
17
- onCompleted(null, { rowsAffected: affectedRows });
17
+ try {
18
+ var statement = statementCache.get(sql);
19
+ if (!statement) {
20
+ statement = connection.prepare(sql);
21
+ statementCache.set(sql, statement);
18
22
  }
19
- });
23
+ var info = statement.run.apply(statement, params);
24
+ var affected = info && typeof info.changes === 'number' ? info.changes : 0;
25
+ var insertId = info && typeof info.lastInsertRowid !== 'undefined' ? info.lastInsertRowid : undefined;
26
+ if (typeof insertId !== 'undefined')
27
+ onCompleted(null, { rowsAffected: affected, lastInsertRowid: insertId });
28
+ else
29
+ onCompleted(null, { rowsAffected: affected });
30
+ }
31
+ catch (e) {
32
+ onCompleted(e);
33
+ }
20
34
  }
21
35
  }
22
36
 
@@ -1,24 +1,39 @@
1
- var log = require('../table/log');
1
+ const log = require('../table/log');
2
+ const connectionCache = new WeakMap();
2
3
 
3
4
  function wrapQuery(_context, connection) {
4
- var runOriginalQuery = connection.all;
5
+ let statementCache = connectionCache.get(connection);
6
+ if (!statementCache) {
7
+ statementCache = new Map();
8
+ connectionCache.set(connection, statementCache);
9
+ }
10
+
5
11
  return runQuery;
6
12
 
7
13
  function runQuery(query, onCompleted) {
8
- var params = query.parameters;
9
- var sql = query.sql();
10
- log.emitQuery({sql, parameters: params});
14
+ try {
15
+ var params = query.parameters;
16
+ var sql = query.sql();
17
+ log.emitQuery({ sql, parameters: params });
11
18
 
12
- runOriginalQuery.call(connection, sql, params, onInnerCompleted);
19
+ let statement = statementCache.get(sql);
20
+ if (!statement) {
21
+ statement = connection.prepare(sql);
22
+ statementCache.set(sql, statement);
23
+ }
13
24
 
14
- function onInnerCompleted(err, rows) {
15
- if (err)
16
- onCompleted(err);
17
- else
25
+ if (statement.reader) {
26
+ const rows = statement.all.apply(statement, params);
18
27
  onCompleted(null, rows);
28
+ } else {
29
+ statement.run.apply(statement, params);
30
+ onCompleted(null, []);
31
+ }
32
+ }
33
+ catch (e) {
34
+ onCompleted(e);
19
35
  }
20
36
  }
21
-
22
37
  }
23
38
 
24
- module.exports = wrapQuery;
39
+ module.exports = wrapQuery;