@lambdaorm/lib 3.5.2 → 3.5.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/CHANGELOG.md +44 -0
- package/README.md +315 -156
- package/connection/infrastructure/adapters/MongoDB.d.ts.map +1 -1
- package/connection/infrastructure/adapters/MongoDB.js +5 -3
- package/connection/infrastructure/adapters/MongoDB.js.map +1 -1
- package/language/infrastructure/adapters/NoSqlDdlBuilder.js +11 -11
- package/language/infrastructure/adapters/NoSqlDdlBuilder.js.map +1 -1
- package/operand/application/services/operandNormalizer.d.ts.map +1 -1
- package/operand/application/services/operandNormalizer.js +2 -1
- package/operand/application/services/operandNormalizer.js.map +1 -1
- package/package.json +2 -2
- package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.d.ts +23 -0
- package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.d.ts.map +1 -1
- package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.js +107 -20
- package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.js.map +1 -1
- package/sentence/infrastructure/adapters/NoSql/config.json +88 -62
- package/sentence/infrastructure/adapters/NoSql/likeRegex.d.ts +13 -0
- package/sentence/infrastructure/adapters/NoSql/likeRegex.d.ts.map +1 -0
- package/sentence/infrastructure/adapters/NoSql/likeRegex.js +49 -0
- package/sentence/infrastructure/adapters/NoSql/likeRegex.js.map +1 -0
- package/sentence/infrastructure/adapters/Sql/SqlDmlBuilder.d.ts.map +1 -1
- package/sentence/infrastructure/adapters/Sql/SqlDmlBuilder.js +8 -2
- package/sentence/infrastructure/adapters/Sql/SqlDmlBuilder.js.map +1 -1
- package/sentence/infrastructure/adapters/Sql/config.json +50 -77
- package/sentence/infrastructure/adapters/base/dmlBuilder.d.ts +7 -0
- package/sentence/infrastructure/adapters/base/dmlBuilder.d.ts.map +1 -1
- package/sentence/infrastructure/adapters/base/dmlBuilder.js +24 -0
- package/sentence/infrastructure/adapters/base/dmlBuilder.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.5.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 054ba46: `first(x)` and `last(x)` as aggregates were written as `FIRST(...)` / `LAST(...)`, which no SQL database has, so the
|
|
8
|
+
query failed in the database. On SQL they are now an error when the query is built, which says why (the order of the
|
|
9
|
+
rows of a group is not defined) and what to use instead (`min` / `max`, or the `.first()` / `.last()` clause of the
|
|
10
|
+
query). MongoDB keeps `$first` / `$last`. The `.first()` / `.last()` clauses don't change.
|
|
11
|
+
- f22f330: An `include` with a filter of its own (`Orders.filter(…).include(p => p.details.filter(d => d.quantity > 5))`) kept only its filter and lost the condition on the parents, so it read the children of every parent; now both apply (`WHERE Quantity > 5 AND OrderID IN (…)`).
|
|
12
|
+
- cd0044e: `includes` has two meanings, as in JavaScript: a list includes a value (`["USA", "Mexico"].includes(p.country)`, an
|
|
13
|
+
`IN`) and a text includes a text (`p.name.includes("fre")`, contains). Which one applied depended on the order of the
|
|
14
|
+
functions in the configuration of each dialect: on SQL Server a list became a `LIKE`, and on MongoDB the pipeline was
|
|
15
|
+
invalid. Now the type of the first operand decides, on every engine: a list, or a variable, is an `IN`; a text (a
|
|
16
|
+
column or any expression of text, such as `upper(p.name)`) is a contains. On MongoDB the text is searched literally
|
|
17
|
+
(`$indexOfCP`), not as a regular expression. The declaration of `includes` for lists is `includes(list, value)`, as it
|
|
18
|
+
works and as the wiki documents.
|
|
19
|
+
- 877dfa7: MongoDB: `startsWith`, `like`, `isNull` and `isNotNull` work in filters (`$match`, and the filters of updates and
|
|
20
|
+
deletes), where they go in a `$expr`, and in maps. `startsWith` and `like` produced invalid JSON (regular expression
|
|
21
|
+
literals), and `isNull`/`isNotNull` an aggregation expression where a query was expected. `like` translates the SQL
|
|
22
|
+
pattern (`%`, `_`, the rest literal) to a regular expression, also when the pattern is a parameter. `addTime` produced
|
|
23
|
+
invalid JSON too; it adds seconds.
|
|
24
|
+
- 9554ac8: MongoDB: functions and operators in a projection that produced invalid pipelines now work — `&`, `|`, `^` and `~` (`$bitAnd`, `$bitOr`, `$bitXor`, `$bitNot`), `trim`, `ltrim`, `rtrim`, `replace`, `substr` / `substring` (1-based, as in SQL), `addYear`, `addMonth`, `addDay`, `addHour`, `addMinute`, `addSecond`, `dayDiff` and the other differences, `toNumber`, `nvl`, `nvl2`, `isNull`, `isNotNull` — and `curTime`, `hour`, `minute`, `second` and `millisecond` exist with the names of the other engines. `includes` on a text in a filter is a regular expression on the field.
|
|
25
|
+
- cff14a4: MongoDB: field, index and sequence names are written as they are, without the SQL delimiters. A composite relation
|
|
26
|
+
whose mapping has a space, is a reserved word or starts with `_` (`Order Details`) was embedded in a field whose name
|
|
27
|
+
included the quotes (`"Order Details"`); it is now embedded in `Order Details`. Index names, the fields of indexes and
|
|
28
|
+
keys, and the `_id` of sequences with those names lose the quotes too, so a sequence with such a name is the one the
|
|
29
|
+
inserts look for. Documents written before with the quoted field must be migrated (rename the field).
|
|
30
|
+
- 317b5f5: MongoDB: a `sort` by a column goes before the `$project` of the map, which removes the columns, so the rows come
|
|
31
|
+
sorted (`Products.map(p => ({ name: p.name })).sort(p => desc(p.price))`); a sort by an alias of the map stays after
|
|
32
|
+
it, with the projected columns by their alias.
|
|
33
|
+
- 0deeb1a: SQL Server: the functions are T-SQL. The dialect had copied Oracle's — `SYSTIMESTAMP`, `TRUNC(SYSDATE)`, `EXTRACT`,
|
|
34
|
+
`ADD_MONTHS`, `interval`, `TO_CHAR`, `NVL`, `NVL2`, `SUBSTR`, `LENGTH`, `LPAD`, `CHR`, `VARCHAR2`, `CAST AS NUMBER`,
|
|
35
|
+
`COSH`, `REMAINDER`, … — which SQL Server doesn't have, so 52 of the 62 functions failed on it. Dates use
|
|
36
|
+
`SYSDATETIME`, `DATEPART`, `DATEADD` and `DATEDIFF`; texts `SUBSTRING`, `LEN`, `REPLICATE`, `CHAR`; nulls `ISNULL` and
|
|
37
|
+
`CASE`. Checked against SQL Server 2022.
|
|
38
|
+
- Updated dependencies [cd0044e]
|
|
39
|
+
- @lambdaorm/base@3.3.2
|
|
40
|
+
|
|
41
|
+
## 3.5.3
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- 7f754d1: PostgreSQL: a `bytea` column is read as `buffer` (`pull`, `fetch` and `introspect` failed with `error with type: bytea`), and a `buffer` property is created as `BYTEA` (it was `BLOB`, which PostgreSQL doesn't have).
|
|
46
|
+
|
|
3
47
|
## 3.5.2
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,164 +1,323 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/lambdaorm)
|
|
3
|
+
# λORM — @lambdaorm/lib
|
|
4
|
+
|
|
5
|
+
**Write a query once. Run it on any database — from your code, a terminal, an API or an AI agent.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@lambdaorm/lib)
|
|
8
|
+
[](https://hub.docker.com/r/flaviorita/data-gateway)
|
|
10
9
|
[](https://opensource.org/licenses/MIT)
|
|
11
|
-
[](https://www.npmjs.com/package/lambdaorm-cli)
|
|
14
|
-
[](https://lambda-orm.github.io/wiki/api/index.md)
|
|
15
|
-
|
|
16
|
-
λORM is an ORM that allows us to perform distributed queries on different database engines.
|
|
17
|
-
|
|
18
|
-
In λORM, queries are defined using lambda expressions based on a domain model which abstracts us from the infrastructure. For example, in a query you can obtain or modify records from different entities, where some persist in MySQL, others in Postgres, and others in Mongo.
|
|
19
|
-
|
|
20
|
-
λORM allows you to define different scenarios for the same domain. For example, in one scenario, the infrastructure may consist of distributed instances across SQL Server, MongoDB, and Oracle, while in another scenario it may be a single Postgres instance. This allows the [CQRS](https://microservices.io/patterns/data/cqrs.html) pattern to be implemented through configuration, without needing to write a single line of code. [view example](https://github.com/lambda-orm/lambdaorm-labs/tree/main/labs/svc/04-northwind-cqrs-with-kafka)
|
|
21
|
-
|
|
22
|
-
In addition to being used as a Node.js library, it can be consumed from a command line interface (CLI), a REST service, or a REST service client in other programming languages.
|
|
23
|
-
|
|
24
|
-
## Query Language
|
|
25
|
-
|
|
26
|
-
Example of a query where orders and their details associated with a customer are obtained:
|
|
27
|
-
|
|
28
|
-
```Typescript
|
|
29
|
-
const query = (country: string) => Products
|
|
30
|
-
.map(p => ({ category: p.category.name, largestPrice: max(p.price) }))
|
|
31
|
-
.filter(p => (p.price > 5 && p.supplier.country == country) || (p.inStock < 3))
|
|
32
|
-
.having(p => max(p.price) > 50)
|
|
33
|
-
.sort(p => desc(p.largestPrice));
|
|
34
|
-
// Run the query passing the value of the country parameter
|
|
35
|
-
const result = await orm.execute(query, { country: 'ARG' });
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
In this example:
|
|
39
|
-
|
|
40
|
-
- Define a query that returns a list of product categories along with the maximum price of each category.
|
|
41
|
-
- Filter products based on price and supplier's country or stock availability
|
|
42
|
-
- Group products by category and calculate the maximum price
|
|
43
|
-
- Map each product to an object with category name and maximum price
|
|
44
|
-
- Sort the products by largest price in descending order
|
|
45
|
-
|
|
46
|
-
**view:** [queries](https://lambda-orm.github.io/wiki/queries/Query-Language) |
|
|
47
|
-
[select](https://lambda-orm.github.io/wiki/queries/dql/Select) |
|
|
48
|
-
[join](https://lambda-orm.github.io/wiki/queries/dql/Join) |
|
|
49
|
-
[grouping](https://lambda-orm.github.io/wiki/queries/dql/Grouping) |
|
|
50
|
-
[include](https://lambda-orm.github.io/wiki/queries/dql/Include) |
|
|
51
|
-
[insert](https://lambda-orm.github.io/wiki/queries/dml/Insert) |
|
|
52
|
-
[bulkInsert](https://lambda-orm.github.io/wiki/queries/dmlBulkInsert) |
|
|
53
|
-
[update](https://lambda-orm.github.io/wiki/queries/dml/Update) |
|
|
54
|
-
[delete](https://lambda-orm.github.io/wiki/queries/dml/Delete) |
|
|
55
|
-
[repository](https://lambda-orm.github.io/wiki/Repository) |
|
|
56
|
-
[usage](https://lambda-orm.github.io/wiki/Usage) |
|
|
57
|
-
[metadata](https://lambda-orm.github.io/wiki/queries/Metadata)
|
|
58
|
-
|
|
59
|
-
### Include
|
|
60
|
-
|
|
61
|
-
The include allows us to obtain the entity data and its relationships in the same query. These data may be in different databases. \
|
|
62
|
-
In this example the query is expressed as a text string. (Which is another alternative to the lambda expression)
|
|
63
|
-
|
|
64
|
-
```Typescript
|
|
65
|
-
import { orm } from '../../lib'
|
|
66
|
-
(async () => {
|
|
67
|
-
try {
|
|
68
|
-
await orm.init('./config/northwind.yaml')
|
|
69
|
-
const query = `Orders
|
|
70
|
-
.filter(p => p.id === id)
|
|
71
|
-
.include(p =>
|
|
72
|
-
[ p.customer.map(p => p.name),
|
|
73
|
-
p.details
|
|
74
|
-
.include(p =>
|
|
75
|
-
p.product
|
|
76
|
-
.include(p => p.category.map(p => p.name))
|
|
77
|
-
.map(p => p.name))
|
|
78
|
-
.map(p => [p.quantity, p.unitPrice])
|
|
79
|
-
]
|
|
80
|
-
)`
|
|
81
|
-
const params = { id: 102 }
|
|
82
|
-
const result = await orm.execute(query, params, { stage: 'PostgreSQL' })
|
|
83
|
-
console.log(JSON.stringify(result, null, 2))
|
|
84
|
-
} catch (error:any) {
|
|
85
|
-
console.error(error.message)
|
|
86
|
-
} finally {
|
|
87
|
-
await orm.end()
|
|
88
|
-
}
|
|
89
|
-
})()
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
**Result:**
|
|
93
|
-
|
|
94
|
-
```json
|
|
95
|
-
[
|
|
96
|
-
{
|
|
97
|
-
"id": 102,
|
|
98
|
-
"customerId": "SPLIR",
|
|
99
|
-
"employeeId": 7,
|
|
100
|
-
"orderDate": "1996-11-07T23:00:00.000Z",
|
|
101
|
-
"requiredDate": "1996-12-05T23:00:00.000Z",
|
|
102
|
-
"shippedDate": "1996-11-14T23:00:00.000Z",
|
|
103
|
-
"shipViaId": 1,
|
|
104
|
-
"freight": 8.63,
|
|
105
|
-
"name": "Split Rail Beer & Ale",
|
|
106
|
-
"address": "P.O. Box 555",
|
|
107
|
-
"city": "Lander",
|
|
108
|
-
"region": "WY",
|
|
109
|
-
"postalCode": "82520",
|
|
110
|
-
"country": "USA",
|
|
111
|
-
"customer": {
|
|
112
|
-
"name": "Split Rail Beer & Ale"
|
|
113
|
-
},
|
|
114
|
-
"details": [
|
|
115
|
-
{
|
|
116
|
-
"quantity": 24,
|
|
117
|
-
"unitPrice": 5.9,
|
|
118
|
-
"product": {
|
|
119
|
-
"name": "Tourtire",
|
|
120
|
-
"category": {
|
|
121
|
-
"name": "Meat/Poultry"
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
]
|
|
126
|
-
}
|
|
127
|
-
]
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
**more info:** [include](https://lambda-orm.github.io/wiki/Include)
|
|
131
|
-
|
|
132
|
-
## Schema Configuration
|
|
133
|
-
|
|
134
|
-
Through the schema, you can define entities, enumerations, indexes, unique keys, default values, constraints, mapping, sources, stages, listeners, etc. The schema can be defined in a JSON or YAML format. Conditions or actions are performed using the same [expression language](https://www.npmjs.com/package/3xpr) that is used to define queries.
|
|
135
|
-
|
|
136
|
-
**view:** [schema](https://lambda-orm.github.io/wiki/schema/Schema) |
|
|
137
|
-
[definition](https://lambda-orm.github.io/wiki/schema/Definition/SchemaDefinition) |
|
|
138
|
-
[use](https://lambda-orm.github.io/wiki/schema/Schema-Use) |
|
|
139
|
-
[expressions](https://lambda-orm.github.io/wiki/schema/Definition/SchemaDefinition-Expressions) |
|
|
140
|
-
[environment Variables](https://lambda-orm.github.io/wiki/schema/Definition/SchemaDefinition-EnvironmentVariables) |
|
|
141
|
-
[composite](https://lambda-orm.github.io/wiki/schema/Definition/SchemaDefinition-Composite) |
|
|
142
|
-
[listener](https://lambda-orm.github.io/wiki/schema/Examples/SchemaExample-Listener) |
|
|
143
|
-
[multiple stages](https://lambda-orm.github.io/wiki/schema/Examples/SchemaExample-MultiplesStages) |
|
|
144
|
-
[multiple sources](https://lambda-orm.github.io/wiki/schema/Examples/SchemaExample-StageMultiplesSources) |
|
|
145
|
-
[push](https://lambda-orm.github.io/wiki/schema/Examples/SchemaSynchronization-Push) |
|
|
146
|
-
[pull](https://lambda-orm.github.io/wiki/schema/Examples/SchemaSynchronization-Pull) |
|
|
147
|
-
[fetch](https://lambda-orm.github.io/wiki/schema/Examples/SchemaSynchronization-Fetch) |
|
|
148
|
-
[introspect](https://lambda-orm.github.io/wiki/schema/Examples/SchemaSynchronization-Introspect) |
|
|
149
|
-
[incorporate](https://lambda-orm.github.io/wiki/schema/Examples/SchemaSynchronization-Incorporate)
|
|
10
|
+
[](https://github.com/lambda-orm/wiki/discussions)
|
|
11
|
+
[](https://discord.com/invite/yXT6XBX2)
|
|
150
12
|
|
|
151
|
-
|
|
13
|
+
📖 **Documentation:** [lambda-orm.github.io/wiki](https://lambda-orm.github.io/wiki) (English, Deutsch, Español, Português)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
λORM is a query language and a runtime for your data. You describe your **domain** once (entities, relations,
|
|
18
|
+
rules) and write queries as **lambda expressions** over it:
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
Orders
|
|
22
|
+
.filter(p => p.customer.country == country && p.orderDate >= since)
|
|
23
|
+
.include(p => [p.customer.map(c => c.name), p.details.include(d => d.product.map(p => p.name))])
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
λORM turns that query into SQL for **MySQL, MariaDB, PostgreSQL, SQL Server, Oracle and SQLite**, or into an
|
|
27
|
+
aggregation pipeline for **MongoDB** — even when the entities of one query live in **different databases**. And the
|
|
28
|
+
same query runs **from a Node library, the command line, a REST or WebSocket API, or an AI agent through MCP**.
|
|
29
|
+
|
|
30
|
+
## Why λORM
|
|
31
|
+
|
|
32
|
+
- 🧩 **One domain, any database.** Your queries talk about `Orders` and `Customers`, not about tables, dialects or
|
|
33
|
+
where each entity is stored.
|
|
34
|
+
- 🌐 **One query across several databases.** Orders in MongoDB, customers in PostgreSQL, products in MySQL: one
|
|
35
|
+
query, one result. λORM splits it per source and joins the results.
|
|
36
|
+
- 🎭 **Stages.** The same domain on one SQLite in development and distributed over three engines in production —
|
|
37
|
+
or a write side and a read side ([CQRS](https://microservices.io/patterns/data/cqrs.html)) — by configuration, not
|
|
38
|
+
code.
|
|
39
|
+
- 🔌 **Every channel.** TypeScript (typed), a string, the CLI, REST, WebSocket, MCP: the same language everywhere.
|
|
40
|
+
- 🔐 **Governed access.** The [Data Gateway](https://lambda-orm.github.io/wiki/data-gateway/) publishes your schemas
|
|
41
|
+
with credentials, permissions (`read`, `write`, …) and an audit of every change — for applications, people and AI
|
|
42
|
+
agents alike.
|
|
43
|
+
- 🛠️ **Schema-first, both ways.** From a YAML to the tables (`push`), from the databases to the YAML (`pull`), or
|
|
44
|
+
from a JSON file of data to a schema, tables and rows (`incorporate`).
|
|
45
|
+
|
|
46
|
+
## Use it as a library
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
npm install @lambdaorm/lib
|
|
50
|
+
npm install mysql2 # the driver of your database: mysql2, pg, tedious, oracledb, mongodb or sql.js
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { orm } from '@lambdaorm/lib'
|
|
55
|
+
import { Orders } from './northwind/domain/model' // generated by `lambdaorm build`, or written by hand
|
|
56
|
+
|
|
57
|
+
await orm.init('./lambdaORM.yaml') // the schema: domain, sources, mappings, stages
|
|
58
|
+
try {
|
|
59
|
+
// a typed lambda…
|
|
60
|
+
const orders = await orm.execute(
|
|
61
|
+
(customerId: string) => Orders.filter(p => p.customerId == customerId).include(p => p.details),
|
|
62
|
+
{ customerId: 'ALFKI' })
|
|
63
|
+
|
|
64
|
+
// …or the same query as a string (from a file, a request, an agent)
|
|
65
|
+
const count = await orm.execute('Orders.filter(p => p.customerId == customerId).map(p => count(1))', { customerId: 'ALFKI' })
|
|
66
|
+
|
|
67
|
+
// several writes in one transaction
|
|
68
|
+
await orm.transaction({}, async tr => {
|
|
69
|
+
const order = await tr.execute('Orders.insert().include(p => p.details)', newOrder)
|
|
70
|
+
await tr.execute('Products.update(p => ({ inStock: p.inStock - quantity })).filter(p => p.id == productId)', { productId: 11, quantity: 2 })
|
|
71
|
+
})
|
|
72
|
+
} finally {
|
|
73
|
+
await orm.end()
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`orm.plan(query)` shows the sentences without running them, and `orm.metadata(query)` what the query returns and
|
|
78
|
+
needs. See [Usage](https://lambda-orm.github.io/wiki/usage/Usage/),
|
|
79
|
+
[Repository](https://lambda-orm.github.io/wiki/usage/Repository/) and
|
|
80
|
+
[Transaction](https://lambda-orm.github.io/wiki/usage/Transaction/).
|
|
81
|
+
|
|
82
|
+
## The same query, from everywhere
|
|
83
|
+
|
|
84
|
+
<table>
|
|
85
|
+
<tr><td><b>Node.js / TypeScript</b> — <a href="https://www.npmjs.com/package/@lambdaorm/lib"><code>@lambdaorm/lib</code></a></td></tr>
|
|
86
|
+
<tr><td>
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { orm } from '@lambdaorm/lib'
|
|
90
|
+
|
|
91
|
+
await orm.init('./lambdaORM.yaml')
|
|
92
|
+
const products = await orm.execute(
|
|
93
|
+
(minPrice: number) => Products.filter(p => p.price > minPrice).map(p => [p.name, p.price]),
|
|
94
|
+
{ minPrice: 50 })
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
</td></tr>
|
|
98
|
+
<tr><td><b>Command line</b> — <a href="https://www.npmjs.com/package/@lambdaorm/cli"><code>@lambdaorm/cli</code></a></td></tr>
|
|
99
|
+
<tr><td>
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
lambdaorm execute -q "Products.filter(p => p.price > minPrice).map(p => [p.name, p.price])" -d '{"minPrice": 50}'
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
</td></tr>
|
|
106
|
+
<tr><td><b>REST API</b> — the <a href="https://lambda-orm.github.io/wiki/data-gateway/">Data Gateway</a>, from any language</td></tr>
|
|
107
|
+
<tr><td>
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
curl -X POST http://gateway:8080/northwind/execute -H "X-Api-Key: $KEY" -H "Content-Type: application/json" \
|
|
111
|
+
-d '{"query": "Products.filter(p => p.price > minPrice).map(p => [p.name, p.price])", "data": {"minPrice": 50}}'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
import requests
|
|
116
|
+
|
|
117
|
+
products = requests.post("http://gateway:8080/northwind/execute", headers={"X-Api-Key": key}, json={
|
|
118
|
+
"query": "Products.filter(p => p.price > minPrice).map(p => [p.name, p.price])",
|
|
119
|
+
"data": {"minPrice": 50},
|
|
120
|
+
}).json()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
</td></tr>
|
|
124
|
+
<tr><td><b>Node client</b> — <a href="https://www.npmjs.com/package/@lambdaorm/client"><code>@lambdaorm/client</code></a>, over REST or WebSocket</td></tr>
|
|
125
|
+
<tr><td>
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { orm } from '@lambdaorm/client'
|
|
129
|
+
|
|
130
|
+
await orm.init('ws://gateway:8083/northwind', { headers: { 'X-Api-Key': key } })
|
|
131
|
+
const products = await orm.execute('Products.filter(p => p.price > minPrice).map(p => [p.name, p.price])', { minPrice: 50 })
|
|
132
|
+
orm.on('schema.statusChanged', ({ status }) => console.log(status))
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
</td></tr>
|
|
136
|
+
<tr><td><b>AI agents</b> — <a href="https://lambda-orm.github.io/wiki/data-gateway/Mcp/">MCP</a></td></tr>
|
|
137
|
+
<tr><td>
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
claude mcp add --transport http northwind http://gateway:8081/northwind/mcp --header "X-Api-Key: $KEY"
|
|
141
|
+
```
|
|
152
142
|
|
|
153
|
-
|
|
143
|
+
> *"Which products cost more than 50?"* — the agent reads the domain of the schema from the tools and calls
|
|
144
|
+
> `orm_execute` with `Products.filter(p => p.price > 50).map(p => [p.name, p.price])`. With a `read` credential, it
|
|
145
|
+
> can't change anything.
|
|
154
146
|
|
|
155
|
-
|
|
147
|
+
</td></tr>
|
|
148
|
+
<tr><td><b>The browser</b> — the <a href="https://lambda-orm.github.io/wiki/data-gateway/Ui/">UI</a> of the Data Gateway</td></tr>
|
|
149
|
+
<tr><td>
|
|
150
|
+
|
|
151
|
+

|
|
152
|
+
|
|
153
|
+
</td></tr>
|
|
154
|
+
</table>
|
|
155
|
+
|
|
156
|
+
## One query, three databases
|
|
157
|
+
|
|
158
|
+
A stage of the [northwind lab](https://github.com/lambda-orm/lambdaorm-labs/tree/main/labs/cli/06-northwind-multiples-datasources)
|
|
159
|
+
keeps the catalog in MySQL, the customers in PostgreSQL and the orders in MongoDB:
|
|
160
|
+
|
|
161
|
+
```yaml
|
|
162
|
+
stages:
|
|
163
|
+
- name: default
|
|
164
|
+
sources:
|
|
165
|
+
- name: Catalog # MySQL
|
|
166
|
+
condition: entity.in(["Categories","Products"])
|
|
167
|
+
- name: Crm # PostgreSQL
|
|
168
|
+
condition: entity.in(["Address","Customers"])
|
|
169
|
+
- name: Ordering # MongoDB
|
|
170
|
+
condition: entity.in(["Orders","Orders.details"])
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The application doesn't know it. It asks for the orders of a customer with the name of the customer and, for each
|
|
174
|
+
line, the product and its category:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
Orders
|
|
178
|
+
.filter(p => p.customerId == customerId)
|
|
179
|
+
.include(p => [
|
|
180
|
+
p.customer.map(c => c.name),
|
|
181
|
+
p.details
|
|
182
|
+
.include(d => d.product.include(pr => pr.category.map(c => c.name)).map(pr => pr.name))
|
|
183
|
+
.map(d => [d.quantity, d.unitPrice])
|
|
184
|
+
])
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
and `orm.plan` shows what λORM will run (abridged):
|
|
188
|
+
|
|
189
|
+
```text
|
|
190
|
+
Orders MongoDB Ordering aggregate [{ $match: { CustomerID: … } }, { $project: … }]
|
|
191
|
+
├─ Customers PostgreSQL Crm SELECT c.CompanyName AS "name", … FROM Customers c WHERE c.CustomerID IN ($1)
|
|
192
|
+
└─ Orders.details MongoDB Ordering aggregate [{ $unwind: … }, { $match: { OrderID: { $in: … } } }, …]
|
|
193
|
+
└─ Products MySQL Catalog SELECT p.ProductName AS name, … FROM Products p WHERE p.ProductID IN (?)
|
|
194
|
+
└─ Categories MySQL Catalog SELECT c1.CategoryName AS name, … FROM Categories c1 WHERE c1.CategoryID IN (?)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**One query per relation, never one per row:** each level reads the keys of the level above with an `IN`. When there
|
|
198
|
+
are many, the keys are split into chunks — at most 999 on Oracle, 7000 on the others — that run in parallel. The
|
|
199
|
+
result is one JSON tree, as if everything were in one database.
|
|
200
|
+
|
|
201
|
+
## One query, each engine's dialect
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
Products
|
|
205
|
+
.filter(p => p.price > minPrice && p.category.name == category)
|
|
206
|
+
.map(p => ({ name: p.name, price: p.price }))
|
|
207
|
+
.sort(p => desc(p.price))
|
|
208
|
+
.page(1, 10)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
```sql
|
|
212
|
+
-- MySQL
|
|
213
|
+
SELECT p.ProductName AS name, p.UnitPrice AS price FROM Products p INNER JOIN Categories c ON c.CategoryID = p.CategoryID
|
|
214
|
+
WHERE (p.UnitPrice > ? AND c.CategoryName = ?) ORDER BY p.UnitPrice desc LIMIT 0,10
|
|
215
|
+
|
|
216
|
+
-- PostgreSQL
|
|
217
|
+
SELECT p.ProductName AS "name", p.UnitPrice AS "price" FROM Products p INNER JOIN Categories c ON c.CategoryID = p.CategoryID
|
|
218
|
+
WHERE (p.UnitPrice > $1 AND c.CategoryName = $2) ORDER BY p.UnitPrice desc OFFSET 0 LIMIT 10
|
|
219
|
+
|
|
220
|
+
-- SQL Server
|
|
221
|
+
SELECT p.ProductName AS name, p.UnitPrice AS price FROM Products p INNER JOIN Categories c ON c.CategoryID = p.CategoryID
|
|
222
|
+
WHERE (p.UnitPrice > @minPrice AND c.CategoryName = @category) ORDER BY p.UnitPrice desc OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY
|
|
223
|
+
|
|
224
|
+
-- Oracle
|
|
225
|
+
SELECT p.ProductName AS "name", p.UnitPrice AS "price" FROM Products p INNER JOIN Categories c ON c.CategoryID = p.CategoryID
|
|
226
|
+
WHERE (p.UnitPrice > :minPrice AND c.CategoryName = :category) ORDER BY p.UnitPrice desc OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
The join is implicit (`p.category.name`), the parameters are always bound, and the property names are the domain's
|
|
230
|
+
(`price`), not the columns' (`UnitPrice`): the [mapping](https://lambda-orm.github.io/wiki/schema/SchemaDefinition/)
|
|
231
|
+
lives in the schema. The [engines lab](https://github.com/lambda-orm/core/tree/main/packages/lib/src/dev/labs/engines) runs the same tests on PostgreSQL, MySQL,
|
|
232
|
+
MariaDB, SQL Server, Oracle and MongoDB.
|
|
233
|
+
|
|
234
|
+
## Stages: the same code, another infrastructure
|
|
235
|
+
|
|
236
|
+
```yaml
|
|
237
|
+
infrastructure:
|
|
238
|
+
stages:
|
|
239
|
+
- name: dev # everything in one database
|
|
240
|
+
sources: [ { name: Local } ]
|
|
241
|
+
- name: prod # the same domain, spread over three engines
|
|
242
|
+
sources:
|
|
243
|
+
- { name: Catalog, condition: 'entity.in(["Categories","Products"])' }
|
|
244
|
+
- { name: Crm, condition: 'entity.in(["Address","Customers"])' }
|
|
245
|
+
- { name: Ordering, condition: 'entity.in(["Orders","Orders.details"])' }
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
await orm.execute(query, data, { stage: 'prod' })
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
A write stage and a read stage over different databases is [CQRS by configuration](https://lambda-orm.github.io/wiki/schema/SchemaExample-MultiplesStages/).
|
|
253
|
+
|
|
254
|
+
## Governed access: the Data Gateway
|
|
255
|
+
|
|
256
|
+
The [Data Gateway](https://lambda-orm.github.io/wiki/data-gateway/) (Docker
|
|
257
|
+
[`flaviorita/data-gateway`](https://hub.docker.com/r/flaviorita/data-gateway)) publishes one or several schemas over
|
|
258
|
+
REST, WebSocket and MCP, with a web UI — no backend to write:
|
|
259
|
+
|
|
260
|
+
```yaml
|
|
261
|
+
authentication:
|
|
262
|
+
adapter: local
|
|
263
|
+
type: apikey
|
|
264
|
+
keys:
|
|
265
|
+
- { name: agent, value: $AGENT_KEY, permissions: [ read ] }
|
|
266
|
+
- { name: backend, value: $BACKEND_KEY, permissions: [ read, write, script ] }
|
|
267
|
+
transports:
|
|
268
|
+
http: { port: 8080, ui: { enabled: true } } # REST, OpenAPI, the UI
|
|
269
|
+
mcpHttp: { port: 8081 } # AI agents
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
- The same permissions on every transport: an agent with `read` can query, never write.
|
|
273
|
+
- Every write leaves an audit line: who, what, which entities, how many rows.
|
|
274
|
+
- Each schema in its own worker; Prometheus metrics, health probes for Kubernetes, rate and size limits.
|
|
275
|
+
|
|
276
|
+
**Try it in ten minutes:** [Getting started](https://lambda-orm.github.io/wiki/data-gateway/GettingStarted/), from
|
|
277
|
+
an empty folder to the REST API, the UI, MCP and WebSocket.
|
|
278
|
+
|
|
279
|
+
## And more
|
|
280
|
+
|
|
281
|
+
- **[Scripts](https://lambda-orm.github.io/wiki/usage/Script/):** a whole use case — variables, conditions, loops and
|
|
282
|
+
several queries — in one transaction and one call, from Node, the CLI or the gateway.
|
|
283
|
+
- **[Transactions](https://lambda-orm.github.io/wiki/usage/Transaction/)** across sources and stages.
|
|
284
|
+
- **Writes with their children:** `Orders.insert().include(p => p.details)`, `bulkInsert`, `upsert`, and updates of
|
|
285
|
+
composite relations.
|
|
286
|
+
- **[Synchronization](https://lambda-orm.github.io/wiki/schema/SchemaSynchronization/):** `push`, `pull`, `fetch`,
|
|
287
|
+
`introspect`, `incorporate`.
|
|
288
|
+
- **[Repositories](https://lambda-orm.github.io/wiki/usage/Repository/)** and a typed model generated from the schema
|
|
289
|
+
(`lambdaorm build`).
|
|
290
|
+
- **[Listeners](https://lambda-orm.github.io/wiki/schema/SchemaExample-Listener/), constraints, default values and
|
|
291
|
+
computed properties**, written in the same expression language.
|
|
292
|
+
|
|
293
|
+
## The λORM family
|
|
294
|
+
|
|
295
|
+
| Package | Published as | What it is |
|
|
296
|
+
| --- | --- | --- |
|
|
297
|
+
| [`lib`](https://github.com/lambda-orm/core/tree/main/packages/lib) | [`@lambdaorm/lib`](https://www.npmjs.com/package/@lambdaorm/lib) | the ORM: runs the queries against the databases (this package) |
|
|
298
|
+
| [`cli`](https://github.com/lambda-orm/core/tree/main/packages/cli) | [`@lambdaorm/cli`](https://www.npmjs.com/package/@lambdaorm/cli) | the `lambdaorm` command: projects, synchronization, import / export, queries, scripts |
|
|
299
|
+
| [`data-gateway`](https://github.com/lambda-orm/core/tree/main/packages/data-gateway) | Docker [`flaviorita/data-gateway`](https://hub.docker.com/r/flaviorita/data-gateway) | the schemas over REST, MCP, WebSocket, with a web UI |
|
|
300
|
+
| [`client`](https://github.com/lambda-orm/core/tree/main/packages/client) | [`@lambdaorm/client`](https://www.npmjs.com/package/@lambdaorm/client) | the interface of the library, run on a Data Gateway |
|
|
301
|
+
| [`ui`](https://github.com/lambda-orm/core/tree/main/packages/ui) | [`@lambdaorm/ui`](https://www.npmjs.com/package/@lambdaorm/ui) | React components: the query editor, results, explorer and diagrams |
|
|
302
|
+
| [`base`](https://github.com/lambda-orm/core/tree/main/packages/base) | [`@lambdaorm/base`](https://www.npmjs.com/package/@lambdaorm/base) | the contracts shared by the packages |
|
|
303
|
+
|
|
304
|
+
## Get started
|
|
305
|
+
|
|
306
|
+
| I want to… | Start here |
|
|
307
|
+
| --- | --- |
|
|
308
|
+
| query my databases from Node / TypeScript | [Usage](https://lambda-orm.github.io/wiki/usage/Usage/) |
|
|
309
|
+
| create a project, sync the databases, import data | [CLI](https://lambda-orm.github.io/wiki/cli/) |
|
|
310
|
+
| give applications in any language, or AI agents, access to my data | [Data Gateway: getting started](https://lambda-orm.github.io/wiki/data-gateway/GettingStarted/) |
|
|
311
|
+
| learn the query language | [Query language](https://lambda-orm.github.io/wiki/queries/Query-Language/) |
|
|
312
|
+
| see complete examples | [Labs](https://github.com/lambda-orm/lambdaorm-labs) |
|
|
313
|
+
|
|
314
|
+
## Contributing
|
|
156
315
|
|
|
157
|
-
|
|
316
|
+
Questions, ideas and feedback are welcome in [GitHub Discussions](https://github.com/lambda-orm/wiki/discussions);
|
|
317
|
+
issues and pull requests in [github.com/lambda-orm/core](https://github.com/lambda-orm/core) (against `develop`). Read the
|
|
318
|
+
[contribution guidelines](https://github.com/lambda-orm/wiki/blob/main/CONTRIBUTING.md). Commits follow
|
|
319
|
+
[Conventional Commits](https://www.conventionalcommits.org/).
|
|
158
320
|
|
|
159
|
-
##
|
|
321
|
+
## License
|
|
160
322
|
|
|
161
|
-
|
|
162
|
-
- [Lambda ORM Service](https://lambda-orm.github.io/wiki/api/index): REST service for λORM
|
|
163
|
-
- [Client Node](https://www.npmjs.com/package/lambdaorm-client-node): HTTP client for λORM
|
|
164
|
-
- [3xpr](https://www.npmjs.com/package/3xpr): Extensible expression engine, which allows evaluating mathematical and logical expressions.
|
|
323
|
+
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoDB.d.ts","sourceRoot":"","sources":["../../../../../src/lib/connection/infrastructure/adapters/MongoDB.ts"],"names":[],"mappings":"AAEA,OAA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,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;IAa1G,WAAW,CAAE,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;IAsB5G,WAAW,CAAE,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;IAuB5G,UAAU,CAAE,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;IAuB3G,OAAO,CAAE,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;YA0BvG,eAAe;YAKf,WAAW;CAazB"}
|
|
@@ -7,6 +7,7 @@ const connectionPool_1 = require("./base/connectionPool");
|
|
|
7
7
|
const connection_1 = require("./base/connection");
|
|
8
8
|
const base_1 = require("@lambdaorm/base");
|
|
9
9
|
const typ3s_1 = require("typ3s");
|
|
10
|
+
const likeRegex_1 = require("../../../sentence/infrastructure/adapters/NoSql/likeRegex");
|
|
10
11
|
class MongoDBConnectionPoolAdapter extends connectionPool_1.ConnectionPoolAdapter {
|
|
11
12
|
constructor(config, helper) {
|
|
12
13
|
super(config, helper);
|
|
@@ -125,7 +126,7 @@ class MongodbConnectionAdapter extends connection_1.ConnectionAdapter {
|
|
|
125
126
|
if (relationEntity.mapping === undefined) {
|
|
126
127
|
throw new base_1.SchemaError(`EntityMapping ${include.relation.entity} not found`);
|
|
127
128
|
}
|
|
128
|
-
const relationEntityMapping =
|
|
129
|
+
const relationEntityMapping = relationEntity.mapping;
|
|
129
130
|
for (let i = 0; i < array.length; i++) {
|
|
130
131
|
const source = array[i];
|
|
131
132
|
const target = list[i];
|
|
@@ -183,7 +184,7 @@ class MongodbConnectionAdapter extends connection_1.ConnectionAdapter {
|
|
|
183
184
|
if (relationEntity.mapping === undefined) {
|
|
184
185
|
throw new base_1.SchemaError(`EntityMapping ${include.relation.entity} not found`);
|
|
185
186
|
}
|
|
186
|
-
const relationProperty =
|
|
187
|
+
const relationProperty = relationEntity.mapping;
|
|
187
188
|
if (include.relation.type === base_1.RelationType.manyToOne) {
|
|
188
189
|
const childList = [];
|
|
189
190
|
for (const child of children) {
|
|
@@ -285,7 +286,8 @@ class MongodbConnectionAdapter extends connection_1.ConnectionAdapter {
|
|
|
285
286
|
else {
|
|
286
287
|
result = template;
|
|
287
288
|
}
|
|
288
|
-
|
|
289
|
+
// a LIKE whose pattern is a parameter becomes its regular expression once the parameter is set
|
|
290
|
+
return result && typeof result === 'string' ? (0, likeRegex_1.solveLikeMarkers)(JSON.parse(result)) : undefined;
|
|
289
291
|
}
|
|
290
292
|
getValue(mapping, dialect, source, type) {
|
|
291
293
|
let value;
|