orange-orm 3.10.2 → 3.10.4
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 +40 -10
- package/docs/changelog.md +8 -4
- package/docs/diagram.svg +12 -0
- package/package.json +1 -1
- package/src/client/index.mjs +1580 -1016
- package/src/getTSDefinition.js +16 -12
- package/src/mssql/newTransaction.js +1 -0
- package/src/mySql/newTransaction.js +1 -0
- package/src/oracle/newTransaction.js +1 -0
- package/src/patchTable.js +4 -1
- package/src/pg/newTransaction.js +1 -0
- package/src/sap/newTransaction.js +1 -0
- package/src/sqlite/newTransaction.js +1 -0
- package/src/table/clearCache.js +7 -0
- package/src/table/getSessionCache.js +8 -0
- package/src/table/newRowCache.js +4 -4
- package/src/table/relation/newExpanderCache.js +2 -0
- package/src/table/relation/newManyCache.js +4 -4
- package/src/table/setSessionCache.js +8 -0
- package/src/tedious/newTransaction.js +1 -0
- package/docs/relations.png +0 -0
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ $ npm install orange-orm
|
|
|
46
46
|
## Example
|
|
47
47
|
Watch the [tutorial video on YouTube](https://youtu.be/1IwwjPr2lMs)
|
|
48
48
|
|
|
49
|
-

|
|
50
50
|
|
|
51
51
|
Here we choose SQLite.
|
|
52
52
|
```bash
|
|
@@ -77,6 +77,12 @@ const map = orange.map(x => ({
|
|
|
77
77
|
amount: column('amount').numeric(),
|
|
78
78
|
})),
|
|
79
79
|
|
|
80
|
+
package: x.table('package').map(({ column }) => ({
|
|
81
|
+
id: column('packageId').numeric().primary().notNullExceptInsert(),
|
|
82
|
+
lineId: column('lineId').numeric().notNullExceptInsert(),
|
|
83
|
+
sscc: column('sscc').string() //the barcode
|
|
84
|
+
})),
|
|
85
|
+
|
|
80
86
|
deliveryAddress: x.table('deliveryAddress').map(({ column }) => ({
|
|
81
87
|
id: column('id').numeric().primary(),
|
|
82
88
|
orderId: column('orderId').numeric(),
|
|
@@ -87,6 +93,10 @@ const map = orange.map(x => ({
|
|
|
87
93
|
countryCode: column('countryCode').string(),
|
|
88
94
|
}))
|
|
89
95
|
|
|
96
|
+
})).map(x => ({
|
|
97
|
+
orderLine: x.orderLine.map(({ hasMany }) => ({
|
|
98
|
+
packages: hasMany(x.package).by('lineId')
|
|
99
|
+
}))
|
|
90
100
|
})).map(x => ({
|
|
91
101
|
order: x.order.map(v => ({
|
|
92
102
|
customer: v.references(x.customer).by('customerId'),
|
|
@@ -130,8 +140,10 @@ async function getRows() {
|
|
|
130
140
|
const orders = await db.order.getAll({
|
|
131
141
|
where: x => x.lines.any(line => line.product.contains('broomstick'))
|
|
132
142
|
.and(db.order.customer.name.startsWith('Harry')),
|
|
133
|
-
lines:
|
|
134
|
-
|
|
143
|
+
lines: {
|
|
144
|
+
packages: true
|
|
145
|
+
},
|
|
146
|
+
deliveryAddress: true,
|
|
135
147
|
customer: true
|
|
136
148
|
});
|
|
137
149
|
}
|
|
@@ -145,7 +157,7 @@ async function getRows() {
|
|
|
145
157
|
|
|
146
158
|
Each column within your database table is designated by using the <strong><i>column()</i></strong> method, in which you specify its name. This action generates a reference to a column object that enables you to articulate further column properties like its data type or if it serves as a primary key.
|
|
147
159
|
|
|
148
|
-
Relationships between tables can also be outlined. By using methods like <strong><i>hasOne</i></strong>, <strong><i>hasMany</i></strong>, and <strong><i>references</i></strong>, you can establish connections that reflect the relationships in your data schema. In the example below, an 'order' is linked to a 'customer' reference, a 'deliveryAddress', and multiple 'lines'. The hasMany and hasOne relations represents ownership - the tables 'deliveryAddress' and 'orderLine' are owned by the 'order' table, and therefore, they contain the 'orderId' column referring to their parent table, which is 'order'. Conversely, the customer table is independent and can exist without any knowledge of the 'order' table. Therefore we say that the order table <i>references</i> the customer table - necessitating the existence of a 'customerId' column in the 'order' table.</p>
|
|
160
|
+
Relationships between tables can also be outlined. By using methods like <strong><i>hasOne</i></strong>, <strong><i>hasMany</i></strong>, and <strong><i>references</i></strong>, you can establish connections that reflect the relationships in your data schema. In the example below, an 'order' is linked to a 'customer' reference, a 'deliveryAddress', and multiple 'lines'. The hasMany and hasOne relations represents ownership - the tables 'deliveryAddress' and 'orderLine' are owned by the 'order' table, and therefore, they contain the 'orderId' column referring to their parent table, which is 'order'. The similar relationship exists between orderLine and package - hence the packages are owned by the orderLine. Conversely, the customer table is independent and can exist without any knowledge of the 'order' table. Therefore we say that the order table <i>references</i> the customer table - necessitating the existence of a 'customerId' column in the 'order' table.</p>
|
|
149
161
|
|
|
150
162
|
<sub>📄 map.ts</sub>
|
|
151
163
|
```javascript
|
|
@@ -171,6 +183,12 @@ const map = orange.map(x => ({
|
|
|
171
183
|
product: column('product').string(),
|
|
172
184
|
})),
|
|
173
185
|
|
|
186
|
+
package: x.table('package').map(({ column }) => ({
|
|
187
|
+
id: column('packageId').numeric().primary().notNullExceptInsert(),
|
|
188
|
+
lineId: column('lineId').numeric().notNullExceptInsert(),
|
|
189
|
+
sscc: column('sscc').string() //the barcode
|
|
190
|
+
})),
|
|
191
|
+
|
|
174
192
|
deliveryAddress: x.table('deliveryAddress').map(({ column }) => ({
|
|
175
193
|
id: column('id').numeric().primary(),
|
|
176
194
|
orderId: column('orderId').numeric(),
|
|
@@ -181,6 +199,10 @@ const map = orange.map(x => ({
|
|
|
181
199
|
countryCode: column('countryCode').string(),
|
|
182
200
|
}))
|
|
183
201
|
|
|
202
|
+
})).map(x => ({
|
|
203
|
+
orderLine: x.orderLine.map(({ hasMany }) => ({
|
|
204
|
+
packages: hasMany(x.package).by('lineId')
|
|
205
|
+
}))
|
|
184
206
|
})).map(x => ({
|
|
185
207
|
order: x.order.map(({ hasOne, hasMany, references }) => ({
|
|
186
208
|
customer: references(x.customer).by('customerId'),
|
|
@@ -225,6 +247,12 @@ CREATE TABLE orderLine (
|
|
|
225
247
|
amount NUMERIC(10,2)
|
|
226
248
|
);
|
|
227
249
|
|
|
250
|
+
CREATE TABLE package (
|
|
251
|
+
packageId INTEGER PRIMARY KEY,
|
|
252
|
+
lineId INTEGER REFERENCES orderLine,
|
|
253
|
+
sscc TEXT
|
|
254
|
+
);
|
|
255
|
+
|
|
228
256
|
CREATE TABLE deliveryAddress (
|
|
229
257
|
id INTEGER PRIMARY KEY,
|
|
230
258
|
orderId INTEGER REFERENCES _order,
|
|
@@ -329,7 +357,7 @@ $ npm install pg
|
|
|
329
357
|
```
|
|
330
358
|
```javascript
|
|
331
359
|
import map from './map';
|
|
332
|
-
const db = map.
|
|
360
|
+
const db = map.postgres('postgres://postgres:postgres@postgres/postgres');
|
|
333
361
|
```
|
|
334
362
|
__Oracle__
|
|
335
363
|
```bash
|
|
@@ -497,12 +525,14 @@ async function getRows() {
|
|
|
497
525
|
const orders = await db.order.getAll({
|
|
498
526
|
customer: true,
|
|
499
527
|
deliveryAddress: true,
|
|
500
|
-
lines:
|
|
528
|
+
lines: {
|
|
529
|
+
packages: true
|
|
530
|
+
}
|
|
501
531
|
});
|
|
502
532
|
}
|
|
503
533
|
```
|
|
504
534
|
__Limit, offset and order by__
|
|
505
|
-
This script demonstrates how to fetch orders with customer, lines and deliveryAddress, limiting the results to 10, skipping the first row, and sorting the data based on the orderDate in descending order followed by id. The lines are sorted by product.
|
|
535
|
+
This script demonstrates how to fetch orders with customer, lines, packages and deliveryAddress, limiting the results to 10, skipping the first row, and sorting the data based on the orderDate in descending order followed by id. The lines are sorted by product.
|
|
506
536
|
|
|
507
537
|
```javascript
|
|
508
538
|
import map from './map';
|
|
@@ -518,6 +548,7 @@ async function getRows() {
|
|
|
518
548
|
customer: true,
|
|
519
549
|
deliveryAddress: true,
|
|
520
550
|
lines: {
|
|
551
|
+
packages: true,
|
|
521
552
|
orderBy: 'product'
|
|
522
553
|
},
|
|
523
554
|
});
|
|
@@ -593,7 +624,7 @@ getRows();
|
|
|
593
624
|
|
|
594
625
|
async function getRows() {
|
|
595
626
|
const order = await db.order.getOne(undefined /* optional filter */, {
|
|
596
|
-
where: x => x.
|
|
627
|
+
where: x => x.customer(customer => customer.isActive.eq(true)
|
|
597
628
|
.and(customer.startsWith('Harr'))),
|
|
598
629
|
customer: true,
|
|
599
630
|
deliveryAddress: true,
|
|
@@ -616,7 +647,6 @@ async function getRows() {
|
|
|
616
647
|
});
|
|
617
648
|
}
|
|
618
649
|
```
|
|
619
|
-
```
|
|
620
650
|
|
|
621
651
|
__Single row by primary key__
|
|
622
652
|
|
|
@@ -1795,7 +1825,7 @@ async function getRows() {
|
|
|
1795
1825
|
```
|
|
1796
1826
|
</details>
|
|
1797
1827
|
|
|
1798
|
-
<details><summary><strong>Aggregate functions</strong></summary>
|
|
1828
|
+
<details id="aggregates"><summary><strong>Aggregate functions</strong></summary>
|
|
1799
1829
|
|
|
1800
1830
|
You can count records and aggregate numerical columns. This can either be done across rows or separately for each row.
|
|
1801
1831
|
Supported functions include:
|
package/docs/changelog.md
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
## Changelog
|
|
2
|
-
__3.10.
|
|
2
|
+
__3.10.4__
|
|
3
|
+
Bugfix: "Changed by Other User" Error Triggered by Precision Mismatch in Numeric Column. See [#120](https://github.com/alfateam/orange-orm/issues/120)
|
|
4
|
+
__3.10.3__
|
|
5
|
+
Fix duplicate method signatures for those still using code generation
|
|
6
|
+
__3.10.2__
|
|
3
7
|
Orange ORM was renamed from rdb. New installation url: [npmjs.org/package/orange-orm](https://npmjs.org/package/orange-orm) . Old url was npmjs.org/package/rdb
|
|
4
|
-
__3.10.
|
|
8
|
+
__3.10.1__
|
|
5
9
|
Bugfix: Adding hasOne row to existing parent throws. See [#86](https://github.com/alfateam/orange-orm/issues/86)
|
|
6
|
-
__3.10.
|
|
10
|
+
__3.10.0__
|
|
7
11
|
Aggregate functions
|
|
8
|
-
__3.9.
|
|
12
|
+
__3.9.1__
|
|
9
13
|
Bugfix: Crashing on many relations if foreign key column is omitted in strategy. See [#83](https://github.com/alfateam/orange-orm/issues/83)
|
|
10
14
|
__3.9.0__
|
|
11
15
|
Possible to elevate associated column on a related table to a parent table when fetching. See https://github.com/alfateam/orange-orm/#user-content-aggregate-results
|