@dbsp/nql 1.2.0 → 1.3.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 +36 -0
- package/dist/index.js +396 -390
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -59,6 +59,7 @@ orders | group customerId | select customerId, sum(total) as revenue
|
|
|
59
59
|
- **SQL-style literals** — Single-quoted strings (`'value'`), not double-quoted
|
|
60
60
|
- **Named parameters** — Bind runtime values with `:name` in expression positions
|
|
61
61
|
- **CTE support** — `WITH name AS (subquery)` for named subqueries
|
|
62
|
+
- **Mutation support** — Insert, update, delete, upsert, and `insert/upsert ... from ...` pipelines
|
|
62
63
|
- **Schema-aware** — Validates column names and relation paths against `ModelIR` at parse time
|
|
63
64
|
- **LLM-friendly** — Concise syntax designed for AI-generated queries
|
|
64
65
|
- **Chevrotain-based** — Robust lexer + parser with structured error recovery
|
|
@@ -90,6 +91,41 @@ const query = adapter.compile(compiled.ast, { model: db.model });
|
|
|
90
91
|
|
|
91
92
|
Missing params fail compilation. `null` binds SQL `NULL`; `undefined`, `NaN`, and `Infinity` are rejected. The `@dbsp/core` `orm.nql` template tag builds on the same mechanism for `${value}` interpolation. See [Named Parameters and Template Binding](https://oorabona.github.io/db-semantic-planner/nql/#named-parameters-and-template-binding) for the full contract.
|
|
92
93
|
|
|
94
|
+
## Tag mutations
|
|
95
|
+
|
|
96
|
+
The `@dbsp/core` `orm.nql` tag can compile and execute final mutation statements. Use `.dump()` for compile-only inspection; mutation dumps expose `parameters` instead of query dump `params`.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
const mutationDump = orm.nql<unknown>`
|
|
100
|
+
insert into users set name = ${'Alice'}, email = ${'alice@example.com'}
|
|
101
|
+
`.dump() as {
|
|
102
|
+
sql: string;
|
|
103
|
+
parameters: readonly unknown[];
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
console.log(mutationDump.sql);
|
|
107
|
+
console.log(mutationDump.parameters);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Read-only `| bind` statements can feed a final `insert ... from ...` or `upsert ... from ...` mutation:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const pipelineDump = orm.nql<unknown>`posts
|
|
114
|
+
| where published = ${false}
|
|
115
|
+
| select id, title, authorId, published, createdAt
|
|
116
|
+
| bind draft_posts
|
|
117
|
+
insert into posts from draft_posts`
|
|
118
|
+
.dump() as {
|
|
119
|
+
sql: string;
|
|
120
|
+
parameters: readonly unknown[];
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
console.log(pipelineDump.sql);
|
|
124
|
+
console.log(pipelineDump.parameters);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Tag mutation execution uses the normal mutation hooks. Multi-statement tags require every non-final statement to end with `| bind <name>`, and writable mutation bodies inside `| bind` are rejected by the tag executor.
|
|
128
|
+
|
|
93
129
|
## Documentation
|
|
94
130
|
|
|
95
131
|
- [Guides](https://oorabona.github.io/db-semantic-planner/guide/)
|