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 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
  [![npm version](https://img.shields.io/npm/v/orange-orm.svg?style=flat-square)](https://www.npmjs.org/package/orange-orm)
8
- [![Build status](https://github.com/alfateam/orange-orm/workflows/Node.js%20CI/badge.svg)](https://github.com/alfateam/orange-orm/actions)
8
+ [![Build status](https://github.com/alfateam/orange-orm/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/alfateam/orange-orm/actions)
9
9
  [![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/lroal/1a69422f03da7f8155cf94fe66022452/raw/rdb__heads_master.json)](https://github.com/alfateam/orange-orm/actions)
10
10
  [![Github](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/lroal/1ccb2b79abbe0258d636e9b5e4630a1a/raw/rdb__heads_master.json)](https://github.com/alfateam/orange-orm)
11
11
  [![GitHub Discussions](https://img.shields.io/github/discussions/alfateam/orange-orm)](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
@@ -1,4 +1,6 @@
1
1
  ## Changelog
2
+ __4.5.0__
3
+ Support for Cloudflare D1.
2
4
  __4.4.2__
3
5
  Support for schema in connection string. Postgrs only. [#116](https://github.com/alfateam/orange-orm/issues/118)
4
6
  __4.4.1__
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-beta.3",
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,9 +0,0 @@
1
- function wrapQueryStream(connection) {
2
- return runQuery;
3
-
4
- function runQuery(query, options) {
5
- return connection.executeQuery(query).stream(options);
6
- }
7
- }
8
-
9
- module.exports = wrapQueryStream;
@@ -1,7 +0,0 @@
1
- var QueryStream;
2
-
3
- module.exports = function(sql, params) {
4
- if (!QueryStream)
5
- QueryStream = require('pg-query-stream');
6
- return new QueryStream(sql, params);
7
- };
@@ -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;