orange-orm 4.5.0-beta.3 → 4.5.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/README.md +33 -16
- package/docs/changelog.md +2 -0
- package/docs/docs.md +1 -0
- package/package.json +4 -6
- package/src/clsTest.js +0 -79
- package/src/mySql/wrapQueryStream.js +0 -9
- package/src/pg/newStreamableQuery.js +0 -7
- package/src/pg/wrapQueryStream.js +0 -20
- package/src/table/getManyDto/pg/newQuery.js +0 -8
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
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.
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.org/package/orange-orm)
|
|
8
|
-
[](https://github.com/alfateam/orange-orm/actions)
|
|
9
9
|
[](https://github.com/alfateam/orange-orm/actions)
|
|
10
10
|
[](https://github.com/alfateam/orange-orm)
|
|
11
11
|
[](https://github.com/alfateam/orange-orm/discussions)
|
|
@@ -320,22 +320,7 @@ import map from './map';
|
|
|
320
320
|
|
|
321
321
|
const db = map.http('http://localhost:3000/orange');
|
|
322
322
|
```
|
|
323
|
-
__Cloudflare D1__
|
|
324
|
-
<sub>📄 wrangler.toml</sub>
|
|
325
|
-
```toml
|
|
326
|
-
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
|
327
|
-
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
|
|
328
|
-
[[d1_databases]]
|
|
329
|
-
binding = "DB"
|
|
330
|
-
database_name = "<your-name-for-the-database>"
|
|
331
|
-
database_id = "<your-guid-for-the-database>"
|
|
332
|
-
```
|
|
333
323
|
|
|
334
|
-
```javascript
|
|
335
|
-
import map from './map';
|
|
336
|
-
// Must match the binding name in wrangler.toml
|
|
337
|
-
const db = map.d1(env.DB);
|
|
338
|
-
```
|
|
339
324
|
__MySQL__
|
|
340
325
|
```bash
|
|
341
326
|
$ npm install mysql2
|
|
@@ -381,6 +366,38 @@ With schema
|
|
|
381
366
|
import map from './map';
|
|
382
367
|
const db = map.postgres('postgres://postgres:postgres@postgres/postgres?search_path=custom');
|
|
383
368
|
```
|
|
369
|
+
__Cloudflare D1__
|
|
370
|
+
<sub>📄 wrangler.toml</sub>
|
|
371
|
+
```toml
|
|
372
|
+
name = "d1-tutorial"
|
|
373
|
+
main = "src/index.ts"
|
|
374
|
+
compatibility_date = "2025-02-04"
|
|
375
|
+
|
|
376
|
+
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
|
377
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
|
|
378
|
+
[[d1_databases]]
|
|
379
|
+
binding = "DB"
|
|
380
|
+
database_name = "<your-name-for-the-database>"
|
|
381
|
+
database_id = "<your-guid-for-the-database>"
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
<sub>📄 src/index.ts</sub>
|
|
385
|
+
```javascript
|
|
386
|
+
import map from './map';
|
|
387
|
+
|
|
388
|
+
export interface Env {
|
|
389
|
+
// Must match the binding name in wrangler.toml
|
|
390
|
+
DB: D1Database;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export default {
|
|
394
|
+
async fetch(request, env): Promise<Response> {
|
|
395
|
+
const db = map.d1(env.DB);
|
|
396
|
+
const customers = await db.customer.getAll();
|
|
397
|
+
return Response.json(customers);
|
|
398
|
+
},
|
|
399
|
+
} satisfies ExportedHandler<Env>;
|
|
400
|
+
```
|
|
384
401
|
__Oracle__
|
|
385
402
|
```bash
|
|
386
403
|
npm install oracledb
|
package/docs/changelog.md
CHANGED
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orange-orm",
|
|
3
|
-
"version": "4.5.0
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"browser": "./src/client/index.mjs",
|
|
6
6
|
"bin": {
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"@lroal/on-change": "^4.0.2",
|
|
55
55
|
"@tediousjs/connection-string": "^0.4.1",
|
|
56
56
|
"@types/express": "^4.17.13",
|
|
57
|
+
"@cloudflare/workers-types": "^4.20241106.0",
|
|
57
58
|
"@types/oracledb": "^6.0.4",
|
|
58
59
|
"@types/tedious": "^4.0.14",
|
|
59
60
|
"ajv": "^6.10.2",
|
|
@@ -62,10 +63,8 @@
|
|
|
62
63
|
"findup-sync": "^5.0.0",
|
|
63
64
|
"glob": "^10.3.4",
|
|
64
65
|
"module-definition": "^4.0.0",
|
|
65
|
-
"node-cls": "^1.0.5",
|
|
66
66
|
"rfdc": "^1.2.0",
|
|
67
|
-
"uuid": "^8.3.2"
|
|
68
|
-
"wrangler": "^3.107.2"
|
|
67
|
+
"uuid": "^8.3.2"
|
|
69
68
|
},
|
|
70
69
|
"peerDependencies": {
|
|
71
70
|
"msnodesqlv8": "^4.1.0",
|
|
@@ -103,8 +102,7 @@
|
|
|
103
102
|
"optional": true
|
|
104
103
|
}
|
|
105
104
|
},
|
|
106
|
-
"devDependencies": {
|
|
107
|
-
"@cloudflare/workers-types": "^4.20241106.0",
|
|
105
|
+
"devDependencies": {
|
|
108
106
|
"@miniflare/d1": "^2.14.4",
|
|
109
107
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
110
108
|
"@rollup/plugin-json": "^6.1.0",
|
package/src/clsTest.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
let cls = require('node-cls');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const log = (str) => fs.writeSync(1, `${str}\n`);
|
|
4
|
-
|
|
5
|
-
function begin(id) {
|
|
6
|
-
return new Promise((resolve) => {
|
|
7
|
-
let context = cls.get();
|
|
8
|
-
context.id = id;
|
|
9
|
-
resolve();
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getById() {
|
|
14
|
-
return new Promise((resolve) => {
|
|
15
|
-
let context = cls.get();
|
|
16
|
-
context.id;
|
|
17
|
-
resolve(context.id);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function getFromDb() {
|
|
22
|
-
let c = cls.create();
|
|
23
|
-
await c.start();
|
|
24
|
-
await begin(1);
|
|
25
|
-
await new Promise((resolve) => {
|
|
26
|
-
setTimeout(resolve(), 500);
|
|
27
|
-
});
|
|
28
|
-
await getFromDb2();
|
|
29
|
-
|
|
30
|
-
let c3 = cls.create();
|
|
31
|
-
await c3.start();
|
|
32
|
-
await begin(3);
|
|
33
|
-
let id3 = await getById();
|
|
34
|
-
if (id3 !== 3)
|
|
35
|
-
throw new Error('3 Unexpected context id : ' + id3);
|
|
36
|
-
cls.exit();
|
|
37
|
-
|
|
38
|
-
await getFromDb3();
|
|
39
|
-
|
|
40
|
-
let id = await getById();
|
|
41
|
-
if (id !== 1)
|
|
42
|
-
throw new Error('1 Unexpected context id : ' + id);
|
|
43
|
-
cls.exit();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function getFromDb2() {
|
|
47
|
-
return new Promise((resolve) => {
|
|
48
|
-
setTimeout(async () => {
|
|
49
|
-
let c2 = cls.create();
|
|
50
|
-
await c2.start();
|
|
51
|
-
await begin(2);
|
|
52
|
-
let id2 = await getById();
|
|
53
|
-
if (id2 !== 2)
|
|
54
|
-
throw new Error('2 Unexpected context id : ' + id2);
|
|
55
|
-
id2 = cls.active.id;
|
|
56
|
-
if (id2 !== 2)
|
|
57
|
-
throw new Error('2 Unexpected context id : ' + id2);
|
|
58
|
-
cls.exit();
|
|
59
|
-
resolve();
|
|
60
|
-
}, 500);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function getFromDb3() {
|
|
65
|
-
let c3 = cls.create();
|
|
66
|
-
await c3.start();
|
|
67
|
-
await begin(3);
|
|
68
|
-
let id3 = await getById();
|
|
69
|
-
if (id3 !== 3)
|
|
70
|
-
throw new Error('3 Unexpected context id : ' + id3);
|
|
71
|
-
cls.exit();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
async function testStart() {
|
|
76
|
-
await getFromDb();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
testStart().then(() => log('done'), (e) => log(e.stack));
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var log = require('../table/log');
|
|
2
|
-
var replaceParamChar = require('./replaceParamChar');
|
|
3
|
-
var newStreamableQuery = require('./newStreamableQuery');
|
|
4
|
-
|
|
5
|
-
function wrapQueryStream(connection) {
|
|
6
|
-
var runOriginalQuery = connection.query;
|
|
7
|
-
return runQuery;
|
|
8
|
-
|
|
9
|
-
function runQuery(query, options) {
|
|
10
|
-
var params = query.parameters;
|
|
11
|
-
var sql = replaceParamChar(query, params);
|
|
12
|
-
log.emitQuery({sql, parameters: params});
|
|
13
|
-
query = newStreamableQuery(sql, params, options);
|
|
14
|
-
|
|
15
|
-
return runOriginalQuery.call(connection, query);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = wrapQueryStream;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
var newQueryCore = require('../../readStream/pg/newQueryCore');
|
|
2
|
-
|
|
3
|
-
function newQuery() {
|
|
4
|
-
var query = newQueryCore.apply(null, arguments);
|
|
5
|
-
return query.prepend('select json_strip_nulls(coalesce(json_agg(row_to_json(r)), \'[]\')) as result from (').append(') r');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
module.exports = newQuery;
|