joist-codegen 2.3.0-next.99 → 2.4.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/build/EntityDbMetadata.cjs +43 -13
- package/build/EntityDbMetadata.cjs.map +1 -1
- package/build/EntityDbMetadata.d.cts +4 -2
- package/build/EntityDbMetadata.d.cts.map +1 -1
- package/build/EntityDbMetadata.d.mts +4 -2
- package/build/EntityDbMetadata.d.mts.map +1 -1
- package/build/EntityDbMetadata.js +41 -11
- package/build/EntityDbMetadata.js.map +1 -1
- package/build/generateEntitiesFile.cjs +1 -1
- package/build/generateEntitiesFile.cjs.map +1 -1
- package/build/generateEntitiesFile.d.cts +1 -1
- package/build/generateEntitiesFile.d.mts +1 -1
- package/build/generateEntitiesFile.js +1 -1
- package/build/generateEntitiesFile.js.map +1 -1
- package/build/generateEntityCodegenFile.cjs +1 -0
- package/build/generateEntityCodegenFile.cjs.map +1 -1
- package/build/generateEntityCodegenFile.d.cts.map +1 -1
- package/build/generateEntityCodegenFile.d.mts.map +1 -1
- package/build/generateEntityCodegenFile.js +1 -0
- package/build/generateEntityCodegenFile.js.map +1 -1
- package/build/generateMetadataFile.cjs +23 -17
- package/build/generateMetadataFile.cjs.map +1 -1
- package/build/generateMetadataFile.d.cts.map +1 -1
- package/build/generateMetadataFile.d.mts.map +1 -1
- package/build/generateMetadataFile.js +23 -17
- package/build/generateMetadataFile.js.map +1 -1
- package/build/index.cjs +6 -6
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts.map +1 -1
- package/build/index.d.mts.map +1 -1
- package/build/index.js +7 -6
- package/build/index.js.map +1 -1
- package/build/inheritance.cjs +1 -0
- package/build/inheritance.cjs.map +1 -1
- package/build/inheritance.d.cts.map +1 -1
- package/build/inheritance.d.mts.map +1 -1
- package/build/inheritance.js +1 -0
- package/build/inheritance.js.map +1 -1
- package/build/loadMetadata.cjs +3 -3
- package/build/loadMetadata.cjs.map +1 -1
- package/build/loadMetadata.d.cts +1 -1
- package/build/loadMetadata.d.mts +1 -1
- package/build/loadMetadata.js +2 -2
- package/build/loadMetadata.js.map +1 -1
- package/build/pgMetadata.cjs +332 -0
- package/build/pgMetadata.cjs.map +1 -0
- package/build/pgMetadata.d.cts +128 -0
- package/build/pgMetadata.d.cts.map +1 -0
- package/build/pgMetadata.d.mts +128 -0
- package/build/pgMetadata.d.mts.map +1 -0
- package/build/pgMetadata.js +320 -0
- package/build/pgMetadata.js.map +1 -0
- package/build/utils.cjs +3 -1
- package/build/utils.cjs.map +1 -1
- package/build/utils.d.cts +4 -2
- package/build/utils.d.cts.map +1 -1
- package/build/utils.d.mts +4 -2
- package/build/utils.d.mts.map +1 -1
- package/build/utils.js +3 -2
- package/build/utils.js.map +1 -1
- package/package.json +12 -3
- package/skills/joist-docs/SKILL.md +1 -1
- package/skills/joist-em-basics/SKILL.md +2 -2
- package/skills/joist-em-execute/SKILL.md +35 -0
- package/skills/joist-em-find/SKILL.md +27 -0
- package/skills/joist-em-query/SKILL.md +32 -0
- package/skills/joist-reactive-hints/SKILL.md +2 -2
|
@@ -72,8 +72,8 @@ const one = await em.findOrCreate(Author, { email: "a@b.com" });
|
|
|
72
72
|
`undefined` values are pruned (the condition and any now-unused join are
|
|
73
73
|
dropped), so filters compose cleanly. To filter for null, pass `null`
|
|
74
74
|
explicitly, e.g. `{ firstName: null }`. For `OR` / nested boolean logic, use
|
|
75
|
-
`alias`/`aliases` with a `conditions` argument.
|
|
76
|
-
|
|
75
|
+
`alias`/`aliases` with a `conditions` argument. See `joist-em-find` for more;
|
|
76
|
+
for aggregates or group-bys, use `joist-em-query` instead.
|
|
77
77
|
|
|
78
78
|
## Mutating
|
|
79
79
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: joist-em-execute
|
|
3
|
+
description: Use when writing bulk or immediate SQL INSERT, UPDATE, or DELETE statements with Joist em.execute, including typed table values, set expressions, and returning rows. Explains when to prefer entity mutations and em.flush and which hooks, validation, and in-memory state immediate writes bypass.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- Managed by joist-codegen. Do not edit by hand; re-run codegen to update. -->
|
|
7
|
+
|
|
8
|
+
# Immediate SQL writes with `em.execute`
|
|
9
|
+
|
|
10
|
+
Prefer mutating entities and calling `em.flush()` so Joist runs validation, hooks, and reactions. Use `em.execute` for bulk SQL writes that must happen immediately:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { table, sql } from "joist-orm";
|
|
14
|
+
|
|
15
|
+
const b = table(Book);
|
|
16
|
+
const inserted = await em.execute({
|
|
17
|
+
insert: b,
|
|
18
|
+
values: [{ title: "New book", authorId: "a:1" }],
|
|
19
|
+
returning: b.id,
|
|
20
|
+
}); // inserted.rows is BookId[]
|
|
21
|
+
|
|
22
|
+
const updated = await em.execute({
|
|
23
|
+
update: b,
|
|
24
|
+
set: { order: sql.number`${b.order} + ${1}` },
|
|
25
|
+
where: b.id.eq("b:1"),
|
|
26
|
+
returning: b.order,
|
|
27
|
+
}); // updated.rows is number[]
|
|
28
|
+
|
|
29
|
+
await em.execute({ delete: b, where: b.id.eq("b:1") });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- `insert` also supports `from: { from: source, select: [...] }` for INSERT ... SELECT. `returning` accepts a column or a named projection; results are in `.rows`.
|
|
33
|
+
- These statements do **not** flush pending entities or run entity hooks, validation, defaults, reactions, updatedAt maintenance, or optimistic locking. Already-loaded entities may be stale afterward; database triggers still run.
|
|
34
|
+
|
|
35
|
+
Full docs: <https://joist-orm.io/features/sql-mutations/>.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: joist-em-find
|
|
3
|
+
description: Use when writing or debugging Joist em.find, findOne, or findOneOrFail entity queries, including relation filters, OR conditions, optional filters, collection joins, and N+1 behavior. For aggregates or custom SELECTs, use joist-em-query instead.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- Managed by joist-codegen. Do not edit by hand; re-run codegen to update. -->
|
|
7
|
+
|
|
8
|
+
# Finding entities with `em.find`
|
|
9
|
+
|
|
10
|
+
Prefer `em.find` for entity SELECTs: Joist automatically batches finds to avoid N+1 queries. Nested relation filters become joins; inline conditions are AND-ed:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
const books = await em.find(Book, {
|
|
14
|
+
author: { firstName: "Alice" },
|
|
15
|
+
publishedAt: { gte: jan1 },
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Operators include `eq`, `ne`, `in`, `gt`, `gte`, `lt`, `lte`, `like`, and `ilike`. Pass an entity or tagged ID to filter a reference.
|
|
20
|
+
- `undefined` drops a condition and any unused join; use explicit `null` for `IS NULL`.
|
|
21
|
+
- For `OR`, bind `alias(Book)` with `{ as: b }` and pass `{ conditions: { or: [b.title.eq("A"), b.title.eq("B")] } }` as the third argument. Bind aliases on joined tables too when conditions span relations.
|
|
22
|
+
- Collection filters usually become `EXISTS` subqueries to avoid duplicate roots. Complex alias conditions may instead use `LEFT JOIN`s; opt into multiple collection left joins only when the fanout is intentional.
|
|
23
|
+
- `findOne` returns `undefined` when absent; `findOneOrFail` throws. Both reject multiple matches.
|
|
24
|
+
- Normal `find` reads the database, not unflushed entity changes; use `findWithNewOrChanged` for flat filters that must include in-memory changes.
|
|
25
|
+
|
|
26
|
+
For aggregates, projections, subqueries, or explicit SQL control, use `joist-em-query`.
|
|
27
|
+
Full docs: <https://joist-orm.io/features/queries-find/>.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: joist-em-query
|
|
3
|
+
description: Use when writing Joist em.query SELECTs that need aggregates, projections, grouping, subqueries, CTEs, or SQL expressions beyond em.find. Covers typed table aliases, joins, select result shapes, pruning, and the fact that every em.query is a database call.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- Managed by joist-codegen. Do not edit by hand; re-run codegen to update. -->
|
|
7
|
+
|
|
8
|
+
# SQL SELECTs with `em.query`
|
|
9
|
+
|
|
10
|
+
Use `em.find` for ordinary entity reads; use `em.query` for SQL-shaped SELECTs. Unlike batched `em.find`, **each `em.query` makes a database call**.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { tables } from "joist-orm";
|
|
14
|
+
|
|
15
|
+
const [a, b] = tables(Author, Book);
|
|
16
|
+
const rows = await em.query({
|
|
17
|
+
from: a,
|
|
18
|
+
join: [a.books.as(b)],
|
|
19
|
+
select: { name: a.firstName, bookCount: b.id.count() },
|
|
20
|
+
groupBy: [a.firstName],
|
|
21
|
+
orderBy: { bookCount: "DESC" },
|
|
22
|
+
}); // { name: string; bookCount: number }[]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- `table(Entity)` / `tables(...)` expose typed columns. Join via relation paths (`a.books.as(b)`), a relation tree, or explicit `{ inner: b, on: ... }` / `{ left: b, on: ... }`.
|
|
26
|
+
- `select: { ... }` returns typed rows; `select: a.id` returns scalar values; `select: a` returns identity-mapped entities (optionally with `populate`). None are auto-batched.
|
|
27
|
+
- Use column methods (`eq`, `gte`, `count`, etc.) in `where`/`having`; compose conditions with `{ and: [...] }` or `{ or: [...] }`. Use `query(...)` for reusable subqueries or CTEs and typed `sql.*` tagged templates for custom SQL.
|
|
28
|
+
- Conditions with `undefined` and joins unused after pruning disappear. Use explicit `null` to filter for SQL NULL; use `keep: true` on a join or `pruneJoins: false` if it must remain.
|
|
29
|
+
- Joins to collections fan out rows. For a yes/no child filter without duplicates, use `exists` or an `in` subquery.
|
|
30
|
+
|
|
31
|
+
For immediate INSERT/UPDATE/DELETE, use `joist-em-execute`.
|
|
32
|
+
Full docs: <https://joist-orm.io/features/queries-raw/>.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
|
-
name: joist-reactive-
|
|
3
|
-
description:
|
|
2
|
+
name: joist-reactive-hints
|
|
3
|
+
description: "Use when diagnosing Joist reactive rule, field, property, or reference performance (addRule, hasReactiveField, hasReactiveProperty, hasReactiveReference), especially unexpected loads during validation or bulk mutations. Reactive hints serve as both reverse-reactivity triggers, finding which roots rerun when a hinted field changes, and forward load hints, populating data before the lambda runs. A child-rooted rule reacting to a parent field can load every sibling during the reverse walk; a parent-rooted rule hinting into children can load the whole child collection before its lambda runs, even if the lambda only reads a parent field. Covers followReverseHint, m2o/o2m traversal, and how to avoid surprise O(children) loads."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Joist reactive hints
|