orange-orm 4.5.4 → 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 (61) 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 +5 -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/map.d.ts +12 -6
  20. package/src/merge-browser.js +9 -0
  21. package/src/merge-server.js +9 -0
  22. package/src/mssql/newTransaction.js +2 -2
  23. package/src/mssql/pool/newGenericPool.js +10 -2
  24. package/src/mssql/wrapQuery.js +7 -1
  25. package/src/mySql/newTransaction.js +2 -2
  26. package/src/mySql/pool/newGenericPool.js +11 -2
  27. package/src/mySql/wrapQuery.js +1 -1
  28. package/src/nodeSqlite/decodeBinary.js +9 -0
  29. package/src/nodeSqlite/encodeBinary.js +17 -0
  30. package/src/nodeSqlite/newDatabase.js +116 -0
  31. package/src/nodeSqlite/newPool.js +19 -0
  32. package/src/nodeSqlite/newTransaction.js +88 -0
  33. package/src/nodeSqlite/pool/newGenericPool.js +50 -0
  34. package/src/nodeSqlite/wrapQuery.js +23 -0
  35. package/src/oracle/newTransaction.js +2 -2
  36. package/src/oracle/pool/newGenericPool.js +13 -5
  37. package/src/oracle/wrapQuery.js +1 -1
  38. package/src/pg/newDatabase.js +0 -5
  39. package/src/pg/newTransaction.js +2 -2
  40. package/src/pg/pool/newPgPool.js +15 -3
  41. package/src/pg/wrapQuery.js +1 -1
  42. package/src/{client/rollup.config.js → rollup.config.browser.js} +1 -1
  43. package/src/rollup.config.server.js +32 -0
  44. package/src/runtimes.js +24 -0
  45. package/src/sap/newTransaction.js +2 -2
  46. package/src/sqlite3/encodeBuffer.js +7 -0
  47. package/src/sqlite3/newDatabase.js +116 -0
  48. package/src/{sqlite → sqlite3}/newTransaction.js +10 -10
  49. package/src/sqlite3/pool/end.js +13 -0
  50. package/src/{sqlite → sqlite3}/pool/newGenericPool.js +10 -2
  51. package/src/{sqlite → sqlite3}/wrapQuery.js +1 -1
  52. package/src/table/column/binary/newDecode.js +13 -2
  53. package/src/table/column/binary/newEncode.js +16 -6
  54. package/src/table/resultToRows/newDecodeDbRow.js +1 -1
  55. package/src/tedious/newTransaction.js +2 -2
  56. package/src/tedious/pool/newGenericPool.js +8 -2
  57. package/src/tedious/wrapQuery.js +41 -18
  58. package/index.html +0 -100
  59. package/src/client/merge.js +0 -9
  60. /package/src/{sqlite → bunSqlite}/newDatabase.js +0 -0
  61. /package/src/{sqlite → sqlite3}/newPool.js +0 -0
package/README.md CHANGED
@@ -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
26
-
27
- Postgres
28
- MS SQL
29
- MySQL
30
- Oracle
31
- SAP ASE
32
- SQLite
33
- Cloudflare D1
34
-
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 | | | | ✅
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
 
