@prisma-next/cli 0.3.0-pr.99.6 → 0.4.0-dev.1
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/LICENSE +201 -0
- package/README.md +381 -128
- package/dist/agent-skill-mongo.md +106 -0
- package/dist/agent-skill-postgres.md +106 -0
- package/dist/cli-errors-BDCYR5ap.mjs +4 -0
- package/dist/cli-errors-DStABy9d.d.mts +3 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.js +1 -2910
- package/dist/cli.mjs +254 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/client-DiUkJAeN.mjs +987 -0
- package/dist/client-DiUkJAeN.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts +7 -0
- package/dist/commands/contract-emit.d.mts.map +1 -0
- package/dist/commands/contract-emit.mjs +4 -0
- package/dist/commands/contract-infer.d.mts +7 -0
- package/dist/commands/contract-infer.d.mts.map +1 -0
- package/dist/commands/contract-infer.mjs +4 -0
- package/dist/commands/db-init.d.mts +7 -0
- package/dist/commands/db-init.d.mts.map +1 -0
- package/dist/commands/db-init.mjs +125 -0
- package/dist/commands/db-init.mjs.map +1 -0
- package/dist/commands/db-schema.d.mts +7 -0
- package/dist/commands/db-schema.d.mts.map +1 -0
- package/dist/commands/db-schema.mjs +53 -0
- package/dist/commands/db-schema.mjs.map +1 -0
- package/dist/commands/db-sign.d.mts +7 -0
- package/dist/commands/db-sign.d.mts.map +1 -0
- package/dist/commands/db-sign.mjs +136 -0
- package/dist/commands/db-sign.mjs.map +1 -0
- package/dist/commands/db-update.d.mts +7 -0
- package/dist/commands/db-update.d.mts.map +1 -0
- package/dist/commands/db-update.mjs +122 -0
- package/dist/commands/db-update.mjs.map +1 -0
- package/dist/commands/db-verify.d.mts +7 -0
- package/dist/commands/db-verify.d.mts.map +1 -0
- package/dist/commands/db-verify.mjs +322 -0
- package/dist/commands/db-verify.mjs.map +1 -0
- package/dist/commands/migration-apply.d.mts +36 -0
- package/dist/commands/migration-apply.d.mts.map +1 -0
- package/dist/commands/migration-apply.mjs +244 -0
- package/dist/commands/migration-apply.mjs.map +1 -0
- package/dist/commands/migration-new.d.mts +8 -0
- package/dist/commands/migration-new.d.mts.map +1 -0
- package/dist/commands/migration-new.mjs +152 -0
- package/dist/commands/migration-new.mjs.map +1 -0
- package/dist/commands/migration-plan.d.mts +47 -0
- package/dist/commands/migration-plan.d.mts.map +1 -0
- package/dist/commands/migration-plan.mjs +313 -0
- package/dist/commands/migration-plan.mjs.map +1 -0
- package/dist/commands/migration-ref.d.mts +43 -0
- package/dist/commands/migration-ref.d.mts.map +1 -0
- package/dist/commands/migration-ref.mjs +195 -0
- package/dist/commands/migration-ref.mjs.map +1 -0
- package/dist/commands/migration-show.d.mts +28 -0
- package/dist/commands/migration-show.d.mts.map +1 -0
- package/dist/commands/migration-show.mjs +140 -0
- package/dist/commands/migration-show.mjs.map +1 -0
- package/dist/commands/migration-status.d.mts +86 -0
- package/dist/commands/migration-status.d.mts.map +1 -0
- package/dist/commands/migration-status.mjs +4 -0
- package/dist/commands/migration-verify.d.mts +16 -0
- package/dist/commands/migration-verify.d.mts.map +1 -0
- package/dist/commands/migration-verify.mjs +110 -0
- package/dist/commands/migration-verify.mjs.map +1 -0
- package/dist/config-loader-C4VXKl8f.mjs +43 -0
- package/dist/config-loader-C4VXKl8f.mjs.map +1 -0
- package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
- package/dist/config-loader.d.mts.map +1 -0
- package/dist/config-loader.mjs +3 -0
- package/dist/contract-emit-D2wDXfyo.mjs +191 -0
- package/dist/contract-emit-D2wDXfyo.mjs.map +1 -0
- package/dist/contract-emit-D9WOShFz.mjs +4 -0
- package/dist/contract-emit-Zm_sd1wQ.mjs +112 -0
- package/dist/contract-emit-Zm_sd1wQ.mjs.map +1 -0
- package/dist/contract-enrichment-CGW6mm-E.mjs +79 -0
- package/dist/contract-enrichment-CGW6mm-E.mjs.map +1 -0
- package/dist/contract-infer-DozZT511.mjs +90 -0
- package/dist/contract-infer-DozZT511.mjs.map +1 -0
- package/dist/exports/config-types.d.mts +2 -0
- package/dist/exports/config-types.mjs +3 -0
- package/dist/exports/control-api.d.mts +624 -0
- package/dist/exports/control-api.d.mts.map +1 -0
- package/dist/exports/control-api.mjs +6 -0
- package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +12 -7
- package/dist/exports/index.d.mts.map +1 -0
- package/dist/exports/index.mjs +137 -0
- package/dist/exports/index.mjs.map +1 -0
- package/dist/extract-operation-statements-DZUJNmL3.mjs +13 -0
- package/dist/extract-operation-statements-DZUJNmL3.mjs.map +1 -0
- package/dist/extract-sql-ddl-DDMX-9mz.mjs +26 -0
- package/dist/extract-sql-ddl-DDMX-9mz.mjs.map +1 -0
- package/dist/framework-components-BAsliT4V.mjs +59 -0
- package/dist/framework-components-BAsliT4V.mjs.map +1 -0
- package/dist/init-DQ8auNB4.mjs +430 -0
- package/dist/init-DQ8auNB4.mjs.map +1 -0
- package/dist/inspect-live-schema-BYnhztxZ.mjs +91 -0
- package/dist/inspect-live-schema-BYnhztxZ.mjs.map +1 -0
- package/dist/migration-command-scaffold-CntCcntR.mjs +105 -0
- package/dist/migration-command-scaffold-CntCcntR.mjs.map +1 -0
- package/dist/migration-status-CJANY4yr.mjs +1583 -0
- package/dist/migration-status-CJANY4yr.mjs.map +1 -0
- package/dist/migrations-DTZBYXm1.mjs +173 -0
- package/dist/migrations-DTZBYXm1.mjs.map +1 -0
- package/dist/progress-adapter-B-YvmcDu.mjs +43 -0
- package/dist/progress-adapter-B-YvmcDu.mjs.map +1 -0
- package/dist/quick-reference-mongo.md +93 -0
- package/dist/quick-reference-postgres.md +91 -0
- package/dist/result-handler-oK_vA-Fn.mjs +697 -0
- package/dist/result-handler-oK_vA-Fn.mjs.map +1 -0
- package/dist/terminal-ui-C5k88MmW.mjs +274 -0
- package/dist/terminal-ui-C5k88MmW.mjs.map +1 -0
- package/dist/validate-contract-deps-esa-VQ0h.mjs +37 -0
- package/dist/validate-contract-deps-esa-VQ0h.mjs.map +1 -0
- package/dist/verify-DlFQ2FOw.mjs +385 -0
- package/dist/verify-DlFQ2FOw.mjs.map +1 -0
- package/package.json +87 -40
- package/src/cli.ts +118 -58
- package/src/commands/contract-emit.ts +101 -78
- package/src/commands/contract-infer-paths.ts +32 -0
- package/src/commands/contract-infer.ts +143 -0
- package/src/commands/db-init.ts +97 -219
- package/src/commands/db-schema.ts +77 -0
- package/src/commands/db-sign.ts +46 -73
- package/src/commands/db-update.ts +236 -0
- package/src/commands/db-verify.ts +409 -119
- package/src/commands/init/detect-package-manager.ts +47 -0
- package/src/commands/init/index.ts +21 -0
- package/src/commands/init/init.ts +203 -0
- package/src/commands/init/templates/agent-skill-mongo.md +106 -0
- package/src/commands/init/templates/agent-skill-postgres.md +106 -0
- package/src/commands/init/templates/agent-skill.ts +19 -0
- package/src/commands/init/templates/code-templates.ts +168 -0
- package/src/commands/init/templates/quick-reference-mongo.md +93 -0
- package/src/commands/init/templates/quick-reference-postgres.md +91 -0
- package/src/commands/init/templates/quick-reference.ts +19 -0
- package/src/commands/init/templates/render.ts +20 -0
- package/src/commands/init/templates/tsconfig.ts +35 -0
- package/src/commands/inspect-live-schema.ts +170 -0
- package/src/commands/migration-apply.ts +427 -0
- package/src/commands/migration-new.ts +260 -0
- package/src/commands/migration-plan.ts +519 -0
- package/src/commands/migration-ref.ts +305 -0
- package/src/commands/migration-show.ts +246 -0
- package/src/commands/migration-status.ts +864 -0
- package/src/commands/migration-verify.ts +180 -0
- package/src/config-loader.ts +13 -3
- package/src/control-api/client.ts +205 -183
- package/src/control-api/contract-enrichment.ts +119 -0
- package/src/control-api/errors.ts +9 -0
- package/src/control-api/operations/contract-emit.ts +181 -0
- package/src/control-api/operations/db-init.ts +53 -49
- package/src/control-api/operations/db-update.ts +220 -0
- package/src/control-api/operations/extract-operation-statements.ts +14 -0
- package/src/control-api/operations/extract-sql-ddl.ts +47 -0
- package/src/control-api/operations/migration-apply.ts +191 -0
- package/src/control-api/operations/migration-helpers.ts +49 -0
- package/src/control-api/types.ts +274 -52
- package/src/exports/config-types.ts +4 -3
- package/src/exports/control-api.ts +15 -5
- package/src/load-ts-contract.ts +30 -19
- package/src/utils/cli-errors.ts +14 -8
- package/src/utils/command-helpers.ts +302 -3
- package/src/utils/formatters/emit.ts +67 -0
- package/src/utils/formatters/errors.ts +82 -0
- package/src/utils/formatters/graph-migration-mapper.ts +240 -0
- package/src/utils/formatters/graph-render.ts +1323 -0
- package/src/utils/formatters/graph-types.ts +120 -0
- package/src/utils/formatters/help.ts +380 -0
- package/src/utils/formatters/helpers.ts +28 -0
- package/src/utils/formatters/migrations.ts +346 -0
- package/src/utils/formatters/styled.ts +212 -0
- package/src/utils/formatters/verify.ts +621 -0
- package/src/utils/framework-components.ts +13 -10
- package/src/utils/global-flags.ts +41 -23
- package/src/utils/migration-command-scaffold.ts +184 -0
- package/src/utils/migration-types.ts +12 -0
- package/src/utils/progress-adapter.ts +18 -29
- package/src/utils/result-handler.ts +12 -13
- package/src/utils/shutdown.ts +92 -0
- package/src/utils/suggest-command.ts +31 -0
- package/src/utils/terminal-ui.ts +276 -0
- package/src/utils/validate-contract-deps.ts +49 -0
- package/dist/chunk-AGOTG4L3.js +0 -965
- package/dist/chunk-AGOTG4L3.js.map +0 -1
- package/dist/chunk-HLLI4YL7.js +0 -180
- package/dist/chunk-HLLI4YL7.js.map +0 -1
- package/dist/chunk-HWYQOCAJ.js +0 -47
- package/dist/chunk-HWYQOCAJ.js.map +0 -1
- package/dist/chunk-VG2R7DGF.js +0 -735
- package/dist/chunk-VG2R7DGF.js.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/contract-emit.d.ts +0 -3
- package/dist/commands/contract-emit.d.ts.map +0 -1
- package/dist/commands/contract-emit.js +0 -10
- package/dist/commands/contract-emit.js.map +0 -1
- package/dist/commands/db-init.d.ts +0 -3
- package/dist/commands/db-init.d.ts.map +0 -1
- package/dist/commands/db-init.js +0 -257
- package/dist/commands/db-init.js.map +0 -1
- package/dist/commands/db-introspect.d.ts +0 -3
- package/dist/commands/db-introspect.d.ts.map +0 -1
- package/dist/commands/db-introspect.js +0 -155
- package/dist/commands/db-introspect.js.map +0 -1
- package/dist/commands/db-schema-verify.d.ts +0 -3
- package/dist/commands/db-schema-verify.d.ts.map +0 -1
- package/dist/commands/db-schema-verify.js +0 -171
- package/dist/commands/db-schema-verify.js.map +0 -1
- package/dist/commands/db-sign.d.ts +0 -3
- package/dist/commands/db-sign.d.ts.map +0 -1
- package/dist/commands/db-sign.js +0 -195
- package/dist/commands/db-sign.js.map +0 -1
- package/dist/commands/db-verify.d.ts +0 -3
- package/dist/commands/db-verify.d.ts.map +0 -1
- package/dist/commands/db-verify.js +0 -193
- package/dist/commands/db-verify.js.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -7
- package/dist/config-loader.js.map +0 -1
- package/dist/control-api/client.d.ts +0 -13
- package/dist/control-api/client.d.ts.map +0 -1
- package/dist/control-api/operations/db-init.d.ts +0 -29
- package/dist/control-api/operations/db-init.d.ts.map +0 -1
- package/dist/control-api/types.d.ts +0 -387
- package/dist/control-api/types.d.ts.map +0 -1
- package/dist/exports/config-types.d.ts +0 -3
- package/dist/exports/config-types.d.ts.map +0 -1
- package/dist/exports/config-types.js +0 -6
- package/dist/exports/config-types.js.map +0 -1
- package/dist/exports/control-api.d.ts +0 -13
- package/dist/exports/control-api.d.ts.map +0 -1
- package/dist/exports/control-api.js +0 -7
- package/dist/exports/control-api.js.map +0 -1
- package/dist/exports/index.d.ts +0 -4
- package/dist/exports/index.d.ts.map +0 -1
- package/dist/exports/index.js +0 -176
- package/dist/exports/index.js.map +0 -1
- package/dist/load-ts-contract.d.ts.map +0 -1
- package/dist/utils/cli-errors.d.ts +0 -7
- package/dist/utils/cli-errors.d.ts.map +0 -1
- package/dist/utils/command-helpers.d.ts +0 -12
- package/dist/utils/command-helpers.d.ts.map +0 -1
- package/dist/utils/framework-components.d.ts +0 -70
- package/dist/utils/framework-components.d.ts.map +0 -1
- package/dist/utils/global-flags.d.ts +0 -25
- package/dist/utils/global-flags.d.ts.map +0 -1
- package/dist/utils/output.d.ts +0 -142
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/progress-adapter.d.ts +0 -26
- package/dist/utils/progress-adapter.d.ts.map +0 -1
- package/dist/utils/result-handler.d.ts +0 -15
- package/dist/utils/result-handler.d.ts.map +0 -1
- package/src/commands/db-introspect.ts +0 -227
- package/src/commands/db-schema-verify.ts +0 -238
- package/src/utils/output.ts +0 -1471
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Prisma Next — project skill
|
|
2
|
+
|
|
3
|
+
This project uses **Prisma Next** with **MongoDB** via `@prisma-next/mongo`. Prisma Next lets the user define data models in a contract file and query them with a fully typed ORM.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
- **Contract**: `{{schemaPath}}` — the user's data models. Edit this to add or change models.
|
|
8
|
+
- **Config**: `prisma-next.config.ts` — tells the CLI where the contract is and how to connect to the database. Loads `.env` via `dotenv/config`.
|
|
9
|
+
- **Database client**: `{{schemaDir}}/db.ts` — `import { db } from '{{dbImportPath}}'`. This is the entry point for all queries.
|
|
10
|
+
- **Generated files** (do not edit by hand):
|
|
11
|
+
- `{{schemaDir}}/contract.json` — compiled contract, used at runtime
|
|
12
|
+
- `{{schemaDir}}/contract.d.ts` — TypeScript types for the contract, used for autocomplete and type checking
|
|
13
|
+
|
|
14
|
+
## Commands
|
|
15
|
+
|
|
16
|
+
- `{{pkgRun}} contract emit` — regenerate `contract.json` and `contract.d.ts` after changing the contract
|
|
17
|
+
- `{{pkgRun}} db init` — bootstrap a database to match the contract (creates collections, indexes, constraints). Additive only — won't drop existing structures.
|
|
18
|
+
- `{{pkgRun}} db update` — update the database to match the current contract. Prompts for confirmation on destructive changes. Use `--dry-run` to preview.
|
|
19
|
+
- `{{pkgRun}} migration plan` — create a new migration from contract changes (offline, no database needed). Use `--name <slug>` to name it.
|
|
20
|
+
- `{{pkgRun}} migration apply` — apply pending migrations to the database
|
|
21
|
+
- `{{pkgRun}} migration status` — show which migrations are applied and which are pending
|
|
22
|
+
- `{{pkgRun}} migration show <name>` — show details of a specific migration
|
|
23
|
+
|
|
24
|
+
## How to write queries
|
|
25
|
+
|
|
26
|
+
Always use the ORM (`db.orm`). Only fall back to `db.sql` if the user explicitly asks for raw queries or the ORM doesn't support the operation.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { db } from '{{dbImportPath}}';
|
|
30
|
+
|
|
31
|
+
// Find one record
|
|
32
|
+
const user = await db.orm.User
|
|
33
|
+
.where(user => user.email.eq('alice@example.com'))
|
|
34
|
+
.first();
|
|
35
|
+
// Returns { id: ObjectId; email: string; ... } | null
|
|
36
|
+
|
|
37
|
+
// Find multiple records
|
|
38
|
+
const users = await db.orm.User
|
|
39
|
+
.select('id', 'email')
|
|
40
|
+
.take(10)
|
|
41
|
+
.all();
|
|
42
|
+
// Returns Array<{ id: ObjectId; email: string }>
|
|
43
|
+
|
|
44
|
+
// Filter, order, limit
|
|
45
|
+
const recentPosts = await db.orm.Post
|
|
46
|
+
.where(post => post.authorId.eq(userId))
|
|
47
|
+
.orderBy(post => post.createdAt.desc())
|
|
48
|
+
.select('id', 'title', 'createdAt')
|
|
49
|
+
.take(50)
|
|
50
|
+
.all();
|
|
51
|
+
|
|
52
|
+
// Include relations
|
|
53
|
+
const usersWithPosts = await db.orm.User
|
|
54
|
+
.select('id', 'email')
|
|
55
|
+
.include('posts', post =>
|
|
56
|
+
post.select('id', 'title').orderBy(p => p.createdAt.desc()).take(5)
|
|
57
|
+
)
|
|
58
|
+
.take(10)
|
|
59
|
+
.all();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Key ORM methods
|
|
63
|
+
|
|
64
|
+
- `.where(predicate)` — filter records. Predicate receives a model accessor with `.eq()`, `.neq()`, `.ilike()`, `.lt()`, `.gt()`, etc.
|
|
65
|
+
- `.select('field1', 'field2', ...)` — pick which fields to return
|
|
66
|
+
- `.orderBy(accessor => accessor.field.asc()` or `.desc())` — sort results
|
|
67
|
+
- `.take(n)` — limit number of results
|
|
68
|
+
- `.all()` — execute and return all matching records as an array
|
|
69
|
+
- `.first()` — execute and return the first matching record, or `null`
|
|
70
|
+
- `.first({ id: value })` — find a single record by primary key, or `null`
|
|
71
|
+
- `.include('relation', builder => ...)` — eager-load a relation
|
|
72
|
+
|
|
73
|
+
## Rules
|
|
74
|
+
|
|
75
|
+
- **Never hand-edit** `contract.json` or `contract.d.ts`. Always regenerate them with `contract emit`.
|
|
76
|
+
- **Always emit after contract changes.** When you modify `{{schemaPath}}`, run `{{pkgRun}} contract emit` before writing any code that depends on the new or changed models.
|
|
77
|
+
- **Don't restructure `db.ts`.** It's scaffolded by init and works as-is.
|
|
78
|
+
- **Use `db.orm` for queries**, not `db.sql`. The ORM is the primary query surface.
|
|
79
|
+
- **Connection string** is `DATABASE_URL` in `.env`. If the user reports connection errors, check this value and the `.env` file.
|
|
80
|
+
|
|
81
|
+
## Workflow for common tasks
|
|
82
|
+
|
|
83
|
+
**User wants to add a new model or field:**
|
|
84
|
+
1. Edit `{{schemaPath}}`
|
|
85
|
+
2. Run `{{pkgRun}} contract emit`
|
|
86
|
+
3. Write query code using `db.orm.ModelName`
|
|
87
|
+
|
|
88
|
+
**User wants to query data:**
|
|
89
|
+
1. Import `db` from `{{dbImportPath}}`
|
|
90
|
+
2. Use `db.orm.ModelName` with `.where()`, `.select()`, `.all()`, `.first()`, etc.
|
|
91
|
+
|
|
92
|
+
**User wants to set up or change the database connection:**
|
|
93
|
+
1. Edit `DATABASE_URL` in `.env`
|
|
94
|
+
2. The config file (`prisma-next.config.ts`) reads it automatically via `dotenv/config`
|
|
95
|
+
|
|
96
|
+
**User wants to set up the database for the first time:**
|
|
97
|
+
1. Run `{{pkgRun}} db init`
|
|
98
|
+
|
|
99
|
+
**User wants to update the database after changing the contract:**
|
|
100
|
+
1. Quick path: `{{pkgRun}} db update` — compares the database to the contract and applies changes directly
|
|
101
|
+
2. Migration path (for production workflows):
|
|
102
|
+
- `{{pkgRun}} migration plan --name describe-the-change` — creates a migration
|
|
103
|
+
- `{{pkgRun}} migration apply` — applies pending migrations
|
|
104
|
+
|
|
105
|
+
**User wants to check what migrations need to be applied:**
|
|
106
|
+
1. Run `{{pkgRun}} migration status`
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Prisma Next — project skill
|
|
2
|
+
|
|
3
|
+
This project uses **Prisma Next** with **PostgreSQL** via `@prisma-next/postgres`. Prisma Next lets the user define data models in a contract file and query them with a fully typed ORM.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
- **Contract**: `{{schemaPath}}` — the user's data models. Edit this to add or change models.
|
|
8
|
+
- **Config**: `prisma-next.config.ts` — tells the CLI where the contract is and how to connect to the database. Loads `.env` via `dotenv/config`.
|
|
9
|
+
- **Database client**: `{{schemaDir}}/db.ts` — `import { db } from '{{dbImportPath}}'`. This is the entry point for all queries.
|
|
10
|
+
- **Generated files** (do not edit by hand):
|
|
11
|
+
- `{{schemaDir}}/contract.json` — compiled contract, used at runtime
|
|
12
|
+
- `{{schemaDir}}/contract.d.ts` — TypeScript types for the contract, used for autocomplete and type checking
|
|
13
|
+
|
|
14
|
+
## Commands
|
|
15
|
+
|
|
16
|
+
- `{{pkgRun}} contract emit` — regenerate `contract.json` and `contract.d.ts` after changing the contract
|
|
17
|
+
- `{{pkgRun}} db init` — bootstrap a database to match the contract (creates tables, indexes, constraints). Additive only — won't drop existing structures.
|
|
18
|
+
- `{{pkgRun}} db update` — update the database to match the current contract. Prompts for confirmation on destructive changes. Use `--dry-run` to preview.
|
|
19
|
+
- `{{pkgRun}} migration plan` — create a new migration from contract changes (offline, no database needed). Use `--name <slug>` to name it.
|
|
20
|
+
- `{{pkgRun}} migration apply` — apply pending migrations to the database
|
|
21
|
+
- `{{pkgRun}} migration status` — show which migrations are applied and which are pending
|
|
22
|
+
- `{{pkgRun}} migration show <name>` — show details of a specific migration
|
|
23
|
+
|
|
24
|
+
## How to write queries
|
|
25
|
+
|
|
26
|
+
Always use the ORM (`db.orm`). Only fall back to `db.sql` if the user explicitly asks for raw SQL or the ORM doesn't support the operation.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { db } from '{{dbImportPath}}';
|
|
30
|
+
|
|
31
|
+
// Find one record
|
|
32
|
+
const user = await db.orm.User
|
|
33
|
+
.where(user => user.email.eq('alice@example.com'))
|
|
34
|
+
.first();
|
|
35
|
+
// Returns { id: number; email: string; ... } | null
|
|
36
|
+
|
|
37
|
+
// Find multiple records
|
|
38
|
+
const users = await db.orm.User
|
|
39
|
+
.select('id', 'email')
|
|
40
|
+
.take(10)
|
|
41
|
+
.all();
|
|
42
|
+
// Returns Array<{ id: number; email: string }>
|
|
43
|
+
|
|
44
|
+
// Filter, order, limit
|
|
45
|
+
const recentPosts = await db.orm.Post
|
|
46
|
+
.where(post => post.authorId.eq(userId))
|
|
47
|
+
.orderBy(post => post.createdAt.desc())
|
|
48
|
+
.select('id', 'title', 'createdAt')
|
|
49
|
+
.take(50)
|
|
50
|
+
.all();
|
|
51
|
+
|
|
52
|
+
// Include relations
|
|
53
|
+
const usersWithPosts = await db.orm.User
|
|
54
|
+
.select('id', 'email')
|
|
55
|
+
.include('posts', post =>
|
|
56
|
+
post.select('id', 'title').orderBy(p => p.createdAt.desc()).take(5)
|
|
57
|
+
)
|
|
58
|
+
.take(10)
|
|
59
|
+
.all();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Key ORM methods
|
|
63
|
+
|
|
64
|
+
- `.where(predicate)` — filter records. Predicate receives a model accessor with `.eq()`, `.neq()`, `.ilike()`, `.lt()`, `.gt()`, etc.
|
|
65
|
+
- `.select('field1', 'field2', ...)` — pick which fields to return
|
|
66
|
+
- `.orderBy(accessor => accessor.field.asc()` or `.desc())` — sort results
|
|
67
|
+
- `.take(n)` — limit number of results
|
|
68
|
+
- `.all()` — execute and return all matching records as an array
|
|
69
|
+
- `.first()` — execute and return the first matching record, or `null`
|
|
70
|
+
- `.first({ id: value })` — find a single record by primary key, or `null`
|
|
71
|
+
- `.include('relation', builder => ...)` — eager-load a relation
|
|
72
|
+
|
|
73
|
+
## Rules
|
|
74
|
+
|
|
75
|
+
- **Never hand-edit** `contract.json` or `contract.d.ts`. Always regenerate them with `contract emit`.
|
|
76
|
+
- **Always emit after contract changes.** When you modify `{{schemaPath}}`, run `{{pkgRun}} contract emit` before writing any code that depends on the new or changed models.
|
|
77
|
+
- **Don't restructure `db.ts`.** It's scaffolded by init and works as-is.
|
|
78
|
+
- **Use `db.orm` for queries**, not `db.sql`. The ORM is the primary query surface.
|
|
79
|
+
- **Connection string** is `DATABASE_URL` in `.env`. If the user reports connection errors, check this value and the `.env` file.
|
|
80
|
+
|
|
81
|
+
## Workflow for common tasks
|
|
82
|
+
|
|
83
|
+
**User wants to add a new model or field:**
|
|
84
|
+
1. Edit `{{schemaPath}}`
|
|
85
|
+
2. Run `{{pkgRun}} contract emit`
|
|
86
|
+
3. Write query code using `db.orm.ModelName`
|
|
87
|
+
|
|
88
|
+
**User wants to query data:**
|
|
89
|
+
1. Import `db` from `{{dbImportPath}}`
|
|
90
|
+
2. Use `db.orm.ModelName` with `.where()`, `.select()`, `.all()`, `.first()`, etc.
|
|
91
|
+
|
|
92
|
+
**User wants to set up or change the database connection:**
|
|
93
|
+
1. Edit `DATABASE_URL` in `.env`
|
|
94
|
+
2. The config file (`prisma-next.config.ts`) reads it automatically via `dotenv/config`
|
|
95
|
+
|
|
96
|
+
**User wants to set up the database for the first time:**
|
|
97
|
+
1. Run `{{pkgRun}} db init`
|
|
98
|
+
|
|
99
|
+
**User wants to update the database after changing the contract:**
|
|
100
|
+
1. Quick path: `{{pkgRun}} db update` — compares the database to the contract and applies changes directly
|
|
101
|
+
2. Migration path (for production workflows):
|
|
102
|
+
- `{{pkgRun}} migration plan --name describe-the-change` — creates a migration
|
|
103
|
+
- `{{pkgRun}} migration apply` — applies pending migrations
|
|
104
|
+
|
|
105
|
+
**User wants to check what migrations need to be applied:**
|
|
106
|
+
1. Run `{{pkgRun}} migration status`
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CliStructuredError, errorConfigValidation as errorConfigValidation$1, errorContractConfigMissing as errorContractConfigMissing$1, errorContractValidationFailed, errorDatabaseConnectionRequired, errorDriverRequired, errorFileNotFound, errorMigrationPlanningFailed, errorTargetMigrationNotSupported, errorUnexpected as errorUnexpected$1 } from "@prisma-next/errors/control";
|
|
2
|
+
import { ERROR_CODE_DESTRUCTIVE_CHANGES, errorDestructiveChanges, errorHashMismatch, errorMarkerMissing, errorRunnerFailed, errorRuntime as errorRuntime$1, errorTargetMismatch } from "@prisma-next/errors/execution";
|
|
3
|
+
|
|
4
|
+
export { errorUnexpected$1 as _, errorContractValidationFailed as a, errorDriverRequired as c, errorMarkerMissing as d, errorMigrationPlanningFailed as f, errorTargetMismatch as g, errorTargetMigrationNotSupported as h, errorContractConfigMissing$1 as i, errorFileNotFound as l, errorRuntime$1 as m, ERROR_CODE_DESTRUCTIVE_CHANGES as n, errorDatabaseConnectionRequired as o, errorRunnerFailed as p, errorConfigValidation$1 as r, errorDestructiveChanges as s, CliStructuredError as t, errorHashMismatch as u };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|