added drizzle and connected to vercel
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m21s

This commit is contained in:
ChrQR 2024-05-16 14:37:35 +02:00
parent 8b2feffb1e
commit 98ffb58cdb
8 changed files with 1541 additions and 27 deletions

2
.gitignore vendored
View File

@ -34,3 +34,5 @@ yarn-error.log*
# typescript # typescript
*.tsbuildinfo *.tsbuildinfo
next-env.d.ts next-env.d.ts
.vercel

10
drizzle.config.ts Normal file
View File

@ -0,0 +1,10 @@
import "@/drizzle/envConfig";
import { defineConfig } from "drizzle-kit";
export default defineConfig({
schema: "./drizzle/schema.ts",
dialect: "postgresql",
dbCredentials: {
url: process.env.POSTGRES_URL!,
},
});

10
drizzle/db.ts Normal file
View File

@ -0,0 +1,10 @@
import "@/drizzle/envConfig";
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";
import * as schema from "./schema";
export const db = drizzle(sql, { schema });
export const getUsers = async () => {
return db.query.UsersTable.findMany();
};

4
drizzle/envConfig.ts Normal file
View File

@ -0,0 +1,4 @@
import { loadEnvConfig } from "@next/env";
const projectDir = process.cwd();
loadEnvConfig(projectDir);

25
drizzle/schema.ts Normal file
View File

@ -0,0 +1,25 @@
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";
import {
pgTable,
serial,
text,
timestamp,
uniqueIndex,
} from "drizzle-orm/pg-core";
export const UsersTable = pgTable(
"users",
{
id: serial("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull(),
image: text("image").notNull(),
createdAt: timestamp("createdAt").defaultNow().notNull(),
},
(users) => {
return {
uniqueIdx: uniqueIndex("unique_idx").on(users.email),
};
}
);

1483
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,18 +9,22 @@
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {
"react": "^18", "@next/env": "^14.2.3",
"react-dom": "^18", "@vercel/postgres": "^0.8.0",
"next": "14.2.3" "drizzle-orm": "^0.30.10",
"next": "14.2.3",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}, },
"devDependencies": { "devDependencies": {
"typescript": "^5", "@types/node": "^20.12.12",
"@types/node": "^20", "@types/react": "^18.3.2",
"@types/react": "^18", "@types/react-dom": "^18.3.0",
"@types/react-dom": "^18", "drizzle-kit": "^0.21.2",
"postcss": "^8", "eslint": "^8.57.0",
"tailwindcss": "^3.4.1", "eslint-config-next": "14.2.3",
"eslint": "^8", "postcss": "^8.4.38",
"eslint-config-next": "14.2.3" "tailwindcss": "^3.4.3",
"typescript": "^5.4.5"
} }
} }

View File

@ -21,6 +21,12 @@
"@/*": ["./*"] "@/*": ["./*"]
} }
}, },
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"drizzle.config.ts"
],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }