create-prisma 0.4.1 → 0.4.2-next.37.80.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 (119) hide show
  1. package/README.md +43 -35
  2. package/dist/cli.mjs +1 -1
  3. package/dist/{create-H6Tk0JlE.mjs → create-CfH21J9-.mjs} +529 -914
  4. package/dist/index.d.mts +28 -25
  5. package/dist/index.mjs +3 -3
  6. package/package.json +2 -2
  7. package/templates/create/_shared/packages/db/prisma/seed.ts.hbs +43 -0
  8. package/templates/create/_shared/prisma/seed.ts.hbs +55 -0
  9. package/templates/create/astro/README.md.hbs +23 -12
  10. package/templates/create/astro/deno.json.hbs +1 -1
  11. package/templates/create/astro/prisma/contract.prisma.hbs +44 -0
  12. package/templates/create/astro/prisma/contract.ts.hbs +85 -0
  13. package/templates/create/astro/prisma-next.config.ts.hbs +13 -0
  14. package/templates/create/astro/src/lib/prisma.ts.hbs +49 -43
  15. package/templates/create/astro/src/pages/api/users.ts.hbs +5 -12
  16. package/templates/create/astro/src/pages/index.astro.hbs +19 -21
  17. package/templates/create/elysia/.yarnrc.yml.hbs +3 -0
  18. package/templates/create/elysia/README.md.hbs +27 -18
  19. package/templates/create/elysia/deno.json.hbs +1 -1
  20. package/templates/create/elysia/prisma/contract.prisma.hbs +44 -0
  21. package/templates/create/elysia/prisma/contract.ts.hbs +85 -0
  22. package/templates/create/elysia/prisma-next.config.ts.hbs +13 -0
  23. package/templates/create/elysia/src/index.ts.hbs +12 -7
  24. package/templates/create/elysia/src/lib/prisma.ts.hbs +49 -46
  25. package/templates/create/elysia/tsconfig.json +1 -0
  26. package/templates/create/hono/README.md.hbs +27 -18
  27. package/templates/create/hono/deno.json.hbs +1 -1
  28. package/templates/create/hono/prisma/contract.prisma.hbs +44 -0
  29. package/templates/create/hono/prisma/contract.ts.hbs +85 -0
  30. package/templates/create/hono/prisma-next.config.ts.hbs +13 -0
  31. package/templates/create/hono/src/index.ts.hbs +8 -6
  32. package/templates/create/hono/src/lib/prisma.ts.hbs +49 -46
  33. package/templates/create/hono/tsconfig.json +1 -0
  34. package/templates/create/nest/README.md.hbs +28 -18
  35. package/templates/create/nest/deno.json.hbs +1 -1
  36. package/templates/create/nest/prisma/contract.prisma.hbs +44 -0
  37. package/templates/create/nest/prisma/contract.ts.hbs +85 -0
  38. package/templates/create/nest/prisma-next.config.ts.hbs +13 -0
  39. package/templates/create/nest/src/lib/prisma.ts.hbs +49 -48
  40. package/templates/create/nest/src/prisma.service.ts.hbs +6 -5
  41. package/templates/create/nest/src/users.service.ts.hbs +1 -6
  42. package/templates/create/nest/tsconfig.json +1 -0
  43. package/templates/create/next/README.md.hbs +22 -11
  44. package/templates/create/next/deno.json.hbs +1 -1
  45. package/templates/create/next/prisma/contract.prisma.hbs +44 -0
  46. package/templates/create/next/prisma/contract.ts.hbs +85 -0
  47. package/templates/create/next/prisma-next.config.ts.hbs +13 -0
  48. package/templates/create/next/src/app/page.tsx.hbs +21 -26
  49. package/templates/create/next/src/lib/prisma.ts.hbs +49 -43
  50. package/templates/create/next/tsconfig.json +1 -0
  51. package/templates/create/nuxt/README.md.hbs +22 -11
  52. package/templates/create/nuxt/app/pages/index.vue.hbs +14 -12
  53. package/templates/create/nuxt/deno.json.hbs +1 -1
  54. package/templates/create/nuxt/nuxt.config.ts +16 -0
  55. package/templates/create/nuxt/prisma/contract.prisma.hbs +44 -0
  56. package/templates/create/nuxt/prisma/contract.ts.hbs +85 -0
  57. package/templates/create/nuxt/prisma-next.config.ts.hbs +13 -0
  58. package/templates/create/nuxt/server/api/users.get.ts.hbs +3 -9
  59. package/templates/create/nuxt/server/utils/prisma.ts.hbs +49 -43
  60. package/templates/create/svelte/README.md.hbs +23 -12
  61. package/templates/create/svelte/deno.json.hbs +1 -1
  62. package/templates/create/svelte/prisma/contract.prisma.hbs +44 -0
  63. package/templates/create/svelte/prisma/contract.ts.hbs +85 -0
  64. package/templates/create/svelte/prisma-next.config.ts.hbs +13 -0
  65. package/templates/create/svelte/src/lib/server/prisma.ts.hbs +50 -44
  66. package/templates/create/svelte/src/routes/+page.server.ts.hbs +3 -9
  67. package/templates/create/svelte/src/routes/+page.svelte.hbs +21 -16
  68. package/templates/create/tanstack-start/README.md.hbs +22 -11
  69. package/templates/create/tanstack-start/deno.json.hbs +1 -2
  70. package/templates/create/tanstack-start/prisma/contract.prisma.hbs +44 -0
  71. package/templates/create/tanstack-start/prisma/contract.ts.hbs +85 -0
  72. package/templates/create/tanstack-start/prisma-next.config.ts.hbs +13 -0
  73. package/templates/create/tanstack-start/src/lib/prisma.server.ts.hbs +49 -43
  74. package/templates/create/tanstack-start/src/routes/__root.tsx.hbs +2 -3
  75. package/templates/create/tanstack-start/src/routes/index.tsx.hbs +27 -38
  76. package/templates/create/tanstack-start/tsconfig.json +1 -0
  77. package/templates/create/turborepo/README.md.hbs +25 -14
  78. package/templates/create/turborepo/apps/api/deno.json.hbs +6 -0
  79. package/templates/create/turborepo/apps/api/package.json.hbs +7 -0
  80. package/templates/create/turborepo/apps/api/src/index.ts.hbs +6 -13
  81. package/templates/create/turborepo/deno.json.hbs +5 -1
  82. package/templates/create/turborepo/package.json.hbs +12 -4
  83. package/templates/create/turborepo/packages/db/deno.json.hbs +6 -0
  84. package/templates/create/turborepo/packages/db/package.json.hbs +5 -0
  85. package/templates/create/turborepo/packages/db/prisma/contract.prisma.hbs +44 -0
  86. package/templates/create/turborepo/packages/db/prisma/contract.ts.hbs +85 -0
  87. package/templates/create/turborepo/packages/db/prisma-next.config.ts.hbs +13 -0
  88. package/templates/create/turborepo/packages/db/src/client.ts.hbs +56 -44
  89. package/templates/create/turborepo/packages/db/src/index.ts +1 -1
  90. package/templates/create/turborepo/packages/db/tsconfig.json +2 -1
  91. package/templates/create/turborepo/pnpm-workspace.yaml.hbs +5 -0
  92. package/templates/create/turborepo/turbo.json +9 -3
  93. package/templates/create/astro/prisma/schema.prisma.hbs +0 -21
  94. package/templates/create/astro/prisma/seed.ts.hbs +0 -38
  95. package/templates/create/astro/prisma.config.ts +0 -13
  96. package/templates/create/elysia/prisma/schema.prisma.hbs +0 -25
  97. package/templates/create/elysia/prisma/seed.ts.hbs +0 -42
  98. package/templates/create/elysia/prisma.config.ts.hbs +0 -15
  99. package/templates/create/hono/prisma/schema.prisma.hbs +0 -25
  100. package/templates/create/hono/prisma/seed.ts.hbs +0 -42
  101. package/templates/create/hono/prisma.config.ts.hbs +0 -15
  102. package/templates/create/nest/prisma/schema.prisma.hbs +0 -25
  103. package/templates/create/nest/prisma/seed.ts.hbs +0 -44
  104. package/templates/create/nest/prisma.config.ts.hbs +0 -15
  105. package/templates/create/next/prisma/schema.prisma.hbs +0 -21
  106. package/templates/create/next/prisma/seed.ts.hbs +0 -38
  107. package/templates/create/next/prisma.config.ts +0 -13
  108. package/templates/create/nuxt/prisma/schema.prisma.hbs +0 -21
  109. package/templates/create/nuxt/prisma/seed.ts.hbs +0 -38
  110. package/templates/create/nuxt/prisma.config.ts +0 -13
  111. package/templates/create/svelte/prisma/schema.prisma.hbs +0 -21
  112. package/templates/create/svelte/prisma/seed.ts.hbs +0 -87
  113. package/templates/create/svelte/prisma.config.ts +0 -13
  114. package/templates/create/tanstack-start/prisma/schema.prisma.hbs +0 -21
  115. package/templates/create/tanstack-start/prisma/seed.ts.hbs +0 -37
  116. package/templates/create/tanstack-start/prisma.config.ts +0 -13
  117. package/templates/create/turborepo/packages/db/prisma/schema.prisma.hbs +0 -21
  118. package/templates/create/turborepo/packages/db/prisma/seed.ts.hbs +0 -38
  119. package/templates/create/turborepo/packages/db/prisma.config.ts +0 -13