@@ -49,10 +49,6 @@ Watch the [tutorial video on YouTube](https://youtu.be/1IwwjPr2lMs)
49
49
 
50
50
  ![Relations diagram](./docs/diagram.svg)
51
51
 
52
- Here we choose SQLite.
53
- ```bash
54
- npm install sqlite3
55
- ```
56
52
  <sub>📄 map.ts</sub>
57
53
  ```javascript
58
54
  import orange from 'orange-orm';
@@ -279,10 +275,15 @@ In SQLite, columns with the INTEGER PRIMARY KEY attribute are designed to autoin
279
275
 
280
276
  <details><summary><strong>Connecting</strong></summary>
281
277
 
282
- __SQLite__
278
+ __SQLite__
279
+
280
+ **Node.js 21 and earlier**
283
281
  ```bash
284
282
  npm install sqlite3
285
283
  ```
284
+ __Node.js 22+, Bun, or Deno__
285
+ When running Node.js 22 and later, Bun, or Deno, you can use the builtin SQLite dependency and don't need to install sqlite3.
286
+
286
287
  ```javascript
287
288
  import map from './map';
288
289
  const db = map.sqlite('demo.db');
@@ -353,7 +354,8 @@ const db = map.mssql({
353
354
  });
354
355
  ```
355
356
 
356
- __PostgreSQL__
357
+ __PostgreSQL__
358
+ With Bun, you don't need to install the 'pg' package as PostgreSQL support is built-in.
357
359
  ```bash
358
360
  npm install pg
359
361
  ```
@@ -5322,29 +5322,39 @@ function requireNewEncode () {
5322
5322
  hasRequiredNewEncode = 1;
5323
5323
  var purify = requirePurify();
5324
5324
  var newParam = requireNewParameterized();
5325
+ var getSessionSingleton = requireGetSessionSingleton();
5325
5326
 
5326
5327
  function _new(_column) {
5327
5328
 
5328
- function encode(_context, value) {
5329
+ function encode(context, value) {
5329
5330
  value = purify(value);
5330
5331
  if (value === null)
5331
5332
  return newParam('null');
5332
- return newParam('?', [Buffer.from(value, 'base64')]);
5333
+
5334
+ var encodeCore = getSessionSingleton(context, 'encodeBinary') || encodeDefault;
5335
+ const enc = encodeCore(value);
5336
+ return newParam('?', [enc]);
5333
5337
  }
5334
- encode.unsafe = function(_context, value) {
5338
+ encode.unsafe = function(context, value) {
5335
5339
  value = purify(value);
5336
5340
  if (value === null)
5337
5341
  return 'null';
5338
- return Buffer.from(value, 'base64');
5342
+ var encodeCore = getSessionSingleton(context, 'encodeBinary') || encodeDefault;
5343
+ return encodeCore(value);
5339
5344
  };
5340
5345
 
5341
- encode.direct = function(_context, value) {
5342
- return Buffer.from(value, 'base64');
5346
+ encode.direct = function(context, value) {
5347
+ var encodeCore = getSessionSingleton(context, 'encodeBinary') || encodeDefault;
5348
+ return encodeCore(value);
5343
5349
  };
5344
5350
 
5345
5351
  return encode;
5346
5352
  }
5347
5353
 
5354
+ function encodeDefault(base64) {
5355
+ return Buffer.from(base64, 'base64');
5356
+ }
5357
+
5348
5358
  newEncode = _new;
5349
5359
  return newEncode;
5350
5360
  }
@@ -5356,19 +5366,30 @@ function requireNewDecode () {
5356
5366
  if (hasRequiredNewDecode) return newDecode;
5357
5367
  hasRequiredNewDecode = 1;
5358
5368
  var newDecodeCore = requireNewDecodeCore();
5369
+ var getSessionSingleton = requireGetSessionSingleton();
5359
5370
 
5360
5371
  function _new(column) {
5361
5372
  var decodeCore = newDecodeCore(column);
5362
5373
 
5363
5374
  return function(context, value) {
5375
+
5376
+ var toBase64 = getSessionSingleton(context, 'decodeBinary') || toBase64Default;
5377
+
5364
5378
  value = decodeCore(context, value);
5365
5379
  if (value === null)
5366
5380
  return value;
5367
- else
5368
- return value.toString('base64');
5381
+ else {
5382
+ const ret = toBase64(value);
5383
+ return ret;
5384
+ }
5369
5385
  };
5370
5386
  }
5371
5387
 
5388
+ function toBase64Default(buffer) {
5389
+ return buffer.toString('base64');
5390
+
5391
+ }
5392
+
5372
5393
  newDecode = _new;
5373
5394
  return newDecode;
5374
5395
  }
@@ -8093,7 +8114,7 @@ function requireNewDecodeDbRow () {
8093
8114
  for (let i = 0; i < numberOfColumns; i++) {
8094
8115
  let index = offset + i;
8095
8116
  let key = keys[index];
8096
- if (row[key] !== undefined)
8117
+ if (row[key] !== undefined && !isInsert)
8097
8118
  row[key] = columns[i].decode(context, row[key]);
8098
8119
  if (shouldValidate && columns[i].validate)
8099
8120
  columns[i].validate(row[key], row, isInsert);
@@ -12495,7 +12516,7 @@ function requireWrapQuery () {
12495
12516
  hasRequiredWrapQuery = 1;
12496
12517
  var log = requireLog();
12497
12518
 
12498
- function wrapQuery(client) {
12519
+ function wrapQuery(_context, client) {
12499
12520
 
12500
12521
  return runQuery;
12501
12522
 
@@ -13088,7 +13109,7 @@ function requireNewTransaction () {
13088
13109
  return callback(err);
13089
13110
  }
13090
13111
  try {
13091
- wrapQuery(client)(query, (err, res) => {
13112
+ wrapQuery(domain, client)(query, (err, res) => {
13092
13113
  done();
13093
13114
  callback(err, res);
13094
13115
  });
@@ -13112,7 +13133,7 @@ function requireNewTransaction () {
13112
13133
  onError(err);
13113
13134
  return;
13114
13135
  }
13115
- client.executeQuery = wrapQuery(client);
13136
+ client.executeQuery = wrapQuery(domain, client);
13116
13137
  rdb.dbClient = client;
13117
13138
  rdb.dbClientDone = done;
13118
13139
  domain.rdb = rdb;