create-prisma 0.4.1 → 0.4.2-next.37.79.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-Btn7yJR3.mjs} +513 -913
  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
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";
@@ -195,6 +194,10 @@ declare const SchemaPresetSchema: z.ZodEnum<{
195
194
  empty: "empty";
196
195
  basic: "basic";
197
196
  }>;
197
+ declare const AuthoringStyleSchema: z.ZodEnum<{
198
+ psl: "psl";
199
+ typescript: "typescript";
200
+ }>;
198
201
  declare const CreateTemplateSchema: z.ZodEnum<{
199
202
  hono: "hono";
200
203
  elysia: "elysia";
@@ -210,12 +213,15 @@ declare const DatabaseUrlSchema: z.ZodString;
210
213
  declare const CreateCommandInputSchema: z.ZodObject<{
211
214
  yes: z.ZodOptional<z.ZodBoolean>;
212
215
  verbose: z.ZodOptional<z.ZodBoolean>;
213
- provider: z.ZodOptional<z.ZodEnum<{
216
+ provider: z.ZodOptional<z.ZodPipe<z.ZodEnum<{
217
+ postgres: "postgres";
214
218
  postgresql: "postgresql";
215
- mysql: "mysql";
216
- sqlite: "sqlite";
217
- sqlserver: "sqlserver";
218
- cockroachdb: "cockroachdb";
219
+ mongo: "mongo";
220
+ mongodb: "mongodb";
221
+ }>, z.ZodTransform<"postgres" | "mongo", "postgres" | "postgresql" | "mongo" | "mongodb">>>;
222
+ authoring: z.ZodOptional<z.ZodEnum<{
223
+ psl: "psl";
224
+ typescript: "typescript";
219
225
  }>>;
220
226
  packageManager: z.ZodOptional<z.ZodEnum<{
221
227
  npm: "npm";
@@ -227,7 +233,7 @@ declare const CreateCommandInputSchema: z.ZodObject<{
227
233
  prismaPostgres: z.ZodOptional<z.ZodBoolean>;
228
234
  databaseUrl: z.ZodOptional<z.ZodString>;
229
235
  install: z.ZodOptional<z.ZodBoolean>;
230
- generate: z.ZodOptional<z.ZodBoolean>;
236
+ emit: z.ZodOptional<z.ZodBoolean>;
231
237
  schemaPreset: z.ZodOptional<z.ZodEnum<{
232
238
  empty: "empty";
233
239
  basic: "basic";
@@ -244,9 +250,6 @@ declare const CreateCommandInputSchema: z.ZodObject<{
244
250
  "tanstack-start": "tanstack-start";
245
251
  turborepo: "turborepo";
246
252
  }>>;
247
- skills: z.ZodOptional<z.ZodBoolean>;
248
- mcp: z.ZodOptional<z.ZodBoolean>;
249
- extension: z.ZodOptional<z.ZodBoolean>;
250
253
  force: z.ZodOptional<z.ZodBoolean>;
251
254
  }, z.core.$strip>;
252
255
  type CreateCommandInput = z.infer<typeof CreateCommandInputSchema>;
@@ -256,12 +259,15 @@ declare const router: {
256
259
  create: _orpc_server0.Procedure<_orpc_server0.MergedInitialContext<Record<never, never>, Record<never, never>, Record<never, never>>, Record<never, never>, zod.ZodOptional<zod.ZodObject<{
257
260
  yes: zod.ZodOptional<zod.ZodBoolean>;
258
261
  verbose: zod.ZodOptional<zod.ZodBoolean>;
259
- provider: zod.ZodOptional<zod.ZodEnum<{
262
+ provider: zod.ZodOptional<zod.ZodPipe<zod.ZodEnum<{
263
+ postgres: "postgres";
260
264
  postgresql: "postgresql";
261
- mysql: "mysql";
262
- sqlite: "sqlite";
263
- sqlserver: "sqlserver";
264
- cockroachdb: "cockroachdb";
265
+ mongo: "mongo";
266
+ mongodb: "mongodb";
267
+ }>, zod.ZodTransform<"postgres" | "mongo", "postgres" | "postgresql" | "mongo" | "mongodb">>>;
268
+ authoring: zod.ZodOptional<zod.ZodEnum<{
269
+ psl: "psl";
270
+ typescript: "typescript";
265
271
  }>>;
266
272
  packageManager: zod.ZodOptional<zod.ZodEnum<{
267
273
  npm: "npm";
@@ -273,7 +279,7 @@ declare const router: {
273
279
  prismaPostgres: zod.ZodOptional<zod.ZodBoolean>;
274
280
  databaseUrl: zod.ZodOptional<zod.ZodString>;
275
281
  install: zod.ZodOptional<zod.ZodBoolean>;
276
- generate: zod.ZodOptional<zod.ZodBoolean>;
282
+ emit: zod.ZodOptional<zod.ZodBoolean>;
277
283
  schemaPreset: zod.ZodOptional<zod.ZodEnum<{
278
284
  empty: "empty";
279
285
  basic: "basic";
@@ -290,13 +296,10 @@ declare const router: {
290
296
  "tanstack-start": "tanstack-start";
291
297
  turborepo: "turborepo";
292
298
  }>>;
293
- skills: zod.ZodOptional<zod.ZodBoolean>;
294
- mcp: zod.ZodOptional<zod.ZodBoolean>;
295
- extension: zod.ZodOptional<zod.ZodBoolean>;
296
299
  force: zod.ZodOptional<zod.ZodBoolean>;
297
300
  }, zod_v4_core0.$strip>>, Schema<void, void>, MergedErrorMap<Record<never, never>, Record<never, never>>, Record<never, never>>;
298
301
  };
299
302
  declare function createCreatePrismaCli(): trpc_cli0.TrpcCli;
300
303
  declare function create(input?: CreateCommandInput): Promise<void>;
301
304
  //#endregion
302
- export { type CreateCommandInput, CreateCommandInputSchema, CreateTemplateSchema, DatabaseProviderSchema, DatabaseUrlSchema, PackageManagerSchema, SchemaPresetSchema, create, createCreatePrismaCli, router };
305
+ export { AuthoringStyleSchema, type CreateCommandInput, CreateCommandInputSchema, CreateTemplateSchema, DatabaseProviderSchema, DatabaseUrlSchema, PackageManagerSchema, SchemaPresetSchema, 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, c as SchemaPresetSchema, i as CreateTemplateSchema, n as AuthoringStyleSchema, o as DatabaseUrlSchema, r as CreateCommandInputSchema, s as PackageManagerSchema, t as runCreateCommand } from "./create-Btn7yJR3.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.79.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, SchemaPresetSchema, 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.79.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"
@@ -0,0 +1,43 @@
1
+ {{#if (eq template "turborepo")}}
2
+ {{#if (eq schemaPreset "basic")}}
3
+ import { db } from "../src/client{{#if (eq packageManager "deno")}}.ts{{/if}}";
4
+
5
+ const seedUsers = [
6
+ { email: "alice@prisma.io", name: "Alice" },
7
+ { email: "bob@prisma.io", name: "Bob" },
8
+ { email: "carol@prisma.io", name: "Carol" },
9
+ ];
10
+
11
+ let createdCount = 0;
12
+
13
+ {{#if (eq provider "mongo")}}
14
+ try {
15
+ for (const user of seedUsers) {
16
+ const existingUser = await db.orm.users.where({ email: user.email }).first();
17
+ if (!existingUser) {
18
+ createdCount += await db.orm.users.createCount([user]);
19
+ }
20
+ }
21
+
22
+ console.log(`Seeded ${createdCount} user${createdCount === 1 ? "" : "s"}.`);
23
+ } finally {
24
+ await db.close();
25
+ }
26
+ {{else}}
27
+ try {
28
+ for (const user of seedUsers) {
29
+ const existingUser = await db.orm.User.where({ email: user.email }).first();
30
+ if (!existingUser) {
31
+ createdCount += await db.orm.User.createCount([user]);
32
+ }
33
+ }
34
+
35
+ console.log(`Seeded ${createdCount} user${createdCount === 1 ? "" : "s"}.`);
36
+ } finally {
37
+ await db.runtime().close();
38
+ }
39
+ {{/if}}
40
+ {{else}}
41
+ console.log("No seed data for the empty schema preset.");
42
+ {{/if}}
43
+ {{/if}}
@@ -0,0 +1,55 @@
1
+ {{#unless (eq template "turborepo")}}
2
+ {{#if (eq schemaPreset "basic")}}
3
+ {{#if (eq template "nuxt")}}
4
+ import { db } from "../server/utils/prisma{{#if (eq packageManager "deno")}}.ts{{/if}}";
5
+ {{else}}
6
+ {{#if (eq template "svelte")}}
7
+ import { db } from "../src/lib/server/prisma{{#if (eq packageManager "deno")}}.ts{{/if}}";
8
+ {{else}}
9
+ {{#if (eq template "tanstack-start")}}
10
+ import { db } from "../src/lib/prisma.server{{#if (eq packageManager "deno")}}.ts{{/if}}";
11
+ {{else}}
12
+ import { db } from "../src/lib/prisma{{#if (eq packageManager "deno")}}.ts{{/if}}";
13
+ {{/if}}
14
+ {{/if}}
15
+ {{/if}}
16
+
17
+ const seedUsers = [
18
+ { email: "alice@prisma.io", name: "Alice" },
19
+ { email: "bob@prisma.io", name: "Bob" },
20
+ { email: "carol@prisma.io", name: "Carol" },
21
+ ];
22
+
23
+ let createdCount = 0;
24
+
25
+ {{#if (eq provider "mongo")}}
26
+ try {
27
+ for (const user of seedUsers) {
28
+ const existingUser = await db.orm.users.where({ email: user.email }).first();
29
+ if (!existingUser) {
30
+ createdCount += await db.orm.users.createCount([user]);
31
+ }
32
+ }
33
+
34
+ console.log(`Seeded ${createdCount} user${createdCount === 1 ? "" : "s"}.`);
35
+ } finally {
36
+ await db.close();
37
+ }
38
+ {{else}}
39
+ try {
40
+ for (const user of seedUsers) {
41
+ const existingUser = await db.orm.User.where({ email: user.email }).first();
42
+ if (!existingUser) {
43
+ createdCount += await db.orm.User.createCount([user]);
44
+ }
45
+ }
46
+
47
+ console.log(`Seeded ${createdCount} user${createdCount === 1 ? "" : "s"}.`);
48
+ } finally {
49
+ await db.runtime().close();
50
+ }
51
+ {{/if}}
52
+ {{else}}
53
+ console.log("No seed data for the empty schema preset.");
54
+ {{/if}}
55
+ {{/unless}}
@@ -9,27 +9,38 @@ 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`
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
26
+ - `{{runScriptCommand packageManager "db:down"}}` - stop the local MongoDB replica set
27
+ - `{{runScriptCommand packageManager "migration:plan"}}` - create a MongoDB migration plan
28
+ - `{{runScriptCommand packageManager "migration:apply"}}` - 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 "migration:apply"}}` - apply a planned migration
34
+ {{/if}}
35
+ {{#if (eq schemaPreset "basic")}}
36
+ - `{{runScriptCommand packageManager "db:seed"}}` - insert sample users manually
37
+ {{/if}}
38
+
39
+ Node-based Prisma Next projects expect Node.js 24 LTS or newer.
29
40
  {{#if (eq schemaPreset "basic")}}
30
41
 
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.
42
+ 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.
32
43
  {{else}}
33
44
 
34
- The starter page keeps the official Astro minimal structure and points you to `prisma/schema.prisma` for your first model.
45
+ The starter page keeps the official Astro minimal structure and points you to your Prisma Next contract for the first model.
35
46
  {{/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
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 =
21
- import.meta.env?.DATABASE_URL ?? process.env.DATABASE_URL ?? "file:./dev.db";
2
+ {{#if (eq provider "mongo")}}
3
+ import mongo from "@prisma-next/mongo/runtime";
22
4
  {{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
- }
5
+ import postgres from "@prisma-next/postgres/runtime";
27
6
  {{/if}}
7
+ import type { Contract } from "../../prisma/contract.d";
8
+ import contractJson from "../../prisma/contract.json" with { type: "json" };
28
9
 
29
- {{#if (eq provider "postgresql")}}
30
- const adapter = new PrismaPg({
31
- connectionString: databaseUrl,
10
+ {{#if (eq provider "mongo")}}
11
+ export const db = mongo<Contract>({
12
+ contractJson,
13
+ url: process.env["DATABASE_URL"],
32
14
  });
33
- {{/if}}
34
- {{#if (eq provider "cockroachdb")}}
35
- const adapter = new PrismaPg({
36
- connectionString: databaseUrl,
15
+ {{else}}
16
+ export const db = postgres<Contract>({
17
+ contractJson,
18
+ url: process.env["DATABASE_URL"],
37
19
  });
38
20
  {{/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
- });
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
+ }));
46
53
  {{/if}}
47
- {{#if (eq provider "sqlserver")}}
48
- const adapter = new PrismaMssql(databaseUrl);
54
+ {{else}}
55
+ return [];
49
56
  {{/if}}
57
+ }
50
58
 
51
- const prisma = new PrismaClient({ adapter });
52
-
53
- export default prisma;
59
+ export default db;
@@ -1,19 +1,12 @@
1
1
  import type { APIRoute } from "astro";
2
2
  {{#if (eq schemaPreset "basic")}}
3
- import prisma from "../../lib/prisma";
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." }), {