@@ -1,53 +1,59 @@
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";
17
- {{/if}}
18
-
19
- {{#if (eq provider "sqlite")}}
20
- const databaseUrl = process.env.DATABASE_URL ?? "file:./dev.db";
2
+ {{#if (eq provider "mongo")}}
3
+ import mongo from "@prisma-next/mongo/runtime";
21
4
  {{else}}
22
- const databaseUrl = process.env.DATABASE_URL;
23
- if (!databaseUrl) {
24
- throw new Error("DATABASE_URL is required");
25
- }
5
+ import postgres from "@prisma-next/postgres/runtime";
26
6
  {{/if}}
7
+ import type { Contract } from "../../prisma/contract.d";
8
+ import contractJson from "../../prisma/contract.json" with { type: "json" };
27
9
 
28
- {{#if (eq provider "postgresql")}}
29
- const adapter = new PrismaPg({
30
- connectionString: databaseUrl,
10
+ {{#if (eq provider "mongo")}}
11
+ export const db = mongo<Contract>({
12
+ contractJson,
13
+ url: process.env["DATABASE_URL"],
31
14
  });
32
- {{/if}}
33
- {{#if (eq provider "cockroachdb")}}
34
- const adapter = new PrismaPg({
35
- connectionString: databaseUrl,
15
+ {{else}}
16
+ export const db = postgres<Contract>({
17
+ contractJson,
18
+ url: process.env["DATABASE_URL"],
36
19
  });
37
20
  {{/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
- });
21
+
22
+ export type StarterUser = {
23
+ id: string;
24
+ email: string;
25
+ name: string | null;
26
+ createdAt: Date | null;
27
+ };
28
+
29
+ export async function listUsers(limit = 10): Promise<StarterUser[]> {
30
+ {{#if (eq schemaPreset "basic")}}
31
+ {{#if (eq provider "mongo")}}
32
+ const users: StarterUser[] = [];
33
+
34
+ for await (const user of db.orm.users.select("_id", "email", "name").take(limit).all()) {
35
+ users.push({
36
+ id: String(user._id),
37
+ email: user.email,
38
+ name: user.name ?? null,
39
+ createdAt: null,
40
+ });
41
+ }
42
+
43
+ return users;
44
+ {{else}}
45
+ const users = await db.orm.User.select("id", "email", "name", "createdAt").take(limit).all();
46
+
47
+ return users.map((user) => ({
48
+ id: String(user.id),
49
+ email: user.email,
50
+ name: user.name ?? null,
51
+ createdAt: user.createdAt,
52
+ }));
45
53
  {{/if}}
46
- {{#if (eq provider "sqlserver")}}
47
- const adapter = new PrismaMssql(databaseUrl);
54
+ {{else}}
55
+ return [];
48
56
  {{/if}}
57
+ }
49
58
 
50
- const prisma = new PrismaClient({ adapter });
51
-
52
- export { prisma };
53
- export default prisma;
59
+ export default db;
@@ -9,26 +9,37 @@ Generated by `create-prisma` with the SvelteKit template.
9
9
  - `{{runScriptCommand packageManager "preview"}}` - preview the production build
10
10
  - `{{runScriptCommand packageManager "check"}}` - run SvelteKit sync and 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
  - `src/lib/server/prisma.ts`
19
- - `prisma.config.ts`
20
- - `src/generated/prisma`
21
19
 
22
20
  Database helper scripts are added to `package.json`:
23
21
 
24
- - `db:generate`
25
- - `db:push`
26
- - `db:migrate`
27
- - `db:seed`
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
25
+ - `{{runScriptCommand packageManager "db:down"}}` - stop the local MongoDB replica set
26
+ - `{{runScriptCommand packageManager "migration:plan"}}` - create a MongoDB migration plan
27
+ - `{{runScriptCommand packageManager "migration:apply"}}` - 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 "migration:apply"}}` - apply a planned migration
33
+ {{/if}}
34
+ {{#if (eq schemaPreset "basic")}}
35
+ - `{{runScriptCommand packageManager "db:seed"}}` - insert sample users manually
36
+ {{/if}}
37
+
38
+ Node-based Prisma Next projects expect Node.js 24 LTS or newer.
28
39
  {{#if (eq schemaPreset "basic")}}
29
40
 
30
- The starter page loads users in `+page.server.ts`, renders them in `+page.svelte`, and `prisma/seed.ts` inserts starter users.
41
+ The starter page loads users in `+page.server.ts` and renders them in `+page.svelte` after you initialize and apply your schema.
31
42
  {{else}}
32
43
 
33
- The starter page keeps the official SvelteKit minimal structure and points you to `prisma/schema.prisma` for your first model.
44
+ The starter page keeps the official SvelteKit minimal structure and points you to your Prisma Next contract for the first model.
34
45
  {{/if}}
@@ -1,5 +1,5 @@
1
1
  {{#if (eq packageManager "deno")}}
2
2
  {
3
- "nodeModulesDir": "auto"
3
+ "nodeModulesDir": "manual"
4
4
  }
5
5
  {{/if}}
@@ -0,0 +1,44 @@
1
+ {{#if (eq authoring "psl")}}
2
+ // use prisma-next
3
+ {{#if (eq schemaPreset "basic")}}
4
+ {{#if (eq provider "mongo")}}
5
+
6
+ model User {
7
+ id ObjectId @id @map("_id")
8
+ email String @unique
9
+ name String?
10
+ posts Post[]
11
+
12
+ @@map("users")
13
+ }
14
+
15
+ model Post {
16
+ id ObjectId @id @map("_id")
17
+ title String
18
+ content String?
19
+ author User @relation(fields: [authorId], references: [id])
20
+ authorId ObjectId
21
+
22
+ @@map("posts")
23
+ }
24
+ {{else}}
25
+
26
+ model User {
27
+ id Int @id @default(autoincrement())
28
+ email String @unique
29
+ name String?
30
+ posts Post[]
31
+ createdAt DateTime @default(now())
32
+ }
33
+
34
+ model Post {
35
+ id Int @id @default(autoincrement())
36
+ title String
37
+ content String?
38
+ author User @relation(fields: [authorId], references: [id])
39
+ authorId Int
40
+ createdAt DateTime @default(now())
41
+ }
42
+ {{/if}}
43
+ {{/if}}
44
+ {{/if}}
@@ -0,0 +1,85 @@
1
+ {{#if (eq authoring "typescript")}}
2
+ {{#if (eq provider "mongo")}}
3
+ import mongoFamily from "@prisma-next/family-mongo/pack";
4
+ import { defineContract } from "@prisma-next/mongo-contract-ts/contract-builder";
5
+ import mongoTarget from "@prisma-next/target-mongo/pack";
6
+
7
+ export const contract = defineContract(
8
+ { family: mongoFamily, target: mongoTarget },
9
+ ({ field, index, model, rel }) => ({
10
+ models: {
11
+ {{#if (eq schemaPreset "basic")}}
12
+ User: model("User", {
13
+ collection: "users",
14
+ fields: {
15
+ _id: field.objectId(),
16
+ email: field.string(),
17
+ name: field.string().optional(),
18
+ },
19
+ indexes: [
20
+ index({ email: 1 }, { unique: true }),
21
+ ],
22
+ relations: {
23
+ posts: rel.hasMany("Post", { from: "_id", to: "authorId" }),
24
+ },
25
+ }),
26
+
27
+ Post: model("Post", {
28
+ collection: "posts",
29
+ fields: {
30
+ _id: field.objectId(),
31
+ title: field.string(),
32
+ content: field.string().optional(),
33
+ authorId: field.objectId(),
34
+ },
35
+ indexes: [
36
+ index({ authorId: 1 }),
37
+ ],
38
+ relations: {
39
+ author: rel.belongsTo("User", { from: "authorId", to: "_id" }),
40
+ },
41
+ }),
42
+ {{/if}}
43
+ },
44
+ }),
45
+ );
46
+ {{else}}
47
+ import sqlFamily from "@prisma-next/family-sql/pack";
48
+ import { defineContract } from "@prisma-next/sql-contract-ts/contract-builder";
49
+ import postgresPack from "@prisma-next/target-postgres/pack";
50
+
51
+ export const contract = defineContract(
52
+ { family: sqlFamily, target: postgresPack },
53
+ ({ field, model, rel }) => ({
54
+ models: {
55
+ {{#if (eq schemaPreset "basic")}}
56
+ User: model("User", {
57
+ fields: {
58
+ id: field.id.uuidv7(),
59
+ email: field.text().unique(),
60
+ name: field.text().optional(),
61
+ createdAt: field.createdAt(),
62
+ },
63
+ relations: {
64
+ posts: rel.hasMany("Post", { by: "authorId" }),
65
+ },
66
+ }),
67
+
68
+ Post: model("Post", {
69
+ fields: {
70
+ id: field.id.uuidv7(),
71
+ title: field.text(),
72
+ content: field.text().optional(),
73
+ authorId: field.uuid(),
74
+ createdAt: field.createdAt(),
75
+ },
76
+ relations: {
77
+ author: rel.belongsTo("User", { from: "authorId", to: "id" }),
78
+ },
79
+ }),
80
+ {{/if}}
81
+ },
82
+ }),
83
+ );
84
+ {{/if}}
85
+ {{/if}}
@@ -0,0 +1,13 @@
1
+ import "dotenv/config";
2
+ {{#if (eq provider "mongo")}}
3
+ import { defineConfig } from "@prisma-next/mongo/config";
4
+ {{else}}
5
+ import { defineConfig } from "@prisma-next/postgres/config";
6
+ {{/if}}
7
+
8
+ export default defineConfig({
9
+ contract: "./prisma/contract{{#if (eq authoring "typescript")}}.ts{{else}}.prisma{{/if}}",
10
+ db: {
11
+ connection: process.env["DATABASE_URL"],
12
+ },
13
+ });
@@ -1,53 +1,59 @@
1
- import { env } from "$env/dynamic/private";
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";
17
- {{/if}}
18
-
19
- {{#if (eq provider "sqlite")}}
20
- const databaseUrl = env.DATABASE_URL ?? "file:./dev.db";
1
+ import "dotenv/config";
2
+ {{#if (eq provider "mongo")}}
3
+ import mongo from "@prisma-next/mongo/runtime";
21
4
  {{else}}
22
- const databaseUrl = env.DATABASE_URL;
23
- if (!databaseUrl) {
24
- throw new Error("DATABASE_URL is required");
25
- }
5
+ import postgres from "@prisma-next/postgres/runtime";
26
6
  {{/if}}
7
+ import type { Contract } from "../../../prisma/contract.d";
8
+ import contractJson from "../../../prisma/contract.json" with { type: "json" };
27
9
 
28
- {{#if (eq provider "postgresql")}}
29
- const adapter = new PrismaPg({
30
- connectionString: databaseUrl,
10
+ {{#if (eq provider "mongo")}}
11
+ export const db = mongo<Contract>({
12
+ contractJson,
13
+ url: process.env["DATABASE_URL"],
31
14
  });
32
- {{/if}}
33
- {{#if (eq provider "cockroachdb")}}
34
- const adapter = new PrismaPg({
35
- connectionString: databaseUrl,
15
+ {{else}}
16
+ export const db = postgres<Contract>({
17
+ contractJson,
18
+ url: process.env["DATABASE_URL"],
36
19
  });
37
20
  {{/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
- });
21
+
22
+ export type StarterUser = {
23
+ id: string;
24
+ email: string;
25
+ name: string | null;
26
+ createdAt: Date | null;
27
+ };
28
+
29
+ export async function listUsers(limit = 10): Promise<StarterUser[]> {
30
+ {{#if (eq schemaPreset "basic")}}
31
+ {{#if (eq provider "mongo")}}
32
+ const users: StarterUser[] = [];
33
+
34
+ for await (const user of db.orm.users.select("_id", "email", "name").take(limit).all()) {
35
+ users.push({
36
+ id: String(user._id),
37
+ email: user.email,
38
+ name: user.name ?? null,
39
+ createdAt: null,
40
+ });
41
+ }
42
+
43
+ return users;
44
+ {{else}}
45
+ const users = await db.orm.User.select("id", "email", "name", "createdAt").take(limit).all();
46
+
47
+ return users.map((user) => ({
48
+ id: String(user.id),
49
+ email: user.email,
50
+ name: user.name ?? null,
51
+ createdAt: user.createdAt,
52
+ }));
45
53
  {{/if}}
46
- {{#if (eq provider "sqlserver")}}
47
- const adapter = new PrismaMssql(databaseUrl);
54
+ {{else}}
55
+ return [];
48
56
  {{/if}}
57
+ }
49
58
 
50
- const prisma = new PrismaClient({ adapter });
51
-
52
- export { prisma };
53
- export default prisma;
59
+ export default db;
@@ -1,19 +1,13 @@
1
1
  import type { PageServerLoad } from "./$types";
2
2
  {{#if (eq schemaPreset "basic")}}
3
- import prisma from "$lib/server/prisma";
3
+ import { listUsers } from "$lib/server/prisma";
4
4
 
5
5
  export const load: PageServerLoad = async () => {
6
- const users = await prisma.user
7
- .findMany({
8
- take: 10,
9
- orderBy: {
10
- createdAt: "desc",
11
- },
12
- })
6
+ const users = await listUsers(10)
13
7
  .then((rows) =>
14
8
  rows.map((user) => ({
15
9
  ...user,
16
- createdAt: user.createdAt.toISOString(),
10
+ createdAt: user.createdAt?.toISOString() ?? null,
17
11
  }))
18
12
  )
19
13
  .catch(() => undefined);
@@ -18,10 +18,10 @@
18
18
 
19
19
  <section class="shell">
20
20
  <div class="hero">
21
- <p class="eyebrow">SvelteKit + Prisma 7</p>
21
+ <p class="eyebrow">SvelteKit + Prisma Next</p>
22
22
  <h1>Users from your database, loaded on the server.</h1>
23
23
  <p class="lede">
24
- This page reads from <code>+page.server.ts</code> using the Prisma instance in
24
+ This page reads from <code>+page.server.ts</code> using the Prisma Next helper in
25
25
  <code>src/lib/server/prisma.ts</code>.
26
26
  </p>
27
27
  </div>
@@ -34,11 +34,11 @@
34
34
 
35
35
  {#if !data.users}
36
36
  <p class="empty">
37
- Could not query users yet. Run <code>db:migrate</code>, then <code>db:seed</code>, then
37
+ Could not query users yet. Run <code>contract:emit</code> and apply your schema, then
38
38
  refresh.
39
39
  </p>
40
40
  {:else if data.users.length === 0}
41
- <p class="empty">No users yet. Run <code>db:seed</code> after your first migration.</p>
41
+ <p class="empty">No users yet. Run db:seed after applying your first migration.</p>
42
42
  {:else}
43
43
  <ul class="users">
44
44
  {#each data.users as user}
@@ -47,9 +47,13 @@
47
47
  <strong>{user.name ?? 'Unnamed user'}</strong>
48
48
  <p>{user.email}</p>
49
49
  </div>
50
- <time datetime={new Date(user.createdAt).toISOString()}>
51
- {formatter.format(new Date(user.createdAt))}
52
- </time>
50
+ {#if user.createdAt}
51
+ <time datetime={new Date(user.createdAt).toISOString()}>
52
+ {formatter.format(new Date(user.createdAt))}
53
+ </time>
54
+ {:else}
55
+ <span class="muted">No timestamp</span>
56
+ {/if}
53
57
  </li>
54
58
  {/each}
55
59
  </ul>
@@ -120,6 +124,7 @@
120
124
 
121
125
  .panel-header span,
122
126
  .empty,
127
+ .muted,
123
128
  time {
124
129
  color: #888;
125
130
  font-size: 0.8rem;
@@ -180,11 +185,11 @@
180
185
 
181
186
  <section class="shell">
182
187
  <div class="hero">
183
- <p class="eyebrow">SvelteKit + Prisma 7</p>
188
+ <p class="eyebrow">SvelteKit + Prisma Next</p>
184
189
  <h1>Your SvelteKit app is ready.</h1>
185
190
  <p class="lede">
186
- Edit <code>prisma/schema.prisma</code>, run <code>db:migrate</code>, then load your data from
187
- <code>+page.server.ts</code> with the Prisma instance in <code>src/lib/server/prisma.ts</code>.
191
+ Edit your Prisma Next contract, run <code>contract:emit</code>, then load your data from
192
+ <code>+page.server.ts</code> with the helper in <code>src/lib/server/prisma.ts</code>.
188
193
  </p>
189
194
  </div>
190
195
 
@@ -197,20 +202,20 @@
197
202
  <ul class="users">
198
203
  <li>
199
204
  <div>
200
- <strong>Prisma client</strong>
201
- <p>Use the server-only instance from <code>src/lib/server/prisma.ts</code>.</p>
205
+ <strong>Prisma Next runtime</strong>
206
+ <p>Use the server-only helper from <code>src/lib/server/prisma.ts</code>.</p>
202
207
  </div>
203
208
  </li>
204
209
  <li>
205
210
  <div>
206
- <strong>Seed script</strong>
207
- <p>Run <code>db:seed</code> after your first migration.</p>
211
+ <strong>Manual database setup</strong>
212
+ <p>Run the schema setup commands when you are ready.</p>
208
213
  </div>
209
214
  </li>
210
215
  <li>
211
216
  <div>
212
- <strong>Generated client output</strong>
213
- <p>Prisma Client is generated into <code>src/generated/prisma</code>.</p>
217
+ <strong>Contract output</strong>
218
+ <p>Prisma Next emits contract artifacts next to your contract file.</p>
214
219
  </div>
215
220
  </li>
216
221
  </ul>
@@ -9,23 +9,34 @@ Generated by `create-prisma` with the TanStack Start template.
9
9
  - `{{runScriptCommand packageManager "preview"}}` - preview the production build
10
10
  - `{{runScriptCommand packageManager "typecheck"}}` - run TypeScript 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
  - `src/lib/prisma.server.ts`
19
- - `prisma.config.ts`
20
- - `src/generated/prisma`
21
19
 
22
20
  Database helper scripts are added to `package.json`:
23
21
 
24
- - `db:generate`
25
- - `db:push`
26
- - `db:migrate`
27
- - `db:seed`
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
25
+ - `{{runScriptCommand packageManager "db:down"}}` - stop the local MongoDB replica set
26
+ - `{{runScriptCommand packageManager "migration:plan"}}` - create a MongoDB migration plan
27
+ - `{{runScriptCommand packageManager "migration:apply"}}` - 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 "migration:apply"}}` - apply a planned migration
33
+ {{/if}}
34
+ {{#if (eq schemaPreset "basic")}}
35
+ - `{{runScriptCommand packageManager "db:seed"}}` - insert sample users manually
36
+ {{/if}}
37
+
38
+ Node-based Prisma Next projects expect Node.js 24 LTS or newer.
28
39
  {{#if (eq schemaPreset "basic")}}
29
40
 
30
- The home route uses a TanStack Start server function to load users with the Prisma client from `src/lib/prisma.server.ts`, so you can verify a real database query without adding an API route first.
41
+ The home route uses a TanStack Start server function to load users through the Prisma Next helper in `src/lib/prisma.server.ts`.
31
42
  {{/if}}
@@ -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",
@@ -10,4 +10,3 @@
10
10
  ]
11
11
  }
12
12
  {{/if}}
13
-
@@ -0,0 +1,44 @@
1
+ {{#if (eq authoring "psl")}}
2
+ // use prisma-next
3
+ {{#if (eq schemaPreset "basic")}}
4
+ {{#if (eq provider "mongo")}}
5
+
6
+ model User {
7
+ id ObjectId @id @map("_id")
8
+ email String @unique
9
+ name String?
10
+ posts Post[]
11
+
12
+ @@map("users")
13
+ }
14
+
15
+ model Post {
16
+ id ObjectId @id @map("_id")
17
+ title String
18
+ content String?
19
+ author User @relation(fields: [authorId], references: [id])
20
+ authorId ObjectId
21
+
22
+ @@map("posts")
23
+ }
24
+ {{else}}
25
+
26
+ model User {
27
+ id Int @id @default(autoincrement())
28
+ email String @unique
29
+ name String?
30
+ posts Post[]
31
+ createdAt DateTime @default(now())
32
+ }
33
+
34
+ model Post {
35
+ id Int @id @default(autoincrement())
36
+ title String
37
+ content String?
38
+ author User @relation(fields: [authorId], references: [id])
39
+ authorId Int
40
+ createdAt DateTime @default(now())
41
+ }
42
+ {{/if}}
43
+ {{/if}}
44
+ {{/if}}