Skip to content

Commit

Permalink
Fix database package typing
Browse files Browse the repository at this point in the history
  • Loading branch information
gramliu committed Oct 22, 2023
1 parent fd100ce commit 404ad55
Show file tree
Hide file tree
Showing 7 changed files with 482 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
node_modules
.pnp
.pnp.js
dist

# testing
coverage
Expand Down
6 changes: 5 additions & 1 deletion packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
"studio": "prisma studio"
},
"dependencies": {
"@prisma/client": "^5.4.2"
"@prisma/client": "^5.4.2",
"@t3-oss/env-core": "^0.7.1",
"core": "link:@t3-oss/env/core",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^17.0.12",
"config": "workspace:*",
"eslint": "^8.12.0",
"prisma": "^5.4.2",
Expand Down
16 changes: 9 additions & 7 deletions packages/database/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { PrismaClient } from "@prisma/client";
import { env } from "./env";

declare global {
var prisma: PrismaClient | undefined;
}
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };

export const prisma = global.prisma || new PrismaClient();
export const prisma =
globalForPrisma.prisma ||
new PrismaClient({
log: ["error"],
});

if (process.env.NODE_ENV !== "production") global.prisma = prisma;

export * from "@prisma/client";
if (env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
export * from "@prisma/client"
12 changes: 12 additions & 0 deletions packages/database/src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";

export const env = createEnv({
clientPrefix: "PUBLIC_",
server: {
NODE_ENV: z.enum(["development", "test", "production"]),
DATABASE_URL: z.string().url(),
},
client: {},
runtimeEnv: process.env,
});
36 changes: 0 additions & 36 deletions packages/database/src/seed.ts

This file was deleted.

12 changes: 10 additions & 2 deletions packages/database/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ const isProduction = process.env.NODE_ENV === "production";

export default defineConfig({
clean: true,
dts: true,
dts: {
"resolve": true,
"entry": [
"./src/index.ts"
],
"compilerOptions": {
"moduleResolution": "node"
}
},
entry: ["src/index.ts"],
format: ["cjs", "esm"],
minify: isProduction,
sourcemap: true,
});
});
Loading

0 comments on commit 404ad55

Please sign in to comment.