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
@@ -3,13 +3,12 @@
3
3
  "target": "ES2022",
4
4
  "module": "ESNext",
5
5
  "moduleResolution": "Bundler",
6
+ "resolveJsonModule": true,
6
7
  "verbatimModuleSyntax": true,
7
8
  "strict": true,
8
9
  "esModuleInterop": true,
9
10
  "skipLibCheck": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "outDir": "dist",
12
- "rootDir": "."
11
+ "forceConsistentCasingInFileNames": true
13
12
  },
14
- "include": ["src/**/*.ts"]
13
+ "include": ["src/**/*.ts", "prisma/**/*.ts"]
15
14
  }
@@ -8,25 +8,36 @@ Generated by `create-prisma` with the NestJS template.
8
8
  - `{{runScriptCommand packageManager "build"}}` - {{#if (eq packageManager "deno")}}type-check the app with Deno{{else}}{{#if (eq packageManager "bun")}}type-check the app for Bun{{else}}compile the app into `dist/`{{/if}}{{/if}}
9
9
  - `{{runScriptCommand packageManager "start"}}` - {{#if (eq packageManager "deno")}}run the server directly from `src/main.ts` with Deno{{else}}{{#if (eq packageManager "bun")}}run the server directly from `src/main.ts` with Bun{{else}}run the compiled server from `dist/main.js`{{/if}}{{/if}}
10
10
 
11
- ## Prisma
12
-
13
- 1. Make sure dependencies are installed.
14
- 2. Generate Prisma Client:
15
-
16
- `{{runScriptCommand packageManager "db:generate"}}`
17
-
18
- 3. Run your first migration:
19
-
20
- `{{runScriptCommand packageManager "db:migrate"}}`
11
+ ## Prisma Next
12
+
13
+ Prisma Next setup is scaffolded in:
14
+
15
+ - `prisma/contract{{#if (eq authoring "typescript")}}.ts{{else}}.prisma{{/if}}`
16
+ - `prisma-next.config.ts`
17
+ - `src/lib/prisma.ts`
18
+ - `src/prisma.service.ts`
19
+
20
+ Database helper scripts are added to `package.json`:
21
+
22
+ - `{{runScriptCommand packageManager "contract:emit"}}` - emit contract artifacts after contract changes
23
+ {{#if (eq provider "mongo")}}
24
+ - `{{runScriptCommand packageManager "db:up"}}` - start the local MongoDB replica set with `mongodb-memory-server`. Data persists in `.mongo-data/` across restarts.
25
+ - `{{runScriptCommand packageManager "db:down"}}` - stop the local MongoDB process (data preserved)
26
+ - `{{runScriptCommand packageManager "db:reset"}}` - stop and wipe `.mongo-data/` for a clean slate
27
+ - `{{runScriptCommand packageManager "migration:plan"}}` - create a MongoDB migration plan
28
+ - `{{runScriptCommand packageManager "migrate"}}` - apply the planned MongoDB migration
29
+ {{else}}
30
+ - `{{runScriptCommand packageManager "db:init"}}` - initialize database state manually
31
+ - `{{runScriptCommand packageManager "db:update"}}` - update database state manually
32
+ - `{{runScriptCommand packageManager "migration:plan"}}` - create a migration plan
33
+ - `{{runScriptCommand packageManager "migrate"}}` - apply a planned migration
34
+ {{/if}}
21
35
 
22
- 4. Seed the database:
36
+ - `{{runScriptCommand packageManager "db:seed"}}` - insert sample users manually
23
37
 
24
- `{{runScriptCommand packageManager "db:seed"}}`
38
+ 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.
25
39
 
26
- 5. Use the shared Prisma setup from `src/lib/prisma.ts` and inject `PrismaService` from `src/prisma.service.ts` inside Nest providers.
40
+ Node-based Prisma Next projects expect Node.js 24 LTS or newer.
27
41
 
28
- Generated Prisma files are written to `src/generated/prisma`.
29
- {{#if (eq schemaPreset "basic")}}
42
+ The template includes a basic `User` model and a sample `GET /users` endpoint.
30
43
 
31
- The template includes a basic `User` model, a sample `GET /users` endpoint, and seed data in `prisma/seed.ts`.
32
- {{/if}}
@@ -1,5 +1,5 @@
1
1
  {{#if (eq packageManager "deno")}}
2
2
  {
3
- "nodeModulesDir": "auto"
3
+ "nodeModulesDir": "manual"
4
4
  }
5
5
  {{/if}}
@@ -1,20 +1,19 @@
1
1
  import { Module } from "@nestjs/common";
2
2
  import { AppController } from "./app.controller{{#if (eq packageManager "deno")}}.ts{{/if}}";
3
3
  import { PrismaService } from "./prisma.service{{#if (eq packageManager "deno")}}.ts{{/if}}";
4
- {{#if (eq schemaPreset "basic")}}
4
+
5
5
  import { UsersController } from "./users.controller{{#if (eq packageManager "deno")}}.ts{{/if}}";
6
6
  import { UsersService } from "./users.service{{#if (eq packageManager "deno")}}.ts{{/if}}";
7
- {{/if}}
8
7
 
9
8
  @Module({
10
9
  imports: [],
11
10
  controllers: [
12
- AppController{{#if (eq schemaPreset "basic")}},
13
- UsersController{{/if}}
11
+ AppController,
12
+ UsersController
14
13
  ],
15
14
  providers: [
16
- PrismaService{{#if (eq schemaPreset "basic")}},
17
- UsersService{{/if}}
15
+ PrismaService,
16
+ UsersService
18
17
  ],
19
18
  })
20
19
  export class AppModule {}
@@ -1,58 +1,73 @@
1
- {{#if (requiresDotenvConfigImport packageManager)}}
2
1
  import "dotenv/config";
2
+ {{#if (eq provider "mongo")}}
3
+ import mongo from "@prisma-next/mongo/runtime";
4
+ {{else}}
5
+ import postgres from "@prisma-next/postgres/runtime";
3
6
  {{/if}}
4
7
 
5
- import { PrismaClient } from "../generated/prisma/client{{#if (eq packageManager "deno")}}.ts{{/if}}";
6
- {{#if (eq provider "postgresql")}}
7
- import { PrismaPg } from "@prisma/adapter-pg";
8
- {{/if}}
9
- {{#if (eq provider "cockroachdb")}}
10
- import { PrismaPg } from "@prisma/adapter-pg";
11
- {{/if}}
12
- {{#if (eq provider "mysql")}}
13
- import { PrismaMariaDb } from "@prisma/adapter-mariadb";
14
- {{/if}}
15
- {{#if (eq provider "sqlite")}}
16
- import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3";
17
- {{/if}}
18
- {{#if (eq provider "sqlserver")}}
19
- import { PrismaMssql } from "@prisma/adapter-mssql";
20
- {{/if}}
21
-
22
- const rawDatabaseUrl = {{#if (eq packageManager "deno")}}Deno.env.get("DATABASE_URL"){{else}}process.env.DATABASE_URL{{/if}};
23
- {{#if (eq provider "sqlite")}}
24
- const databaseUrl = (rawDatabaseUrl ?? "").trim() || "file:./dev.db";
8
+ {{#if (eq provider "mongo")}}
9
+ import type { DefaultModelRow } from "@prisma-next/mongo-orm";
25
10
  {{else}}
26
- const databaseUrl = (rawDatabaseUrl ?? "").trim();
27
- if (!databaseUrl) {
28
- throw new Error("DATABASE_URL is required");
29
- }
11
+ import type { DefaultModelRow } from "@prisma-next/sql-orm-client";
30
12
  {{/if}}
31
13
 
32
- {{#if (eq provider "postgresql")}}
33
- const adapter = new PrismaPg({
34
- connectionString: databaseUrl,
35
- });
36
- {{/if}}
37
- {{#if (eq provider "cockroachdb")}}
38
- const adapter = new PrismaPg({
39
- 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"]!,
40
21
  });
41
- {{/if}}
42
- {{#if (eq provider "mysql")}}
43
- const adapter = new PrismaMariaDb(databaseUrl);
44
- {{/if}}
45
- {{#if (eq provider "sqlite")}}
46
- const adapter = new PrismaBetterSqlite3({
47
- url: databaseUrl,
22
+ {{else}}
23
+ export const db = postgres<Contract>({
24
+ contractJson,
25
+ url: process.env["DATABASE_URL"]!,
48
26
  });
49
27
  {{/if}}
50
- {{#if (eq provider "sqlserver")}}
51
- const adapter = new PrismaMssql(databaseUrl);
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
+ }
52
51
  {{/if}}
53
52
 
54
- export const prismaClientOptions = { adapter };
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);
67
+ {{/if}}
55
68
 
56
- export function createPrismaClient() {
57
- return new PrismaClient(prismaClientOptions);
58
69
  }
70
+
71
+ export type StarterUser = Awaited<ReturnType<typeof listUsers>>[number];
72
+
73
+ export default db;
@@ -1,10 +1,11 @@
1
1
  import { Injectable } from "@nestjs/common";
2
- import { PrismaClient } from "./generated/prisma/client{{#if (eq packageManager "deno")}}.ts{{/if}}";
3
- import { prismaClientOptions } from "./lib/prisma{{#if (eq packageManager "deno")}}.ts{{/if}}";
2
+ import { db, listUsers, type StarterUser } from "./lib/prisma{{#if (eq packageManager "deno")}}.ts{{/if}}";
4
3
 
5
4
  @Injectable()
6
- export class PrismaService extends PrismaClient {
7
- constructor() {
8
- super(prismaClientOptions);
5
+ export class PrismaService {
6
+ readonly db = db;
7
+
8
+ listUsers(limit = 10): Promise<StarterUser[]> {
9
+ return listUsers(limit);
9
10
  }
10
11
  }
@@ -1,4 +1,3 @@
1
- {{#if (eq schemaPreset "basic")}}
2
1
  import { Controller, Get } from "@nestjs/common";
3
2
 
4
3
  import { UsersService } from "./users.service{{#if (eq packageManager "deno")}}.ts{{/if}}";
@@ -12,4 +11,4 @@ export class UsersController {
12
11
  return this.usersService.findAll();
13
12
  }
14
13
  }
15
- {{/if}}
14
+
@@ -1,4 +1,3 @@
1
- {{#if (eq schemaPreset "basic")}}
2
1
  import { Injectable } from "@nestjs/common";
3
2
 
4
3
  import { PrismaService } from "./prisma.service{{#if (eq packageManager "deno")}}.ts{{/if}}";
@@ -8,12 +7,7 @@ export class UsersService {
8
7
  constructor(private readonly prisma: PrismaService) {}
9
8
 
10
9
  async findAll() {
11
- return this.prisma.user.findMany({
12
- take: 10,
13
- orderBy: {
14
- createdAt: "desc",
15
- },
16
- });
10
+ return this.prisma.listUsers(10);
17
11
  }
18
12
  }
19
- {{/if}}
13
+
@@ -3,6 +3,7 @@
3
3
  "target": "ES2022",
4
4
  "module": "ESNext",
5
5
  "moduleResolution": "Bundler",
6
+ "resolveJsonModule": true,
6
7
  "verbatimModuleSyntax": true,
7
8
  "strict": true,
8
9
  "esModuleInterop": true,
@@ -8,23 +8,35 @@ Generated by `create-prisma` with the Next.js template.
8
8
  - `{{runScriptCommand packageManager "build"}}` - production build
9
9
  - `{{runScriptCommand packageManager "start"}}` - run production server
10
10
 
11
- ## Prisma
11
+ ## Prisma Next
12
12
 
13
- Prisma setup is scaffolded automatically in:
13
+ Prisma Next setup is scaffolded in:
14
14
 
15
- - `prisma/schema.prisma`
16
- - `prisma/seed.ts`
15
+ - `prisma/contract{{#if (eq authoring "typescript")}}.ts{{else}}.prisma{{/if}}`
16
+ - `prisma-next.config.ts`
17
17
  - `src/lib/prisma.ts`
18
- - `prisma.config.ts`
19
- - `src/generated/prisma`
20
18
 
21
19
  Database helper scripts are added to `package.json`:
22
20
 
23
- - `db:generate`
24
- - `db:push`
25
- - `db:migrate`
26
- - `db:seed`
27
- {{#if (eq schemaPreset "basic")}}
28
-
29
- The starter page in `src/app/page.tsx` reads from a basic `User` model so you can verify queries quickly, and `prisma/seed.ts` inserts starter users.
21
+ - `{{runScriptCommand packageManager "contract:emit"}}` - emit contract artifacts after contract changes
22
+ {{#if (eq provider "mongo")}}
23
+ - `{{runScriptCommand packageManager "db:up"}}` - start the local MongoDB replica set with `mongodb-memory-server`. Data persists in `.mongo-data/` across restarts.
24
+ - `{{runScriptCommand packageManager "db:down"}}` - stop the local MongoDB process (data preserved)
25
+ - `{{runScriptCommand packageManager "db:reset"}}` - stop and wipe `.mongo-data/` for a clean slate
26
+ - `{{runScriptCommand packageManager "migration:plan"}}` - create a MongoDB migration plan
27
+ - `{{runScriptCommand packageManager "migrate"}}` - apply the planned MongoDB migration
28
+ {{else}}
29
+ - `{{runScriptCommand packageManager "db:init"}}` - initialize database state manually
30
+ - `{{runScriptCommand packageManager "db:update"}}` - update database state manually
31
+ - `{{runScriptCommand packageManager "migration:plan"}}` - create a migration plan
32
+ - `{{runScriptCommand packageManager "migrate"}}` - apply a planned migration
30
33
  {{/if}}
34
+
35
+ - `{{runScriptCommand packageManager "db:seed"}}` - insert sample users manually
36
+
37
+ 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.
38
+
39
+ Node-based Prisma Next projects expect Node.js 24 LTS or newer.
40
+
41
+ The starter page in `src/app/page.tsx` reads from a basic `User` model so you can verify queries quickly after you initialize and apply your schema.
42
+
@@ -1,6 +1,6 @@
1
1
  {{#if (eq packageManager "deno")}}
2
2
  {
3
- "nodeModulesDir": "auto",
3
+ "nodeModulesDir": "manual",
4
4
  "unstable": [
5
5
  "bare-node-builtins",
6
6
  "detect-cjs",
@@ -1,35 +1,25 @@
1
- {{#if (eq schemaPreset "basic")}}
2
- import { prisma } from "../lib/prisma";
3
- {{/if}}
4
1
  {{#if (eq packageManager "deno")}}
5
2
 
6
3
  export const dynamic = "force-dynamic";
7
4
  {{/if}}
8
5
 
9
6
  export default async function Home() {
10
- {{#if (eq schemaPreset "basic")}}
7
+
8
+ const { listUsers } = await import("../lib/prisma");
11
9
  const formatter = new Intl.DateTimeFormat("en", {
12
10
  dateStyle: "medium",
13
11
  timeStyle: "short",
14
12
  });
15
- const users = await prisma.user
16
- .findMany({
17
- take: 10,
18
- orderBy: {
19
- createdAt: "desc",
20
- },
21
- })
22
- .catch(() => undefined);
23
- {{/if}}
13
+ const users = await listUsers(10).catch(() => undefined);
24
14
 
25
15
  return (
26
16
  <main className="shell">
27
17
  <div className="hero">
28
- <p className="eyebrow">Next.js + Prisma 7</p>
29
- {{#if (eq schemaPreset "basic")}}
18
+ <p className="eyebrow">Next.js + Prisma Next</p>
19
+
30
20
  <h1>Users from your database, loaded on the server.</h1>
31
21
  <p className="lede">
32
- This page reads from <code>src/app/page.tsx</code> using the Prisma instance in{" "}
22
+ This page reads from <code>src/app/page.tsx</code> using the Prisma Next helper in{" "}
33
23
  <code>src/lib/prisma.ts</code>.
34
24
  </p>
35
25
  </div>
@@ -42,63 +32,32 @@ export default async function Home() {
42
32
 
43
33
  {!users ? (
44
34
  <p className="empty">
45
- Could not query users yet. Run <code>db:migrate</code>, then <code>db:seed</code>,
35
+ Could not query users yet. Run <code>contract:emit</code> and apply your schema,
46
36
  then refresh.
47
37
  </p>
48
38
  ) : users.length === 0 ? (
49
- <p className="empty">No users yet. Run <code>db:seed</code> after your first migration.</p>
39
+ <p className="empty">No users yet. Run db:seed after applying your first migration.</p>
50
40
  ) : (
51
41
  <ul className="users">
52
42
  {users.map((user) => (
53
43
  <li key={user.id}>
54
44
  <div>
55
45
  <strong>{user.name ?? "Unnamed user"}</strong>
56
- <p>{user.email}</p>
46
+ <p>{user.username ? `@${user.username}` : user.email}</p>
57
47
  </div>
58
- <time dateTime={user.createdAt.toISOString()}>
59
- {formatter.format(user.createdAt)}
60
- </time>
48
+ {user.createdAt ? (
49
+ <time dateTime={user.createdAt.toISOString()}>
50
+ {formatter.format(user.createdAt)}
51
+ </time>
52
+ ) : (
53
+ <span className="empty">No timestamp</span>
54
+ )}
61
55
  </li>
62
56
  ))}
63
57
  </ul>
64
58
  )}
65
59
  </section>
66
- {{else}}
67
- <h1>Your Next.js app is ready.</h1>
68
- <p className="lede">
69
- Edit <code>prisma/schema.prisma</code>, run <code>db:migrate</code>, then load your data
70
- in server components with the Prisma instance in <code>src/lib/prisma.ts</code>.
71
- </p>
72
- </div>
73
60
 
74
- <section className="panel">
75
- <div className="panelHeader">
76
- <h2>What&apos;s included</h2>
77
- <span>Starter kit</span>
78
- </div>
79
-
80
- <ul className="users">
81
- <li>
82
- <div>
83
- <strong>Prisma client</strong>
84
- <p>Use the shared instance from <code>src/lib/prisma.ts</code>.</p>
85
- </div>
86
- </li>
87
- <li>
88
- <div>
89
- <strong>Seed script</strong>
90
- <p>Run <code>db:seed</code> after your first migration.</p>
91
- </div>
92
- </li>
93
- <li>
94
- <div>
95
- <strong>Generated client output</strong>
96
- <p>Prisma Client is generated into <code>src/generated/prisma</code>.</p>
97
- </div>
98
- </li>
99
- </ul>
100
- </section>
101
- {{/if}}
102
61
  </main>
103
62
  );
104
63
  }
@@ -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 = process.env.DATABASE_URL ?? "file:./dev.db";
8
+ {{#if (eq provider "mongo")}}
9
+ import type { DefaultModelRow } from "@prisma-next/mongo-orm";
21
10
  {{else}}
22
- const databaseUrl = process.env.DATABASE_URL;
23
- if (!databaseUrl) {
24
- throw new Error("DATABASE_URL is required");
25
- }
11
+ import type { DefaultModelRow } from "@prisma-next/sql-orm-client";
26
12
  {{/if}}
27
13
 
28
- {{#if (eq provider "postgresql")}}
29
- const adapter = new PrismaPg({
30
- 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"]!,
31
21
  });
32
- {{/if}}
33
- {{#if (eq provider "cockroachdb")}}
34
- const adapter = new PrismaPg({
35
- connectionString: databaseUrl,
22
+ {{else}}
23
+ export const db = postgres<Contract>({
24
+ contractJson,
25
+ url: process.env["DATABASE_URL"]!,
36
26
  });
37
27
  {{/if}}
38
- {{#if (eq provider "mysql")}}
39
- const adapter = new PrismaMariaDb(databaseUrl);
40
- {{/if}}
41
- {{#if (eq provider "sqlite")}}
42
- const adapter = new PrismaBetterSqlite3({
43
- url: databaseUrl,
44
- });
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
+ }
45
51
  {{/if}}
46
- {{#if (eq provider "sqlserver")}}
47
- 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);
48
67
  {{/if}}
49
68
 
50
- const prisma = new PrismaClient({ adapter });
69
+ }
70
+
71
+ export type StarterUser = Awaited<ReturnType<typeof listUsers>>[number];
51
72
 
52
- export { prisma };
53
- export default prisma;
73
+ export default db;
@@ -9,6 +9,7 @@
9
9
  "esModuleInterop": true,
10
10
  "module": "esnext",
11
11
  "moduleResolution": "bundler",
12
+ "allowImportingTsExtensions": true,
12
13
  "resolveJsonModule": true,
13
14
  "isolatedModules": true,
14
15
  "jsx": "react-jsx",
@@ -9,24 +9,37 @@ Generated by `create-prisma` with the Nuxt template.
9
9
  - `{{runScriptCommand packageManager "preview"}}` - preview the production build
10
10
  - `{{runScriptCommand packageManager "typecheck"}}` - run Nuxt type checks
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
  - `server/utils/prisma.ts`
19
19
  - `server/api/users.get.ts`
20
- - `prisma.config.ts`
21
- - `server/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 in `app/pages/index.vue` fetches seeded users from `server/api/users.get.ts`, and `prisma/seed.ts` inserts starter users.
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
30
+ {{else}}
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
32
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 Nuxt 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 in `app/pages/index.vue` fetches users from `server/api/users.get.ts` after you initialize and apply your schema.
45
+