create-prisma 0.4.1 → 0.4.2-next.37.104.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.
Files changed (103) hide show
  1. package/README.md +66 -44
  2. package/dist/cli.mjs +1 -1
  3. package/dist/{create-H6Tk0JlE.mjs → create-BeFhatOc.mjs} +910 -993
  4. package/dist/index.d.mts +32 -39
  5. package/dist/index.mjs +3 -3
  6. package/package.json +7 -2
  7. package/templates/create/_shared/prisma/seed.ts.hbs +52 -0
  8. package/templates/create/astro/README.md.hbs +25 -15
  9. package/templates/create/astro/astro.config.mjs +6 -1
  10. package/templates/create/astro/deno.json.hbs +1 -1
  11. package/templates/create/astro/package.json.hbs +3 -2
  12. package/templates/create/astro/src/lib/prisma.ts.hbs +60 -40
  13. package/templates/create/astro/src/pages/api/users.ts.hbs +6 -22
  14. package/templates/create/astro/src/pages/index.astro.hbs +18 -55
  15. package/templates/create/elysia/README.md.hbs +27 -17
  16. package/templates/create/elysia/deno.json.hbs +1 -1
  17. package/templates/create/elysia/src/index.ts.hbs +15 -11
  18. package/templates/create/elysia/src/lib/prisma.ts.hbs +60 -43
  19. package/templates/create/elysia/tsconfig.json +1 -0
  20. package/templates/create/hono/README.md.hbs +27 -17
  21. package/templates/create/hono/deno.json.hbs +1 -1
  22. package/templates/create/hono/src/index.ts.hbs +9 -10
  23. package/templates/create/hono/src/lib/prisma.ts.hbs +60 -43
  24. package/templates/create/hono/tsconfig.json +1 -0
  25. package/templates/create/minimal/.yarnrc.yml.hbs +3 -0
  26. package/templates/create/minimal/README.md.hbs +39 -0
  27. package/templates/create/{turborepo → minimal}/deno.json.hbs +1 -1
  28. package/templates/create/minimal/package.json.hbs +13 -0
  29. package/templates/create/minimal/src/index.ts.hbs +43 -0
  30. package/templates/create/minimal/src/lib/prisma.ts.hbs +73 -0
  31. package/templates/create/{turborepo/apps/api → minimal}/tsconfig.json +3 -4
  32. package/templates/create/nest/README.md.hbs +28 -17
  33. package/templates/create/nest/deno.json.hbs +1 -1
  34. package/templates/create/nest/src/app.module.ts.hbs +5 -6
  35. package/templates/create/nest/src/lib/prisma.ts.hbs +60 -45
  36. package/templates/create/nest/src/prisma.service.ts.hbs +6 -5
  37. package/templates/create/nest/src/users.controller.ts.hbs +1 -2
  38. package/templates/create/nest/src/users.service.ts.hbs +2 -8
  39. package/templates/create/nest/tsconfig.json +1 -0
  40. package/templates/create/next/README.md.hbs +25 -13
  41. package/templates/create/next/deno.json.hbs +1 -1
  42. package/templates/create/next/src/app/page.tsx.hbs +16 -57
  43. package/templates/create/next/src/lib/prisma.ts.hbs +60 -40
  44. package/templates/create/next/tsconfig.json +1 -0
  45. package/templates/create/nuxt/README.md.hbs +26 -13
  46. package/templates/create/nuxt/app/pages/index.vue.hbs +12 -45
  47. package/templates/create/nuxt/deno.json.hbs +1 -1
  48. package/templates/create/nuxt/nuxt.config.ts +21 -0
  49. package/templates/create/nuxt/package.json.hbs +2 -1
  50. package/templates/create/nuxt/server/api/users.get.ts.hbs +4 -15
  51. package/templates/create/nuxt/server/utils/prisma.ts.hbs +60 -40
  52. package/templates/create/svelte/README.md.hbs +25 -15
  53. package/templates/create/svelte/deno.json.hbs +1 -1
  54. package/templates/create/svelte/package.json.hbs +1 -1
  55. package/templates/create/svelte/src/lib/server/prisma.ts.hbs +61 -41
  56. package/templates/create/svelte/src/routes/+page.server.ts.hbs +4 -15
  57. package/templates/create/svelte/src/routes/+page.svelte.hbs +13 -163
  58. package/templates/create/svelte/vite.config.ts +2 -1
  59. package/templates/create/tanstack-start/README.md.hbs +26 -13
  60. package/templates/create/tanstack-start/deno.json.hbs +1 -2
  61. package/templates/create/tanstack-start/package.json.hbs +1 -2
  62. package/templates/create/tanstack-start/src/lib/prisma.server.ts.hbs +60 -40
  63. package/templates/create/tanstack-start/src/routes/__root.tsx.hbs +2 -3
  64. package/templates/create/tanstack-start/src/routes/index.tsx.hbs +26 -77
  65. package/templates/create/tanstack-start/tsconfig.json +1 -0
  66. package/templates/create/tanstack-start/vite.config.ts +7 -1
  67. package/templates/create/astro/prisma/schema.prisma.hbs +0 -21
  68. package/templates/create/astro/prisma/seed.ts.hbs +0 -38
  69. package/templates/create/astro/prisma.config.ts +0 -13
  70. package/templates/create/elysia/prisma/schema.prisma.hbs +0 -25
  71. package/templates/create/elysia/prisma/seed.ts.hbs +0 -42
  72. package/templates/create/elysia/prisma.config.ts.hbs +0 -15
  73. package/templates/create/hono/prisma/schema.prisma.hbs +0 -25
  74. package/templates/create/hono/prisma/seed.ts.hbs +0 -42
  75. package/templates/create/hono/prisma.config.ts.hbs +0 -15
  76. package/templates/create/nest/prisma/schema.prisma.hbs +0 -25
  77. package/templates/create/nest/prisma/seed.ts.hbs +0 -44
  78. package/templates/create/nest/prisma.config.ts.hbs +0 -15
  79. package/templates/create/next/prisma/schema.prisma.hbs +0 -21
  80. package/templates/create/next/prisma/seed.ts.hbs +0 -38
  81. package/templates/create/next/prisma.config.ts +0 -13
  82. package/templates/create/nuxt/prisma/schema.prisma.hbs +0 -21
  83. package/templates/create/nuxt/prisma/seed.ts.hbs +0 -38
  84. package/templates/create/nuxt/prisma.config.ts +0 -13
  85. package/templates/create/svelte/prisma/schema.prisma.hbs +0 -21
  86. package/templates/create/svelte/prisma/seed.ts.hbs +0 -87
  87. package/templates/create/svelte/prisma.config.ts +0 -13
  88. package/templates/create/tanstack-start/prisma/schema.prisma.hbs +0 -21
  89. package/templates/create/tanstack-start/prisma/seed.ts.hbs +0 -37
  90. package/templates/create/tanstack-start/prisma.config.ts +0 -13
  91. package/templates/create/turborepo/README.md.hbs +0 -29
  92. package/templates/create/turborepo/apps/api/package.json.hbs +0 -19
  93. package/templates/create/turborepo/apps/api/src/index.ts.hbs +0 -51
  94. package/templates/create/turborepo/package.json.hbs +0 -24
  95. package/templates/create/turborepo/packages/db/package.json.hbs +0 -17
  96. package/templates/create/turborepo/packages/db/prisma/schema.prisma.hbs +0 -21
  97. package/templates/create/turborepo/packages/db/prisma/seed.ts.hbs +0 -38
  98. package/templates/create/turborepo/packages/db/prisma.config.ts +0 -13
  99. package/templates/create/turborepo/packages/db/src/client.ts.hbs +0 -58
  100. package/templates/create/turborepo/packages/db/src/index.ts +0 -2
  101. package/templates/create/turborepo/packages/db/tsconfig.json +0 -15
  102. package/templates/create/turborepo/turbo.json +0 -28
  103. /package/templates/create/{turborepo → elysia}/.yarnrc.yml.hbs +0 -0
