@prisma/orm-mongo 8.0.0-rc.16-dev.2 → 8.0.0-rc.16-dev.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/orm-mongo",
|
|
3
|
-
"version": "8.0.0-rc.16-dev.
|
|
3
|
+
"version": "8.0.0-rc.16-dev.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
"skills"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@prisma/orm-family-mongo": "8.0.0-rc.16-dev.
|
|
14
|
-
"@prisma/orm-framework": "8.0.0-rc.16-dev.
|
|
15
|
-
"@prisma/orm-target-mongo": "8.0.0-rc.16-dev.
|
|
16
|
-
"@prisma/orm-toolchain": "8.0.0-rc.16-dev.
|
|
13
|
+
"@prisma/orm-family-mongo": "8.0.0-rc.16-dev.3",
|
|
14
|
+
"@prisma/orm-framework": "8.0.0-rc.16-dev.3",
|
|
15
|
+
"@prisma/orm-target-mongo": "8.0.0-rc.16-dev.3",
|
|
16
|
+
"@prisma/orm-toolchain": "8.0.0-rc.16-dev.3",
|
|
17
17
|
"mongodb-connection-string-url": "^7.0.1",
|
|
18
18
|
"pathe": "^2.0.3",
|
|
19
19
|
"tinyglobby": "^0.2.17"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@internal/mongo": "8.0.0-rc.16-dev.
|
|
23
|
-
"@repo/tsconfig": "8.0.0-rc.16-dev.
|
|
24
|
-
"@repo/tsdown": "8.0.0-rc.16-dev.
|
|
22
|
+
"@internal/mongo": "8.0.0-rc.16-dev.3",
|
|
23
|
+
"@repo/tsconfig": "8.0.0-rc.16-dev.3",
|
|
24
|
+
"@repo/tsdown": "8.0.0-rc.16-dev.3",
|
|
25
25
|
"tsdown": "0.22.14",
|
|
26
26
|
"typescript": "5.9.3"
|
|
27
27
|
},
|
package/skills/prisma-8/SKILL.md
CHANGED
|
@@ -574,6 +574,28 @@ await db.transaction(async (tx) => {
|
|
|
574
574
|
|
|
575
575
|
The callback's return value passes through `db.transaction(...)`. Capture inserted ids out of the callback and use them downstream after commit.
|
|
576
576
|
|
|
577
|
+
To read a row and then write it without another transaction changing it in between, lock it when you read it. The lock lasts until the transaction ends; outside a transaction it is released when the statement ends.
|
|
578
|
+
|
|
579
|
+
```typescript
|
|
580
|
+
await db.transaction(async (tx) => {
|
|
581
|
+
// ORM: locks only the model's own rows (`FOR UPDATE OF "product"`).
|
|
582
|
+
const product = await tx.orm.public.Product.where({ id }).forUpdate().first();
|
|
583
|
+
|
|
584
|
+
// SQL builder: the same lock on a plan.
|
|
585
|
+
const [row] = await tx.query(
|
|
586
|
+
tx.sql.public.product.select('id', 'stock').where((f, fns) => fns.eq(f.id, id)).forUpdate().build(),
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
// Work queue: claim the next unclaimed job, skipping jobs other workers hold.
|
|
590
|
+
const job = await tx.orm.public.Job.where({ state: 'queued' })
|
|
591
|
+
.orderBy((j) => j.createdAt.asc())
|
|
592
|
+
.forUpdate({ skipLocked: true })
|
|
593
|
+
.first();
|
|
594
|
+
});
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
The four methods are `forUpdate()`, `forNoKeyUpdate()`, `forShare()` and `forKeyShare()`, each with `{ nowait: true }` or `{ skipLocked: true }`. On the ORM a lock cannot be combined with `include`, `groupBy`, `aggregate`, `distinct`, `distinctOn` or a mutation terminal (`ORM.LOCK_INCOMPATIBLE`).
|
|
598
|
+
|
|
577
599
|
## Namespace-aware accessors
|
|
578
600
|
|
|
579
601
|
On Postgres both `db.sql` and `db.orm` are keyed by storage namespace (the Postgres schema) — always, not only when a contract declares more than one. A model outside any `namespace { }` block is in `public`:
|
|
@@ -607,6 +629,7 @@ Cross-namespace relations (e.g. `public.Profile` → `auth.User`) follow the sam
|
|
|
607
629
|
10. **Mixing the ORM mutation return with `runtime.query(plan)` / `runtime.execute(plan)`.** ORM terminals issue the query themselves and return rows. The runtime methods are for SQL-builder plans.
|
|
608
630
|
11. **Adding a `cursor()` to a relation, count, operation or `nulls` order.** It throws `ORM.ARGUMENT_INVALID`. Use `.limit(n).offset(n)`, or order by plain columns.
|
|
609
631
|
12. **Ordering grouped rows by an aggregate metric.** The grouped collection supports `.orderBy(...)` on group keys plus `.limit(...)` / `.offset(...)`, but it cannot order by an aggregate alias such as `SUM(amount)`. Sorting the materialized aggregate result in JS is fine at small cardinalities; for large grouped result sets, drop to `db.sql.<ns>.<table>`.
|
|
632
|
+
13. **Locking a parent row with `forUpdate()` while other transactions write rows that reference it.** Every insert or update of a row with a foreign key to the locked row takes `FOR KEY SHARE` on it to check the key, and `FOR KEY SHARE` conflicts with `FOR UPDATE`, so those writes wait and can deadlock. Use `forNoKeyUpdate()`: it still blocks writes to the row, but not the foreign-key check.
|
|
610
633
|
|
|
611
634
|
## Reference Files
|
|
612
635
|
|