Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drizzle-kit configuration #54

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -18,7 +18,14 @@ npx create-next-app nextjs-typescript-starter --example "https://github.com/verc

## Getting Started

First, run the development server:
Copy .env.example to .env and add your postgresql settings, along with a randomly created AUTH_SECRET value.
Then, apply the drizzle schema to your database:

```
drizzle-kit push
```

Finally, run the development server:

```bash
pnpm dev
9 changes: 2 additions & 7 deletions app/db.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { drizzle } from 'drizzle-orm/postgres-js';
import { pgTable, serial, varchar } from 'drizzle-orm/pg-core';
import { eq } from 'drizzle-orm';
import postgres from 'postgres';
import { genSaltSync, hashSync } from 'bcrypt-ts';
import { users } from './schema';

// Optionally, if not using email/pass login, you can
// use the Drizzle adapter for Auth.js / NextAuth
// https://authjs.dev/reference/adapter/drizzle
let client = postgres(`${process.env.POSTGRES_URL!}?sslmode=require`);
let client = postgres(`${process.env.POSTGRES_URL!}`);
let db = drizzle(client);

let users = pgTable('User', {
id: serial('id').primaryKey(),
email: varchar('email', { length: 64 }),
password: varchar('password', { length: 64 }),
});

export async function getUser(email: string) {
return await db.select().from(users).where(eq(users.email, email));
7 changes: 7 additions & 0 deletions app/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { pgTable, serial, varchar } from 'drizzle-orm/pg-core';

export const users = pgTable('User', {
id: serial('id').primaryKey(),
email: varchar('email', { length: 64 }),
password: varchar('password', { length: 64 }),
});
10 changes: 10 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
schema: './app/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
url: process.env.POSTGRES_URL!
}
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
"scripts": {
"dev": "next dev --turbo",
"build": "next build",
"generate": "drizzle-kit generate:pg --out drizzle --schema app/db/schema.ts",
"start": "next start",
"lint": "next lint"
},
@@ -21,6 +22,7 @@
},
"devDependencies": {
"autoprefixer": "^10.4.16",
"drizzle-kit": "^0.21.4",
"eslint": "8.56.0",
"eslint-config-next": "^14.0.4",
"postcss": "^8.4.32",
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,