package/dist/index.d.mts CHANGED
@@ -177,13 +177,12 @@ type ErrorMap = { [key in ORPCErrorCode]?: ErrorMapItem<AnySchema> };
177
177
  type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
178
178
  //#endregion
179
179
  //#region src/types.d.ts
180
- declare const DatabaseProviderSchema: z.ZodEnum<{
180
+ declare const DatabaseProviderSchema: z.ZodPipe<z.ZodEnum<{
181
+ postgres: "postgres";
181
182
  postgresql: "postgresql";
182
- mysql: "mysql";
183
- sqlite: "sqlite";
184
- sqlserver: "sqlserver";
185
- cockroachdb: "cockroachdb";
186
- }>;
183
+ mongo: "mongo";
184
+ mongodb: "mongodb";
185
+ }>, z.ZodTransform<"postgres" | "mongo", "postgres" | "postgresql" | "mongo" | "mongodb">>;
187
186
  declare const PackageManagerSchema: z.ZodEnum<{
188
187
  npm: "npm";
189
188
  pnpm: "pnpm";
@@ -191,11 +190,12 @@ declare const PackageManagerSchema: z.ZodEnum<{
191
190
  bun: "bun";
192
191
  deno: "deno";
193
192
  }>;
194
- declare const SchemaPresetSchema: z.ZodEnum<{
195
- empty: "empty";
196
- basic: "basic";
193
+ declare const AuthoringStyleSchema: z.ZodEnum<{
194
+ psl: "psl";
195
+ typescript: "typescript";
197
196
  }>;
198
197
  declare const CreateTemplateSchema: z.ZodEnum<{
198
+ minimal: "minimal";
199
199
  hono: "hono";
200
200
  elysia: "elysia";
201
201
  nest: "nest";
@@ -204,18 +204,20 @@ declare const CreateTemplateSchema: z.ZodEnum<{
204
204
  astro: "astro";
205
205
  nuxt: "nuxt";
206
206
  "tanstack-start": "tanstack-start";
207
- turborepo: "turborepo";
208
207
  }>;
209
208
  declare const DatabaseUrlSchema: z.ZodString;
210
209
  declare const CreateCommandInputSchema: z.ZodObject<{
211
210
  yes: z.ZodOptional<z.ZodBoolean>;
212
211
  verbose: z.ZodOptional<z.ZodBoolean>;
213
- provider: z.ZodOptional<z.ZodEnum<{
212
+ provider: z.ZodOptional<z.ZodPipe<z.ZodEnum<{
213
+ postgres: "postgres";
214
214
  postgresql: "postgresql";
215
- mysql: "mysql";
216
- sqlite: "sqlite";
217
- sqlserver: "sqlserver";
218
- cockroachdb: "cockroachdb";
215
+ mongo: "mongo";
216
+ mongodb: "mongodb";
217
+ }>, z.ZodTransform<"postgres" | "mongo", "postgres" | "postgresql" | "mongo" | "mongodb">>>;
218
+ authoring: z.ZodOptional<z.ZodEnum<{
219
+ psl: "psl";
220
+ typescript: "typescript";
219
221
  }>>;
220
222
  packageManager: z.ZodOptional<z.ZodEnum<{
221
223
  npm: "npm";
@@ -227,13 +229,11 @@ declare const CreateCommandInputSchema: z.ZodObject<{
227
229
  prismaPostgres: z.ZodOptional<z.ZodBoolean>;
228
230
  databaseUrl: z.ZodOptional<z.ZodString>;
229
231
  install: z.ZodOptional<z.ZodBoolean>;
230
- generate: z.ZodOptional<z.ZodBoolean>;
231
- schemaPreset: z.ZodOptional<z.ZodEnum<{
232
- empty: "empty";
233
- basic: "basic";
234
- }>>;
232
+ emit: z.ZodOptional<z.ZodBoolean>;
233
+ prismaNextVersion: z.ZodOptional<z.ZodString>;
235
234
  name: z.ZodOptional<z.ZodString>;
236
235
  template: z.ZodOptional<z.ZodEnum<{
236
+ minimal: "minimal";
237
237
  hono: "hono";
238
238
  elysia: "elysia";
239
239
  nest: "nest";
@@ -242,11 +242,7 @@ declare const CreateCommandInputSchema: z.ZodObject<{
242
242
  astro: "astro";
243
243
  nuxt: "nuxt";
244
244
  "tanstack-start": "tanstack-start";
245
- turborepo: "turborepo";
246
245
  }>>;
247
- skills: z.ZodOptional<z.ZodBoolean>;
248
- mcp: z.ZodOptional<z.ZodBoolean>;
249
- extension: z.ZodOptional<z.ZodBoolean>;
250
246
  force: z.ZodOptional<z.ZodBoolean>;
251
247
  }, z.core.$strip>;
252
248
  type CreateCommandInput = z.infer<typeof CreateCommandInputSchema>;
@@ -256,12 +252,15 @@ declare const router: {
256
252
  create: _orpc_server0.Procedure<_orpc_server0.MergedInitialContext<Record<never, never>, Record<never, never>, Record<never, never>>, Record<never, never>, zod.ZodOptional<zod.ZodObject<{
257
253
  yes: zod.ZodOptional<zod.ZodBoolean>;
258
254
  verbose: zod.ZodOptional<zod.ZodBoolean>;
259
- provider: zod.ZodOptional<zod.ZodEnum<{
255
+ provider: zod.ZodOptional<zod.ZodPipe<zod.ZodEnum<{
256
+ postgres: "postgres";
260
257
  postgresql: "postgresql";
261
- mysql: "mysql";
262
- sqlite: "sqlite";
263
- sqlserver: "sqlserver";
264
- cockroachdb: "cockroachdb";
258
+ mongo: "mongo";
259
+ mongodb: "mongodb";
260
+ }>, zod.ZodTransform<"postgres" | "mongo", "postgres" | "postgresql" | "mongo" | "mongodb">>>;
261
+ authoring: zod.ZodOptional<zod.ZodEnum<{
262
+ psl: "psl";
263
+ typescript: "typescript";
265
264
  }>>;
266
265
  packageManager: zod.ZodOptional<zod.ZodEnum<{
267
266
  npm: "npm";
@@ -273,13 +272,11 @@ declare const router: {
273
272
  prismaPostgres: zod.ZodOptional<zod.ZodBoolean>;
274
273
  databaseUrl: zod.ZodOptional<zod.ZodString>;
275
274
  install: zod.ZodOptional<zod.ZodBoolean>;
276
- generate: zod.ZodOptional<zod.ZodBoolean>;
277
- schemaPreset: zod.ZodOptional<zod.ZodEnum<{
278
- empty: "empty";
279
- basic: "basic";
280
- }>>;
275
+ emit: zod.ZodOptional<zod.ZodBoolean>;
276
+ prismaNextVersion: zod.ZodOptional<zod.ZodString>;
281
277
  name: zod.ZodOptional<zod.ZodString>;
282
278
  template: zod.ZodOptional<zod.ZodEnum<{
279
+ minimal: "minimal";
283
280
  hono: "hono";
284
281
  elysia: "elysia";
285
282
  nest: "nest";
@@ -288,15 +285,11 @@ declare const router: {
288
285
  astro: "astro";
289
286
  nuxt: "nuxt";
290
287
  "tanstack-start": "tanstack-start";
291
- turborepo: "turborepo";
292
288
  }>>;
293
- skills: zod.ZodOptional<zod.ZodBoolean>;
294
- mcp: zod.ZodOptional<zod.ZodBoolean>;
295
- extension: zod.ZodOptional<zod.ZodBoolean>;
296
289
  force: zod.ZodOptional<zod.ZodBoolean>;
297
290
  }, zod_v4_core0.$strip>>, Schema<void, void>, MergedErrorMap<Record<never, never>, Record<never, never>>, Record<never, never>>;
298
291
  };
299
292
  declare function createCreatePrismaCli(): trpc_cli0.TrpcCli;
300
293
  declare function create(input?: CreateCommandInput): Promise<void>;
301
294
  //#endregion
302
- export { type CreateCommandInput, CreateCommandInputSchema, CreateTemplateSchema, DatabaseProviderSchema, DatabaseUrlSchema, PackageManagerSchema, SchemaPresetSchema, create, createCreatePrismaCli, router };
295
+ export { AuthoringStyleSchema, type CreateCommandInput, CreateCommandInputSchema, CreateTemplateSchema, DatabaseProviderSchema, DatabaseUrlSchema, PackageManagerSchema, create, createCreatePrismaCli, router };
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { a as DatabaseUrlSchema, i as DatabaseProviderSchema, n as CreateCommandInputSchema, o as PackageManagerSchema, r as CreateTemplateSchema, s as SchemaPresetSchema, t as runCreateCommand } from "./create-H6Tk0JlE.mjs";
2
+ import { a as DatabaseProviderSchema, i as CreateTemplateSchema, n as AuthoringStyleSchema, o as DatabaseUrlSchema, r as CreateCommandInputSchema, s as PackageManagerSchema, t as runCreateCommand } from "./create-BeFhatOc.mjs";
3
3
  import { os } from "@orpc/server";
4
4
  import { createCli } from "trpc-cli";
5
5
 
6
6
  //#region src/index.ts
7
- const CLI_VERSION = "0.4.1";
7
+ const CLI_VERSION = "0.4.2-next.37.104.1";
8
8
  const router = os.router({ create: os.meta({
9
9
  description: "Create a new project with Prisma setup",
10
10
  default: true,
@@ -24,4 +24,4 @@ async function create(input = {}) {
24
24
  }
25
25
 
26
26
  //#endregion
27
- export { CreateCommandInputSchema, CreateTemplateSchema, DatabaseProviderSchema, DatabaseUrlSchema, PackageManagerSchema, SchemaPresetSchema, create, createCreatePrismaCli, router };
27
+ export { AuthoringStyleSchema, CreateCommandInputSchema, CreateTemplateSchema, DatabaseProviderSchema, DatabaseUrlSchema, PackageManagerSchema, create, createCreatePrismaCli, router };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "create-prisma",
3
- "version": "0.4.1",
3
+ "version": "0.4.2-next.37.104.1",
4
4
  "private": false,
5
- "description": "Create Prisma 7 projects with first-party templates and great DX.",
5
+ "description": "Create Prisma Next projects with first-party templates and great DX.",
6
6
  "homepage": "https://github.com/prisma/create-prisma",
7
7
  "bugs": {
8
8
  "url": "https://github.com/prisma/create-prisma/issues"
@@ -36,6 +36,9 @@
36
36
  "build": "tsdown",
37
37
  "dev": "tsdown --watch",
38
38
  "start": "bun run ./dist/cli.mjs",
39
+ "test": "bun run test:unit && bun run test:e2e",
40
+ "test:unit": "bun test ./tests/dependencies.test.ts ./tests/install.test.ts ./tests/telemetry.test.ts",
41
+ "test:e2e": "bun test --timeout 180000 ./tests/e2e/create-prisma.e2e.test.ts",
39
42
  "check": "bun run format:check && bun run lint",
40
43
  "lint": "oxlint . --deny-warnings",
41
44
  "lint:fix": "oxlint . --fix",
@@ -57,10 +60,12 @@
57
60
  "zod": "^4.3.6"
58
61
  },
59
62
  "devDependencies": {
63
+ "@prisma/dev": "0.24.7",
60
64
  "@types/bun": "^1.3.9",
61
65
  "@types/fs-extra": "^11.0.4",
62
66
  "@types/node": "^25.3.0",
63
67
  "changelogithub": "^14.0.0",
68
+ "mongodb-memory-server": "11.1.0",
64
69
  "oxfmt": "^0.37.0",
65
70
  "oxlint": "^1.52.0",
66
71
  "tsdown": "^0.20.3",
@@ -0,0 +1,52 @@
1
+ {{#if (requiresDotenvConfigImport packageManager)}}
2
+ import "dotenv/config";
3
+ {{/if}}
4
+ {{#if (eq template "nuxt")}}
5
+ import { db } from "../server/utils/prisma{{#if (eq packageManager "deno")}}.ts{{/if}}";
6
+ {{else}}
7
+ {{#if (eq template "svelte")}}
8
+ import { db } from "../src/lib/server/prisma{{#if (eq packageManager "deno")}}.ts{{/if}}";
9
+ {{else}}
10
+ {{#if (eq template "tanstack-start")}}
11
+ import { db } from "../src/lib/prisma.server{{#if (eq packageManager "deno")}}.ts{{/if}}";
12
+ {{else}}
13
+ import { db } from "../src/lib/prisma{{#if (eq packageManager "deno")}}.ts{{/if}}";
14
+ {{/if}}
15
+ {{/if}}
16
+ {{/if}}
17
+
18
+ const seedUsers = [
19
+ { email: "alice@prisma.io", username: "alice", name: "Alice" },
20
+ { email: "bob@prisma.io", username: "bob", name: "Bob" },
21
+ { email: "carol@prisma.io", username: "carol", name: "Carol" },
22
+ ];
23
+
24
+ let createdCount = 0;
25
+
26
+ {{#if (eq provider "mongo")}}
27
+ try {
28
+ for (const user of seedUsers) {
29
+ const existingUser = await db.orm.users.where({ email: user.email }).first();
30
+ if (!existingUser) {
31
+ createdCount += await db.orm.users.createCount([user]);
32
+ }
33
+ }
34
+
35
+ console.log(`Seeded ${createdCount} user${createdCount === 1 ? "" : "s"}.`);
36
+ } finally {
37
+ await db.close();
38
+ }
39
+ {{else}}
40
+ try {
41
+ for (const user of seedUsers) {
42
+ const existingUser = await db.orm.User.where({ email: user.email }).first();
43
+ if (!existingUser) {
44
+ createdCount += await db.orm.User.createCount([user]);
45
+ }
46
+ }
47
+
48
+ console.log(`Seeded ${createdCount} user${createdCount === 1 ? "" : "s"}.`);
49
+ } finally {
50
+ await db.runtime().close();
51
+ }
52
+ {{/if}}
@@ -9,27 +9,37 @@ Generated by `create-prisma` with the Astro template.
9
9
  - `{{runScriptCommand packageManager "preview"}}` - preview the production build
10
10
  - `{{runScriptCommand packageManager "astro"}}` - run Astro CLI commands
11
11
 
12
- ## Prisma
12
+ ## Prisma Next
13
13
 
14
- Prisma setup is scaffolded automatically in:
14
+ Prisma Next setup is scaffolded in:
15
15
 
16
- - `prisma/schema.prisma`
17
- - `prisma/seed.ts`
16
+ - `prisma/contract{{#if (eq authoring "typescript")}}.ts{{else}}.prisma{{/if}}`
17
+ - `prisma-next.config.ts`
18
18
  - `src/lib/prisma.ts`
19
19
  - `src/pages/api/users.ts`
20
- - `prisma.config.ts`
21
- - `src/generated/prisma`
22
20
 
23
21
  Database helper scripts are added to `package.json`:
24
22
 
25
- - `db:generate`
26
- - `db:push`
27
- - `db:migrate`
28
- - `db:seed`
29
- {{#if (eq schemaPreset "basic")}}
30
-
31
- The starter page queries a basic `User` model in `src/pages/index.astro`, and `src/pages/api/users.ts` shows an Astro API route backed by the same Prisma client.
23
+ - `{{runScriptCommand packageManager "contract:emit"}}` - emit contract artifacts after contract changes
24
+ {{#if (eq provider "mongo")}}
25
+ - `{{runScriptCommand packageManager "db:up"}}` - start the local MongoDB replica set with `mongodb-memory-server`. Data persists in `.mongo-data/` across restarts.
26
+ - `{{runScriptCommand packageManager "db:down"}}` - stop the local MongoDB process (data preserved)
27
+ - `{{runScriptCommand packageManager "db:reset"}}` - stop and wipe `.mongo-data/` for a clean slate
28
+ - `{{runScriptCommand packageManager "migration:plan"}}` - create a MongoDB migration plan
29
+ - `{{runScriptCommand packageManager "migrate"}}` - apply the planned MongoDB migration
32
30
  {{else}}
33
-
34
- The starter page keeps the official Astro minimal structure and points you to `prisma/schema.prisma` for your first model.
31
+ - `{{runScriptCommand packageManager "db:init"}}` - initialize database state manually
32
+ - `{{runScriptCommand packageManager "db:update"}}` - update database state manually
33
+ - `{{runScriptCommand packageManager "migration:plan"}}` - create a migration plan
34
+ - `{{runScriptCommand packageManager "migrate"}}` - apply a planned migration
35
35
  {{/if}}
36
+
37
+ - `{{runScriptCommand packageManager "db:seed"}}` - insert sample users manually
38
+
39
+ For provider-specific Prisma Next reference docs, see `prisma-next.md`. Prisma Next skills live in the upstream `skills/` directory: https://github.com/prisma/prisma-next/tree/main/skills.
40
+ The Astro Vite dev server also auto-emits Prisma Next contract artifacts when the contract changes.
41
+
42
+ Node-based Prisma Next projects expect Node.js 24 LTS or newer.
43
+
44
+ The starter page queries a basic `User` model in `src/pages/index.astro`, and `src/pages/api/users.ts` shows an Astro API route backed by the same Prisma Next helper.
45
+
@@ -1,5 +1,10 @@
1
1
  // @ts-check
2
+ import { prismaVitePlugin } from "@prisma-next/vite-plugin-contract-emit";
2
3
  import { defineConfig } from "astro/config";
3
4
 
4
5
  // https://astro.build/config
5
- export default defineConfig({});
6
+ export default defineConfig({
7
+ vite: {
8
+ plugins: [prismaVitePlugin()],
9
+ },
10
+ });
@@ -1,5 +1,5 @@
1
1
  {{#if (eq packageManager "deno")}}
2
2
  {
3
- "nodeModulesDir": "auto"
3
+ "nodeModulesDir": "manual"
4
4
  }
5
5
  {{/if}}
@@ -12,11 +12,12 @@
12
12
  "astro": "astro"
13
13
  },
14
14
  "dependencies": {
15
- "astro": "^5.17.1"
15
+ "astro": "^6.3.3"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/node": "^24.3.0",
19
19
  "tsx": "^4.7.1",
20
- "typescript": "^5.9.3"
20
+ "typescript": "^5.9.3",
21
+ "vite": "^7.3.3"
21
22
  }
22
23
  }
@@ -1,53 +1,73 @@
1
1
  import "dotenv/config";
2
- import { PrismaClient } from "../generated/prisma/client";
3
- {{#if (eq provider "postgresql")}}
4
- import { PrismaPg } from "@prisma/adapter-pg";
5
- {{/if}}
6
- {{#if (eq provider "cockroachdb")}}
7
- import { PrismaPg } from "@prisma/adapter-pg";
8
- {{/if}}
9
- {{#if (eq provider "mysql")}}
10
- import { PrismaMariaDb } from "@prisma/adapter-mariadb";
11
- {{/if}}
12
- {{#if (eq provider "sqlite")}}
13
- import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3";
14
- {{/if}}
15
- {{#if (eq provider "sqlserver")}}
16
- import { PrismaMssql } from "@prisma/adapter-mssql";
2
+ {{#if (eq provider "mongo")}}
3
+ import mongo from "@prisma-next/mongo/runtime";
4
+ {{else}}
5
+ import postgres from "@prisma-next/postgres/runtime";
17
6
  {{/if}}
18
7
 
19
- {{#if (eq provider "sqlite")}}
20
- const databaseUrl =
21
- import.meta.env?.DATABASE_URL ?? process.env.DATABASE_URL ?? "file:./dev.db";
8
+ {{#if (eq provider "mongo")}}
9
+ import type { DefaultModelRow } from "@prisma-next/mongo-orm";
22
10
  {{else}}
23
- const databaseUrl = import.meta.env?.DATABASE_URL ?? process.env.DATABASE_URL;
24
- if (!databaseUrl) {
25
- throw new Error("DATABASE_URL is required");
26
- }
11
+ import type { DefaultModelRow } from "@prisma-next/sql-orm-client";
27
12
  {{/if}}
28
13
 
29
- {{#if (eq provider "postgresql")}}
30
- const adapter = new PrismaPg({
31
- connectionString: databaseUrl,
14
+ import type { Contract } from "../../prisma/contract.d";
15
+ import contractJson from "../../prisma/contract.json" with { type: "json" };
16
+
17
+ {{#if (eq provider "mongo")}}
18
+ export const db = mongo<Contract>({
19
+ contractJson,
20
+ url: process.env["DATABASE_URL"]!,
32
21
  });
33
- {{/if}}
34
- {{#if (eq provider "cockroachdb")}}
35
- const adapter = new PrismaPg({
36
- connectionString: databaseUrl,
22
+ {{else}}
23
+ export const db = postgres<Contract>({
24
+ contractJson,
25
+ url: process.env["DATABASE_URL"]!,
37
26
  });
38
27
  {{/if}}
39
- {{#if (eq provider "mysql")}}
40
- const adapter = new PrismaMariaDb(databaseUrl);
41
- {{/if}}
42
- {{#if (eq provider "sqlite")}}
43
- const adapter = new PrismaBetterSqlite3({
44
- url: databaseUrl,
45
- });
28
+
29
+ type UserRow = DefaultModelRow<Contract, "User">;
30
+
31
+ {{#if (eq provider "mongo")}}
32
+ function toStarterUser(user: Pick<UserRow, "_id" | "email" | "username" | "name">) {
33
+ return {
34
+ id: String(user._id),
35
+ email: user.email,
36
+ username: user.username ?? null,
37
+ name: user.name ?? null,
38
+ createdAt: null as Date | null,
39
+ };
40
+ }
41
+ {{else}}
42
+ function toStarterUser(user: Pick<UserRow, "id" | "email" | "username" | "name" | "createdAt">) {
43
+ return {
44
+ id: String(user.id),
45
+ email: user.email,
46
+ username: user.username ?? null,
47
+ name: user.name ?? null,
48
+ createdAt: user.createdAt,
49
+ };
50
+ }
46
51
  {{/if}}
47
- {{#if (eq provider "sqlserver")}}
48
- const adapter = new PrismaMssql(databaseUrl);
52
+
53
+ export async function listUsers(limit = 10) {
54
+
55
+ {{#if (eq provider "mongo")}}
56
+ const users: ReturnType<typeof toStarterUser>[] = [];
57
+
58
+ for await (const user of db.orm.users.select("_id", "email", "username", "name").take(limit).all()) {
59
+ users.push(toStarterUser(user));
60
+ }
61
+
62
+ return users;
63
+ {{else}}
64
+ const users = await db.orm.User.select("id", "email", "username", "name", "createdAt").take(limit).all();
65
+
66
+ return users.map(toStarterUser);
49
67
  {{/if}}
50
68
 
51
- const prisma = new PrismaClient({ adapter });
69
+ }
70
+
71
+ export type StarterUser = Awaited<ReturnType<typeof listUsers>>[number];
52
72
 
53
- export default prisma;
73
+ export default db;
@@ -1,19 +1,12 @@
1
1
  import type { APIRoute } from "astro";
2
- {{#if (eq schemaPreset "basic")}}
3
- import prisma from "../../lib/prisma";
2
+
3
+ import { listUsers } from "../../lib/prisma";
4
4
 
5
5
  export const GET: APIRoute = async () => {
6
- const users = await prisma.user
7
- .findMany({
8
- take: 10,
9
- orderBy: {
10
- createdAt: "desc",
11
- },
12
- })
13
- .catch((error) => {
14
- console.error("Failed to query users:", error);
15
- return undefined;
16
- });
6
+ const users = await listUsers(10).catch((error) => {
7
+ console.error("Failed to query users:", error);
8
+ return undefined;
9
+ });
17
10
 
18
11
  if (!users) {
19
12
  return new Response(JSON.stringify({ error: "Could not query users yet." }), {
@@ -30,13 +23,4 @@ export const GET: APIRoute = async () => {
30
23
  },
31
24
  });
32
25
  };
33
- {{else}}
34
26
 
35
- export const GET: APIRoute = async () => {
36
- return new Response(JSON.stringify([]), {
37
- headers: {
38
- "Content-Type": "application/json",
39
- },
40
- });
41
- };
42
- {{/if}}
@@ -1,21 +1,14 @@
1
1
  ---
2
- {{#if (eq schemaPreset "basic")}}
3
- import prisma from "../lib/prisma";
2
+
3
+ import { listUsers } from "../lib/prisma";
4
4
 
5
5
  const formatter = new Intl.DateTimeFormat("en", {
6
6
  dateStyle: "medium",
7
7
  timeStyle: "short",
8
8
  });
9
9
 
10
- const users = await prisma.user
11
- .findMany({
12
- take: 10,
13
- orderBy: {
14
- createdAt: "desc",
15
- },
16
- })
17
- .catch(() => undefined);
18
- {{/if}}
10
+ const users = await listUsers(10).catch(() => undefined);
11
+
19
12
  ---
20
13
 
21
14
  <html lang="en">
@@ -29,11 +22,11 @@ const users = await prisma.user
29
22
  <body>
30
23
  <main class="shell">
31
24
  <div class="hero">
32
- <p class="eyebrow">Astro + Prisma 7</p>
33
- {{#if (eq schemaPreset "basic")}}
25
+ <p class="eyebrow">Astro + Prisma Next</p>
26
+
34
27
  <h1>Users from your database, loaded on the server.</h1>
35
28
  <p class="lede">
36
- This page reads from <code>src/pages/index.astro</code> using the Prisma instance in
29
+ This page reads from <code>src/pages/index.astro</code> using the Prisma Next helper in
37
30
  <code>src/lib/prisma.ts</code>. An Astro API route is also scaffolded in
38
31
  <code>src/pages/api/users.ts</code>.
39
32
  </p>
@@ -47,63 +40,32 @@ const users = await prisma.user
47
40
 
48
41
  {!users ? (
49
42
  <p class="empty">
50
- Could not query users yet. Run <code>db:migrate</code>, then <code>db:seed</code>,
43
+ Could not query users yet. Run <code>contract:emit</code> and apply your schema,
51
44
  then refresh.
52
45
  </p>
53
46
  ) : users.length === 0 ? (
54
- <p class="empty">No users yet. Run <code>db:seed</code> after your first migration.</p>
47
+ <p class="empty">No users yet. Run db:seed after applying your first migration.</p>
55
48
  ) : (
56
49
  <ul class="users">
57
50
  {users.map((user) => (
58
51
  <li>
59
52
  <div>
60
53
  <strong>{user.name ?? "Unnamed user"}</strong>
61
- <p>{user.email}</p>
54
+ <p>{user.username ? `@${user.username}` : user.email}</p>
62
55
  </div>
63
- <time datetime={user.createdAt.toISOString()}>
64
- {formatter.format(user.createdAt)}
65
- </time>
56
+ {user.createdAt ? (
57
+ <time datetime={user.createdAt.toISOString()}>
58
+ {formatter.format(user.createdAt)}
59
+ </time>
60
+ ) : (
61
+ <span class="muted">No timestamp</span>
62
+ )}
66
63
  </li>
67
64
  ))}
68
65
  </ul>
69
66
  )}
70
67
  </section>
71
- {{else}}
72
- <h1>Your Astro app is ready.</h1>
73
- <p class="lede">
74
- Edit <code>prisma/schema.prisma</code>, run <code>db:migrate</code>, then load your data
75
- in Astro pages or API routes with the Prisma instance in <code>src/lib/prisma.ts</code>.
76
- </p>
77
- </div>
78
68
 
79
- <section class="panel">
80
- <div class="panel-header">
81
- <h2>What's included</h2>
82
- <span>Starter kit</span>
83
- </div>
84
-
85
- <ul class="users">
86
- <li>
87
- <div>
88
- <strong>Prisma client</strong>
89
- <p>Use the shared instance from <code>src/lib/prisma.ts</code>.</p>
90
- </div>
91
- </li>
92
- <li>
93
- <div>
94
- <strong>API route example</strong>
95
- <p>See <code>src/pages/api/users.ts</code> for an Astro server endpoint.</p>
96
- </div>
97
- </li>
98
- <li>
99
- <div>
100
- <strong>Seed script</strong>
101
- <p>Run <code>db:seed</code> after your first migration.</p>
102
- </div>
103
- </li>
104
- </ul>
105
- </section>
106
- {{/if}}
107
69
  </main>
108
70
  </body>
109
71
  </html>
@@ -171,6 +133,7 @@ const users = await prisma.user
171
133
 
172
134
  .panel-header span,
173
135
  .empty,
136
+ .muted,
174
137
  time {
175
138
  color: #888;
176
139
  font-size: 0.8rem;