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.
- package/README.md +43 -35
- package/dist/cli.mjs +1 -1
- package/dist/{create-H6Tk0JlE.mjs → create-Btn7yJR3.mjs} +513 -913
- package/dist/index.d.mts +28 -25
- package/dist/index.mjs +3 -3
- package/package.json +2 -2
- package/templates/create/_shared/packages/db/prisma/seed.ts.hbs +43 -0
- package/templates/create/_shared/prisma/seed.ts.hbs +55 -0
- package/templates/create/astro/README.md.hbs +23 -12
- package/templates/create/astro/deno.json.hbs +1 -1
- package/templates/create/astro/prisma/contract.prisma.hbs +44 -0
- package/templates/create/astro/prisma/contract.ts.hbs +85 -0
- package/templates/create/astro/prisma-next.config.ts.hbs +13 -0
- package/templates/create/astro/src/lib/prisma.ts.hbs +49 -43
- package/templates/create/astro/src/pages/api/users.ts.hbs +5 -12
- package/templates/create/astro/src/pages/index.astro.hbs +19 -21
- package/templates/create/elysia/.yarnrc.yml.hbs +3 -0
- package/templates/create/elysia/README.md.hbs +27 -18
- package/templates/create/elysia/deno.json.hbs +1 -1
- package/templates/create/elysia/prisma/contract.prisma.hbs +44 -0
- package/templates/create/elysia/prisma/contract.ts.hbs +85 -0
- package/templates/create/elysia/prisma-next.config.ts.hbs +13 -0
- package/templates/create/elysia/src/index.ts.hbs +12 -7
- package/templates/create/elysia/src/lib/prisma.ts.hbs +49 -46
- package/templates/create/elysia/tsconfig.json +1 -0
- package/templates/create/hono/README.md.hbs +27 -18
- package/templates/create/hono/deno.json.hbs +1 -1
- package/templates/create/hono/prisma/contract.prisma.hbs +44 -0
- package/templates/create/hono/prisma/contract.ts.hbs +85 -0
- package/templates/create/hono/prisma-next.config.ts.hbs +13 -0
- package/templates/create/hono/src/index.ts.hbs +8 -6
- package/templates/create/hono/src/lib/prisma.ts.hbs +49 -46
- package/templates/create/hono/tsconfig.json +1 -0
- package/templates/create/nest/README.md.hbs +28 -18
- package/templates/create/nest/deno.json.hbs +1 -1
- package/templates/create/nest/prisma/contract.prisma.hbs +44 -0
- package/templates/create/nest/prisma/contract.ts.hbs +85 -0
- package/templates/create/nest/prisma-next.config.ts.hbs +13 -0
- package/templates/create/nest/src/lib/prisma.ts.hbs +49 -48
- package/templates/create/nest/src/prisma.service.ts.hbs +6 -5
- package/templates/create/nest/src/users.service.ts.hbs +1 -6
- package/templates/create/nest/tsconfig.json +1 -0
- package/templates/create/next/README.md.hbs +22 -11
- package/templates/create/next/deno.json.hbs +1 -1
- package/templates/create/next/prisma/contract.prisma.hbs +44 -0
- package/templates/create/next/prisma/contract.ts.hbs +85 -0
- package/templates/create/next/prisma-next.config.ts.hbs +13 -0
- package/templates/create/next/src/app/page.tsx.hbs +21 -26
- package/templates/create/next/src/lib/prisma.ts.hbs +49 -43
- package/templates/create/next/tsconfig.json +1 -0
- package/templates/create/nuxt/README.md.hbs +22 -11
- package/templates/create/nuxt/app/pages/index.vue.hbs +14 -12
- package/templates/create/nuxt/deno.json.hbs +1 -1
- package/templates/create/nuxt/nuxt.config.ts +16 -0
- package/templates/create/nuxt/prisma/contract.prisma.hbs +44 -0
- package/templates/create/nuxt/prisma/contract.ts.hbs +85 -0
- package/templates/create/nuxt/prisma-next.config.ts.hbs +13 -0
- package/templates/create/nuxt/server/api/users.get.ts.hbs +3 -9
- package/templates/create/nuxt/server/utils/prisma.ts.hbs +49 -43
- package/templates/create/svelte/README.md.hbs +23 -12
- package/templates/create/svelte/deno.json.hbs +1 -1
- package/templates/create/svelte/prisma/contract.prisma.hbs +44 -0
- package/templates/create/svelte/prisma/contract.ts.hbs +85 -0
- package/templates/create/svelte/prisma-next.config.ts.hbs +13 -0
- package/templates/create/svelte/src/lib/server/prisma.ts.hbs +50 -44
- package/templates/create/svelte/src/routes/+page.server.ts.hbs +3 -9
- package/templates/create/svelte/src/routes/+page.svelte.hbs +21 -16
- package/templates/create/tanstack-start/README.md.hbs +22 -11
- package/templates/create/tanstack-start/deno.json.hbs +1 -2
- package/templates/create/tanstack-start/prisma/contract.prisma.hbs +44 -0
- package/templates/create/tanstack-start/prisma/contract.ts.hbs +85 -0
- package/templates/create/tanstack-start/prisma-next.config.ts.hbs +13 -0
- package/templates/create/tanstack-start/src/lib/prisma.server.ts.hbs +49 -43
- package/templates/create/tanstack-start/src/routes/__root.tsx.hbs +2 -3
- package/templates/create/tanstack-start/src/routes/index.tsx.hbs +27 -38
- package/templates/create/tanstack-start/tsconfig.json +1 -0
- package/templates/create/turborepo/README.md.hbs +25 -14
- package/templates/create/turborepo/apps/api/deno.json.hbs +6 -0
- package/templates/create/turborepo/apps/api/package.json.hbs +7 -0
- package/templates/create/turborepo/apps/api/src/index.ts.hbs +6 -13
- package/templates/create/turborepo/deno.json.hbs +5 -1
- package/templates/create/turborepo/package.json.hbs +12 -4
- package/templates/create/turborepo/packages/db/deno.json.hbs +6 -0
- package/templates/create/turborepo/packages/db/package.json.hbs +5 -0
- package/templates/create/turborepo/packages/db/prisma/contract.prisma.hbs +44 -0
- package/templates/create/turborepo/packages/db/prisma/contract.ts.hbs +85 -0
- package/templates/create/turborepo/packages/db/prisma-next.config.ts.hbs +13 -0
- package/templates/create/turborepo/packages/db/src/client.ts.hbs +56 -44
- package/templates/create/turborepo/packages/db/src/index.ts +1 -1
- package/templates/create/turborepo/packages/db/tsconfig.json +2 -1
- package/templates/create/turborepo/pnpm-workspace.yaml.hbs +5 -0
- package/templates/create/turborepo/turbo.json +9 -3
- package/templates/create/astro/prisma/schema.prisma.hbs +0 -21
- package/templates/create/astro/prisma/seed.ts.hbs +0 -38
- package/templates/create/astro/prisma.config.ts +0 -13
- package/templates/create/elysia/prisma/schema.prisma.hbs +0 -25
- package/templates/create/elysia/prisma/seed.ts.hbs +0 -42
- package/templates/create/elysia/prisma.config.ts.hbs +0 -15
- package/templates/create/hono/prisma/schema.prisma.hbs +0 -25
- package/templates/create/hono/prisma/seed.ts.hbs +0 -42
- package/templates/create/hono/prisma.config.ts.hbs +0 -15
- package/templates/create/nest/prisma/schema.prisma.hbs +0 -25
- package/templates/create/nest/prisma/seed.ts.hbs +0 -44
- package/templates/create/nest/prisma.config.ts.hbs +0 -15
- package/templates/create/next/prisma/schema.prisma.hbs +0 -21
- package/templates/create/next/prisma/seed.ts.hbs +0 -38
- package/templates/create/next/prisma.config.ts +0 -13
- package/templates/create/nuxt/prisma/schema.prisma.hbs +0 -21
- package/templates/create/nuxt/prisma/seed.ts.hbs +0 -38
- package/templates/create/nuxt/prisma.config.ts +0 -13
- package/templates/create/svelte/prisma/schema.prisma.hbs +0 -21
- package/templates/create/svelte/prisma/seed.ts.hbs +0 -87
- package/templates/create/svelte/prisma.config.ts +0 -13
- package/templates/create/tanstack-start/prisma/schema.prisma.hbs +0 -21
- package/templates/create/tanstack-start/prisma/seed.ts.hbs +0 -37
- package/templates/create/tanstack-start/prisma.config.ts +0 -13
- package/templates/create/turborepo/packages/db/prisma/schema.prisma.hbs +0 -21
- package/templates/create/turborepo/packages/db/prisma/seed.ts.hbs +0 -38
- 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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
14
|
+
Prisma Next setup is scaffolded in:
|
|
15
15
|
|
|
16
|
-
- `prisma/
|
|
17
|
-
- `prisma
|
|
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
|
-
- `
|
|
26
|
-
|
|
27
|
-
- `db:
|
|
28
|
-
- `db:
|
|
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
|
|
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
|
|
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}}
|
|
@@ -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
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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 "
|
|
30
|
-
const
|
|
31
|
-
|
|
10
|
+
{{#if (eq provider "mongo")}}
|
|
11
|
+
export const db = mongo<Contract>({
|
|
12
|
+
contractJson,
|
|
13
|
+
url: process.env["DATABASE_URL"],
|
|
32
14
|
});
|
|
33
|
-
{{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
15
|
+
{{else}}
|
|
16
|
+
export const db = postgres<Contract>({
|
|
17
|
+
contractJson,
|
|
18
|
+
url: process.env["DATABASE_URL"],
|
|
37
19
|
});
|
|
38
20
|
{{/if}}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
{{
|
|
48
|
-
|
|
54
|
+
{{else}}
|
|
55
|
+
return [];
|
|
49
56
|
{{/if}}
|
|
57
|
+
}
|
|
50
58
|
|
|
51
|
-
|
|
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
|
|
3
|
+
import { listUsers } from "../../lib/prisma";
|
|
4
4
|
|
|
5
5
|
export const GET: APIRoute = async () => {
|
|
6
|
-
const users = await
|
|
7
|
-
.
|
|
8
|
-
|
|
9
|
-
|
|
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." }), {
|