create-lx2-app 0.11.4 → 0.11.5-beta.1c75eb9
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/dist/index.js +28 -26
- package/package.json +104 -98
- package/template/base/_gitignore +1 -0
- package/template/packages/config/prisma.config.ts +14 -0
- package/template/packages/prisma/schema/base.prisma +1 -1
- package/template/packages/prisma/schema/with-authjs.prisma +1 -1
- package/template/packages/prisma/schema/with-better-auth.prisma +1 -1
- package/template/packages/src/app/api/trpc/[trpc]/route.ts +34 -0
- package/template/packages/src/app/layout/with-trpc.tsx +37 -0
- package/template/packages/src/app/page/with-authjs-prisma.tsx +6 -0
- package/template/packages/src/app/page/with-better-auth-prisma.tsx +6 -0
- package/template/packages/src/app/page/with-prisma.tsx +6 -0
- package/template/packages/src/app/page/with-trpc.tsx +115 -0
- package/template/packages/src/components/greeting.tsx +21 -0
- package/template/packages/src/env/with-better-auth-db.js +2 -2
- package/template/packages/src/env/with-better-auth.js +2 -2
- package/template/packages/src/env/with-trpc-authjs-db.js +55 -0
- package/template/packages/src/env/with-trpc-authjs.js +53 -0
- package/template/packages/src/env/with-trpc-better-auth-db.js +52 -0
- package/template/packages/src/env/with-trpc-better-auth.js +50 -0
- package/template/packages/src/env/with-trpc-db.js +46 -0
- package/template/packages/src/env/with-trpc.js +44 -0
- package/template/packages/src/lib/api/client.tsx +85 -0
- package/template/packages/src/lib/api/query-client.ts +22 -0
- package/template/packages/src/lib/api/server.ts +31 -0
- package/template/packages/src/lib/auth/better-auth-client.ts +1 -1
- package/template/packages/src/lib/utils.ts +7 -0
- package/template/packages/src/server/api/init/base.ts +103 -0
- package/template/packages/src/server/api/init/with-authjs-db.ts +132 -0
- package/template/packages/src/server/api/init/with-authjs.ts +130 -0
- package/template/packages/src/server/api/init/with-betterauth-db.ts +134 -0
- package/template/packages/src/server/api/init/with-betterauth.ts +132 -0
- package/template/packages/src/server/api/init/with-db.ts +106 -0
- package/template/packages/src/server/api/root.ts +23 -0
- package/template/packages/src/server/api/routers/post/base.ts +46 -0
- package/template/packages/src/server/api/routers/post/with-auth-drizzle.ts +44 -0
- package/template/packages/src/server/api/routers/post/with-auth-prisma.ts +47 -0
- package/template/packages/src/server/api/routers/post/with-auth.ts +43 -0
- package/template/packages/src/server/api/routers/post/with-drizzle.ts +36 -0
- package/template/packages/src/server/api/routers/post/with-prisma.ts +37 -0
- package/template/packages/src/server/auth/better-auth-with-drizzle.ts +1 -1
- package/template/packages/src/server/auth/better-auth-with-prisma.ts +1 -1
- package/template/packages/src/server/auth/better-auth.ts +1 -0
- package/template/packages/src/server/auth/config/authjs-with-drizzle.ts +1 -1
- package/template/packages/src/server/auth/config/authjs-with-prisma.ts +1 -1
- package/template/packages/src/server/auth/config/authjs.ts +1 -1
- package/template/packages/src/server/db/{db-prisma.ts → prisma/with-mysql.ts} +5 -1
- package/template/packages/src/server/db/prisma/with-postgresql.ts +29 -0
- package/template/packages/src/server/db/prisma/with-sqlite-bun.ts +29 -0
- package/template/packages/src/server/db/prisma/with-sqlite.ts +29 -0
- package/LICENSE.md +0 -20
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YOU PROBABLY DON'T NEED TO EDIT THIS FILE, UNLESS:
|
|
3
|
+
* 1. You want to modify request context (see Part 1).
|
|
4
|
+
* 2. You want to create a new middleware or type of procedure (see Part 3).
|
|
5
|
+
*
|
|
6
|
+
* TL;DR - This is where all the tRPC server stuff is created and plugged in.
|
|
7
|
+
* The pieces you will need to use are documented accordingly near the end.
|
|
8
|
+
*/
|
|
9
|
+
import { initTRPC } from "@trpc/server"
|
|
10
|
+
import superjson from "superjson"
|
|
11
|
+
import { z, ZodError } from "zod"
|
|
12
|
+
|
|
13
|
+
import { db } from "@/server/db"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 1. CONTEXT
|
|
17
|
+
*
|
|
18
|
+
* This section defines the "contexts" that are available in the backend API.
|
|
19
|
+
*
|
|
20
|
+
* These allow you to access things when processing a request, like the database, the session, etc.
|
|
21
|
+
*
|
|
22
|
+
* This helper generates the "internals" for a tRPC context. The API handler and RSC clients each
|
|
23
|
+
* wrap this and provides the required context.
|
|
24
|
+
*
|
|
25
|
+
* @see https://trpc.io/docs/server/context
|
|
26
|
+
*/
|
|
27
|
+
export async function createTRPCContext(opts: { headers: Headers }) {
|
|
28
|
+
return {
|
|
29
|
+
db,
|
|
30
|
+
...opts,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 2. INITIALIZATION
|
|
36
|
+
*
|
|
37
|
+
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
|
|
38
|
+
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
|
|
39
|
+
* errors on the backend.
|
|
40
|
+
*/
|
|
41
|
+
const t = initTRPC.context<typeof createTRPCContext>().create({
|
|
42
|
+
transformer: superjson,
|
|
43
|
+
errorFormatter({ shape, error }) {
|
|
44
|
+
return {
|
|
45
|
+
...shape,
|
|
46
|
+
data: {
|
|
47
|
+
...shape.data,
|
|
48
|
+
zodError:
|
|
49
|
+
error.cause instanceof ZodError ? z.treeifyError(error.cause) : null,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Create a server-side caller.
|
|
57
|
+
*
|
|
58
|
+
* @see https://trpc.io/docs/server/server-side-calls
|
|
59
|
+
*/
|
|
60
|
+
export const createCallerFactory = t.createCallerFactory
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 3. ROUTER & PROCEDURE (THE IMPORTANT BIT)
|
|
64
|
+
*
|
|
65
|
+
* These are the pieces you use to build your tRPC API. You should import these a lot in the
|
|
66
|
+
* "/src/server/api/routers" directory.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* This is how you create new routers and sub-routers in your tRPC API.
|
|
71
|
+
*
|
|
72
|
+
* @see https://trpc.io/docs/router
|
|
73
|
+
*/
|
|
74
|
+
export const createTRPCRouter = t.router
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Middleware for timing procedure execution and adding an artificial delay in development.
|
|
78
|
+
*
|
|
79
|
+
* You can remove this if you don't like it, but it can help catch unwanted waterfalls by simulating
|
|
80
|
+
* network latency that would occur in production but not in local development.
|
|
81
|
+
*/
|
|
82
|
+
const timingMiddleware = t.middleware(async ({ next, path }) => {
|
|
83
|
+
const start = Date.now()
|
|
84
|
+
|
|
85
|
+
if (t._config.isDev) {
|
|
86
|
+
// artificial delay in dev
|
|
87
|
+
const waitMs = Math.floor(Math.random() * 400) + 100
|
|
88
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const result = await next()
|
|
92
|
+
|
|
93
|
+
const end = Date.now()
|
|
94
|
+
console.log(`[TRPC] ${path} took ${end - start}ms to execute`)
|
|
95
|
+
|
|
96
|
+
return result
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Public (unauthenticated) procedure
|
|
101
|
+
*
|
|
102
|
+
* This is the base piece you use to build new queries and mutations on your tRPC API. It does not
|
|
103
|
+
* guarantee that a user querying is authorized, but you can still access user session data if they
|
|
104
|
+
* are logged in.
|
|
105
|
+
*/
|
|
106
|
+
export const publicProcedure = t.procedure.use(timingMiddleware)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createCallerFactory, createTRPCRouter } from "@/server/api/init"
|
|
2
|
+
import { postRouter } from "@/server/api/routers/post"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This is the primary router for your server.
|
|
6
|
+
*
|
|
7
|
+
* All routers added in /api/routers should be manually added here.
|
|
8
|
+
*/
|
|
9
|
+
export const appRouter = createTRPCRouter({
|
|
10
|
+
post: postRouter,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
// Export type definition of API
|
|
14
|
+
export type AppRouter = typeof appRouter
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create a server-side caller for the tRPC API.
|
|
18
|
+
* @example
|
|
19
|
+
* const trpc = createCaller(createContext);
|
|
20
|
+
* const res = await trpc.post.all();
|
|
21
|
+
* ^? Post[]
|
|
22
|
+
*/
|
|
23
|
+
export const createCaller = createCallerFactory(appRouter)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
|
|
3
|
+
import { createTRPCRouter, publicProcedure } from "@/server/api/init"
|
|
4
|
+
|
|
5
|
+
// Mocked DB
|
|
6
|
+
interface Post {
|
|
7
|
+
id: number
|
|
8
|
+
name: string
|
|
9
|
+
}
|
|
10
|
+
const posts: Post[] = [
|
|
11
|
+
{
|
|
12
|
+
id: 1,
|
|
13
|
+
name: "Hello World",
|
|
14
|
+
},
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
export const postRouter = createTRPCRouter({
|
|
18
|
+
greeting: publicProcedure
|
|
19
|
+
.input(
|
|
20
|
+
z.object({
|
|
21
|
+
text: z.string(),
|
|
22
|
+
})
|
|
23
|
+
)
|
|
24
|
+
.query(({ input }) => {
|
|
25
|
+
return `Hello ${input.text}`
|
|
26
|
+
}),
|
|
27
|
+
|
|
28
|
+
create: publicProcedure
|
|
29
|
+
.input(
|
|
30
|
+
z.object({
|
|
31
|
+
name: z.string().min(1),
|
|
32
|
+
})
|
|
33
|
+
)
|
|
34
|
+
.mutation(async ({ input }) => {
|
|
35
|
+
const post: Post = {
|
|
36
|
+
id: posts.length + 1,
|
|
37
|
+
name: input.name,
|
|
38
|
+
}
|
|
39
|
+
posts.push(post)
|
|
40
|
+
return post
|
|
41
|
+
}),
|
|
42
|
+
|
|
43
|
+
getLatest: publicProcedure.query(async () => {
|
|
44
|
+
return posts.at(-1) || null
|
|
45
|
+
}),
|
|
46
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createTRPCRouter,
|
|
5
|
+
protectedProcedure,
|
|
6
|
+
publicProcedure,
|
|
7
|
+
} from "@/server/api/init"
|
|
8
|
+
import { post } from "@/server/db/schema"
|
|
9
|
+
|
|
10
|
+
export const postRouter = createTRPCRouter({
|
|
11
|
+
greeting: publicProcedure
|
|
12
|
+
.input(
|
|
13
|
+
z.object({
|
|
14
|
+
text: z.string(),
|
|
15
|
+
})
|
|
16
|
+
)
|
|
17
|
+
.query(({ input }) => {
|
|
18
|
+
return `Hello ${input.text}`
|
|
19
|
+
}),
|
|
20
|
+
|
|
21
|
+
create: protectedProcedure
|
|
22
|
+
.input(
|
|
23
|
+
z.object({
|
|
24
|
+
name: z.string().min(1),
|
|
25
|
+
})
|
|
26
|
+
)
|
|
27
|
+
.mutation(async ({ ctx, input }) => {
|
|
28
|
+
await ctx.db.insert(post).values({
|
|
29
|
+
name: input.name,
|
|
30
|
+
})
|
|
31
|
+
}),
|
|
32
|
+
|
|
33
|
+
getLatest: protectedProcedure.query(async ({ ctx }) => {
|
|
34
|
+
const post = await ctx.db.query.post.findFirst({
|
|
35
|
+
orderBy: (post, { desc }) => [desc(post.createdAt)],
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return post ?? null
|
|
39
|
+
}),
|
|
40
|
+
|
|
41
|
+
getSecretMessage: protectedProcedure.query(() => {
|
|
42
|
+
return "you can now see this secret message!"
|
|
43
|
+
}),
|
|
44
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createTRPCRouter,
|
|
5
|
+
protectedProcedure,
|
|
6
|
+
publicProcedure,
|
|
7
|
+
} from "@/server/api/init"
|
|
8
|
+
|
|
9
|
+
export const postRouter = createTRPCRouter({
|
|
10
|
+
greeting: publicProcedure
|
|
11
|
+
.input(
|
|
12
|
+
z.object({
|
|
13
|
+
text: z.string(),
|
|
14
|
+
})
|
|
15
|
+
)
|
|
16
|
+
.query(({ input }) => {
|
|
17
|
+
return `Hello ${input.text}`
|
|
18
|
+
}),
|
|
19
|
+
|
|
20
|
+
create: protectedProcedure
|
|
21
|
+
.input(
|
|
22
|
+
z.object({
|
|
23
|
+
name: z.string().min(1),
|
|
24
|
+
})
|
|
25
|
+
)
|
|
26
|
+
.mutation(async ({ ctx, input }) => {
|
|
27
|
+
return ctx.db.post.create({
|
|
28
|
+
data: {
|
|
29
|
+
name: input.name,
|
|
30
|
+
createdBy: { connect: { id: ctx.session.user.id } },
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
}),
|
|
34
|
+
|
|
35
|
+
getLatest: protectedProcedure.query(async ({ ctx }) => {
|
|
36
|
+
const post = await ctx.db.post.findFirst({
|
|
37
|
+
orderBy: { createdAt: "desc" },
|
|
38
|
+
where: { createdBy: { id: ctx.session.user.id } },
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return post ?? null
|
|
42
|
+
}),
|
|
43
|
+
|
|
44
|
+
getSecretMessage: protectedProcedure.query(() => {
|
|
45
|
+
return "you can now see this secret message!"
|
|
46
|
+
}),
|
|
47
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createTRPCRouter,
|
|
5
|
+
protectedProcedure,
|
|
6
|
+
publicProcedure,
|
|
7
|
+
} from "@/server/api/init"
|
|
8
|
+
|
|
9
|
+
let post = {
|
|
10
|
+
id: 1,
|
|
11
|
+
name: "Hello World",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const postRouter = createTRPCRouter({
|
|
15
|
+
greeting: publicProcedure
|
|
16
|
+
.input(
|
|
17
|
+
z.object({
|
|
18
|
+
text: z.string(),
|
|
19
|
+
})
|
|
20
|
+
)
|
|
21
|
+
.query(({ input }) => {
|
|
22
|
+
return `Hello ${input.text}`
|
|
23
|
+
}),
|
|
24
|
+
|
|
25
|
+
create: protectedProcedure
|
|
26
|
+
.input(
|
|
27
|
+
z.object({
|
|
28
|
+
name: z.string().min(1),
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
.mutation(async ({ input }) => {
|
|
32
|
+
post = { id: post.id + 1, name: input.name }
|
|
33
|
+
return post
|
|
34
|
+
}),
|
|
35
|
+
|
|
36
|
+
getLatest: protectedProcedure.query(async () => {
|
|
37
|
+
return post
|
|
38
|
+
}),
|
|
39
|
+
|
|
40
|
+
getSecretMessage: protectedProcedure.query(() => {
|
|
41
|
+
return "you can now see this secret message!"
|
|
42
|
+
}),
|
|
43
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
|
|
3
|
+
import { createTRPCRouter, publicProcedure } from "@/server/api/init"
|
|
4
|
+
import { post } from "@/server/db/schema"
|
|
5
|
+
|
|
6
|
+
export const postRouter = createTRPCRouter({
|
|
7
|
+
greeting: publicProcedure
|
|
8
|
+
.input(
|
|
9
|
+
z.object({
|
|
10
|
+
text: z.string(),
|
|
11
|
+
})
|
|
12
|
+
)
|
|
13
|
+
.query(({ input }) => {
|
|
14
|
+
return `Hello ${input.text}`
|
|
15
|
+
}),
|
|
16
|
+
|
|
17
|
+
create: publicProcedure
|
|
18
|
+
.input(
|
|
19
|
+
z.object({
|
|
20
|
+
name: z.string().min(1),
|
|
21
|
+
})
|
|
22
|
+
)
|
|
23
|
+
.mutation(async ({ ctx, input }) => {
|
|
24
|
+
await ctx.db.insert(post).values({
|
|
25
|
+
name: input.name,
|
|
26
|
+
})
|
|
27
|
+
}),
|
|
28
|
+
|
|
29
|
+
getLatest: publicProcedure.query(async ({ ctx }) => {
|
|
30
|
+
const post = await ctx.db.query.post.findFirst({
|
|
31
|
+
orderBy: (post, { desc }) => [desc(post.createdAt)],
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
return post ?? null
|
|
35
|
+
}),
|
|
36
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
|
|
3
|
+
import { createTRPCRouter, publicProcedure } from "@/server/api/init"
|
|
4
|
+
|
|
5
|
+
export const postRouter = createTRPCRouter({
|
|
6
|
+
greeting: publicProcedure
|
|
7
|
+
.input(
|
|
8
|
+
z.object({
|
|
9
|
+
text: z.string(),
|
|
10
|
+
})
|
|
11
|
+
)
|
|
12
|
+
.query(({ input }) => {
|
|
13
|
+
return `Hello ${input.text}`
|
|
14
|
+
}),
|
|
15
|
+
|
|
16
|
+
create: publicProcedure
|
|
17
|
+
.input(
|
|
18
|
+
z.object({
|
|
19
|
+
name: z.string().min(1),
|
|
20
|
+
})
|
|
21
|
+
)
|
|
22
|
+
.mutation(async ({ ctx, input }) => {
|
|
23
|
+
return ctx.db.post.create({
|
|
24
|
+
data: {
|
|
25
|
+
name: input.name,
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
}),
|
|
29
|
+
|
|
30
|
+
getLatest: publicProcedure.query(async ({ ctx }) => {
|
|
31
|
+
const post = await ctx.db.post.findFirst({
|
|
32
|
+
orderBy: { createdAt: "desc" },
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return post ?? null
|
|
36
|
+
}),
|
|
37
|
+
})
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PrismaMariaDb } from "@prisma/adapter-mariadb"
|
|
2
2
|
|
|
3
3
|
import { env } from "@/env"
|
|
4
|
+
import { PrismaClient } from "@/generated/prisma"
|
|
5
|
+
|
|
6
|
+
const adapter = new PrismaMariaDb(env.DATABASE_URL)
|
|
4
7
|
|
|
5
8
|
const createPrismaClient = () =>
|
|
6
9
|
new PrismaClient({
|
|
10
|
+
adapter,
|
|
7
11
|
log:
|
|
8
12
|
env.NODE_ENV === "development"
|
|
9
13
|
? [
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PrismaPg } from "@prisma/adapter-pg"
|
|
2
|
+
|
|
3
|
+
import { env } from "@/env"
|
|
4
|
+
import { PrismaClient } from "@/generated/prisma"
|
|
5
|
+
|
|
6
|
+
const adapter = new PrismaPg({
|
|
7
|
+
connectionString: env.DATABASE_URL,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const createPrismaClient = () =>
|
|
11
|
+
new PrismaClient({
|
|
12
|
+
adapter,
|
|
13
|
+
log:
|
|
14
|
+
env.NODE_ENV === "development"
|
|
15
|
+
? [
|
|
16
|
+
// "query",
|
|
17
|
+
"error",
|
|
18
|
+
"warn",
|
|
19
|
+
]
|
|
20
|
+
: ["error"],
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const globalForPrisma = globalThis as unknown as {
|
|
24
|
+
prisma: ReturnType<typeof createPrismaClient> | undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const db = globalForPrisma.prisma ?? createPrismaClient()
|
|
28
|
+
|
|
29
|
+
if (env.NODE_ENV !== "production") globalForPrisma.prisma = db
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PrismaLibSql } from "@prisma/adapter-libsql"
|
|
2
|
+
|
|
3
|
+
import { env } from "@/env"
|
|
4
|
+
import { PrismaClient } from "@/generated/prisma"
|
|
5
|
+
|
|
6
|
+
const adapter = new PrismaLibSql({
|
|
7
|
+
url: env.DATABASE_URL,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const createPrismaClient = () =>
|
|
11
|
+
new PrismaClient({
|
|
12
|
+
adapter,
|
|
13
|
+
log:
|
|
14
|
+
env.NODE_ENV === "development"
|
|
15
|
+
? [
|
|
16
|
+
// "query",
|
|
17
|
+
"error",
|
|
18
|
+
"warn",
|
|
19
|
+
]
|
|
20
|
+
: ["error"],
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const globalForPrisma = globalThis as unknown as {
|
|
24
|
+
prisma: ReturnType<typeof createPrismaClient> | undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const db = globalForPrisma.prisma ?? createPrismaClient()
|
|
28
|
+
|
|
29
|
+
if (env.NODE_ENV !== "production") globalForPrisma.prisma = db
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3"
|
|
2
|
+
|
|
3
|
+
import { env } from "@/env"
|
|
4
|
+
import { PrismaClient } from "@/generated/prisma"
|
|
5
|
+
|
|
6
|
+
const adapter = new PrismaBetterSqlite3({
|
|
7
|
+
url: env.DATABASE_URL,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const createPrismaClient = () =>
|
|
11
|
+
new PrismaClient({
|
|
12
|
+
adapter,
|
|
13
|
+
log:
|
|
14
|
+
env.NODE_ENV === "development"
|
|
15
|
+
? [
|
|
16
|
+
// "query",
|
|
17
|
+
"error",
|
|
18
|
+
"warn",
|
|
19
|
+
]
|
|
20
|
+
: ["error"],
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const globalForPrisma = globalThis as unknown as {
|
|
24
|
+
prisma: ReturnType<typeof createPrismaClient> | undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const db = globalForPrisma.prisma ?? createPrismaClient()
|
|
28
|
+
|
|
29
|
+
if (env.NODE_ENV !== "production") globalForPrisma.prisma = db
|
package/LICENSE.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Lasse Lammers
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
-
the Software without restriction, including without limitation the rights to
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
-
subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|