diff options
Diffstat (limited to 'examples/with-prisma/packages')
14 files changed, 224 insertions, 0 deletions
diff --git a/examples/with-prisma/packages/config/eslint-preset.js b/examples/with-prisma/packages/config/eslint-preset.js new file mode 100644 index 0000000..12cbba4 --- /dev/null +++ b/examples/with-prisma/packages/config/eslint-preset.js @@ -0,0 +1,16 @@ +module.exports = { + extends: ["next", "turbo", "prettier"], + settings: { + next: { + rootDir: ["apps/*/", "packages/*/"], + }, + }, + rules: { + "@next/next/no-html-link-for-pages": "off", + }, + parserOptions: { + babelOptions: { + presets: [require.resolve("next/babel")], + }, + }, +}; diff --git a/examples/with-prisma/packages/config/package.json b/examples/with-prisma/packages/config/package.json new file mode 100644 index 0000000..1749cff --- /dev/null +++ b/examples/with-prisma/packages/config/package.json @@ -0,0 +1,18 @@ +{ + "name": "config", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "files": [ + "eslint-preset.js" + ], + "dependencies": { + "eslint-config-next": "latest", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-react": "7.28.0", + "eslint-config-turbo": "latest" + }, + "devDependencies": { + "typescript": "^4.5.3" + } +} diff --git a/examples/with-prisma/packages/database/.eslintrc.js b/examples/with-prisma/packages/database/.eslintrc.js new file mode 100644 index 0000000..dc369e9 --- /dev/null +++ b/examples/with-prisma/packages/database/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require("config/eslint-preset"); diff --git a/examples/with-prisma/packages/database/package.json b/examples/with-prisma/packages/database/package.json new file mode 100644 index 0000000..b7c046c --- /dev/null +++ b/examples/with-prisma/packages/database/package.json @@ -0,0 +1,39 @@ +{ + "name": "database", + "version": "1.0.0", + "license": "MIT", + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist/**" + ], + "scripts": { + "build": "tsup", + "clean": "rimraf .turbo node_modules dist", + "db:migrate:deploy": "prisma migrate deploy", + "db:migrate:dev": "prisma migrate dev", + "db:push": "prisma db push", + "db:seed": "tsx src/seed.ts", + "dev": "tsup --watch", + "format": "prisma format", + "generate": "prisma generate", + "lint": "eslint \"src/**/*.ts\"", + "prebuild": "npm run generate", + "predev": "npm run generate", + "studio": "prisma studio" + }, + "dependencies": { + "@prisma/client": "^3.10.0" + }, + "devDependencies": { + "config": "*", + "eslint": "^8.12.0", + "prisma": "^3.10.0", + "rimraf": "^3.0.2", + "tsconfig": "*", + "tsup": "^5.11.13", + "tsx": "^3.7.1", + "typescript": "^4.5.5" + } +} diff --git a/examples/with-prisma/packages/database/prisma/schema.prisma b/examples/with-prisma/packages/database/prisma/schema.prisma new file mode 100644 index 0000000..b2fb730 --- /dev/null +++ b/examples/with-prisma/packages/database/prisma/schema.prisma @@ -0,0 +1,20 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +datasource db { + provider = "mysql" + url = env("DATABASE_URL") + referentialIntegrity = "prisma" +} + +generator client { + provider = "prisma-client-js" + previewFeatures = ["referentialIntegrity"] +} + +model User { + id String @id @default(cuid()) + name String? + email String? @unique + emailVerified DateTime? +} diff --git a/examples/with-prisma/packages/database/src/client.ts b/examples/with-prisma/packages/database/src/client.ts new file mode 100644 index 0000000..481d7a9 --- /dev/null +++ b/examples/with-prisma/packages/database/src/client.ts @@ -0,0 +1,11 @@ +import { PrismaClient } from "@prisma/client"; + +declare global { + var prisma: PrismaClient | undefined; +} + +export const prisma = global.prisma || new PrismaClient(); + +if (process.env.NODE_ENV !== "production") global.prisma = prisma; + +export * from "@prisma/client"; diff --git a/examples/with-prisma/packages/database/src/index.ts b/examples/with-prisma/packages/database/src/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/examples/with-prisma/packages/database/src/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/examples/with-prisma/packages/database/src/seed.ts b/examples/with-prisma/packages/database/src/seed.ts new file mode 100644 index 0000000..a5d7752 --- /dev/null +++ b/examples/with-prisma/packages/database/src/seed.ts @@ -0,0 +1,36 @@ +import { prisma } from "."; + +import type { User } from "@prisma/client"; + +const DEFAULT_USERS = [ + // Add your own user to pre-populate the database with + { + name: "Tim Apple", + email: "tim@apple.com", + }, +] as Array<Partial<User>>; + +(async () => { + try { + await Promise.all( + DEFAULT_USERS.map((user) => + prisma.user.upsert({ + where: { + email: user.email!, + }, + update: { + ...user, + }, + create: { + ...user, + }, + }) + ) + ); + } catch (error) { + console.error(error); + process.exit(1); + } finally { + await prisma.$disconnect(); + } +})(); diff --git a/examples/with-prisma/packages/database/tsconfig.json b/examples/with-prisma/packages/database/tsconfig.json new file mode 100644 index 0000000..cbf6061 --- /dev/null +++ b/examples/with-prisma/packages/database/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "tsconfig/node16.json", + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "tsup.config.ts"], + "exclude": ["node_modules"] +} diff --git a/examples/with-prisma/packages/database/tsup.config.ts b/examples/with-prisma/packages/database/tsup.config.ts new file mode 100644 index 0000000..27be5a7 --- /dev/null +++ b/examples/with-prisma/packages/database/tsup.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from "tsup"; + +const isProduction = process.env.NODE_ENV === "production"; + +export default defineConfig({ + clean: true, + dts: true, + entry: ["src/index.ts"], + format: ["cjs", "esm"], + minify: isProduction, + sourcemap: true, +}); diff --git a/examples/with-prisma/packages/tsconfig/base.json b/examples/with-prisma/packages/tsconfig/base.json new file mode 100644 index 0000000..d72a9f3 --- /dev/null +++ b/examples/with-prisma/packages/tsconfig/base.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "display": "Default", + "compilerOptions": { + "composite": false, + "declaration": true, + "declarationMap": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "inlineSources": false, + "isolatedModules": true, + "moduleResolution": "node", + "noUnusedLocals": false, + "noUnusedParameters": false, + "preserveWatchOutput": true, + "skipLibCheck": true, + "strict": true + }, + "exclude": ["node_modules"] +} diff --git a/examples/with-prisma/packages/tsconfig/nextjs.json b/examples/with-prisma/packages/tsconfig/nextjs.json new file mode 100644 index 0000000..91cd404 --- /dev/null +++ b/examples/with-prisma/packages/tsconfig/nextjs.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "display": "Next.js", + "extends": "./base.json", + "compilerOptions": { + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "incremental": true, + "esModuleInterop": true, + "module": "esnext", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve" + }, + "include": ["src", "next-env.d.ts"], + "exclude": ["node_modules"] +} diff --git a/examples/with-prisma/packages/tsconfig/node16.json b/examples/with-prisma/packages/tsconfig/node16.json new file mode 100644 index 0000000..bf7fb49 --- /dev/null +++ b/examples/with-prisma/packages/tsconfig/node16.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "display": "Node 16", + "extends": "./base.json", + "compilerOptions": { + "lib": ["ES2021"], + "module": "commonjs", + "target": "ES2021", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true + } +} diff --git a/examples/with-prisma/packages/tsconfig/package.json b/examples/with-prisma/packages/tsconfig/package.json new file mode 100644 index 0000000..6efb83e --- /dev/null +++ b/examples/with-prisma/packages/tsconfig/package.json @@ -0,0 +1,9 @@ +{ + "name": "tsconfig", + "version": "0.0.0", + "private": true, + "license": "MIT", + "publishConfig": { + "access": "public" + } +} |
