8## TO CREATE A FRESH PROJECT USING NODE
npm create hono@latest
npm install bcrypt
npm install --save @types/bcrypt
npm install --save drizzle-kit
npm install drizzle-orm pg
npm install --save drizzle-kit @types/pg
import {defineConfig} from 'drizzle-kit'
export default defineConfig({
schema:'./src/schema.ts',
out:'./drizzle',
dialect:'postgresql',
dbCredentials:{
host:"localhost",
port: 5433,
user: "postgres",
password: "password",
database:"hono"
}
})
import { client, db } from "../client";
import {migrate} from 'drizzle-orm/node-postgres/migrator'
async function Migrate(){
await migrate(db,{migrationsFolder:'./drizzle'});
await client.end();
}
Migrate();
import { Client } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from './src/schema';
export const client = new Client({
host: "localhost",
port: 5433,
user: "postgres",
password: "password",
database: "hono",
});
async function connectClient() {
try {
await client.connect();
console.log('Connected to PostgreSQL successfully');
} catch (err) {
console.error('Failed to connect to PostgreSQL', err);
process.exit(1);
}
}
connectClient();
export const db = drizzle(client, { schema });
process.on('exit', async () => {
await client.end();
console.log('Disconnected from PostgreSQL');
});
bunx drizzle-kit generate
npx tax src/migrate.ts
npx drizzle-kit studio
npx drizzle-kit studio --port 3000
npm run dev
bun install
bunx drizzle-kit generate
bunx tsx src/migrate.ts
bunx drizzle-kit studio
bunx drizzle-kit studio --port 3000
bun run dev
bun create hono@latest
bun add -D drizzle-kit
bun add drizzle-orm pg
bun add -D drizzle-kit @types/pg
import {defineConfig} from 'drizzle-kit'
export default defineConfig({
schema:'./src/schema.ts',
out:'./drizzle',
dialect:'postgresql',
dbCredentials:{
host:"localhost",
port: 5433,
user: "postgres",
password: "password",
database:"hono"
}
})
import { client, db } from "../client";
import {migrate} from 'drizzle-orm/node-postgres/migrator'
async function Migrate(){
await migrate(db,{migrationsFolder:'./drizzle'});
await client.end();
}
Migrate();
import { Client } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from './src/schema';
export const client = new Client({
host: "localhost",
port: 5433,
user: "postgres",
password: "password",
database: "hono",
});
async function connectClient() {
try {
await client.connect();
console.log('Connected to PostgreSQL successfully');
} catch (err) {
console.error('Failed to connect to PostgreSQL', err);
process.exit(1);
}
}
connectClient();
export const db = drizzle(client, { schema });
process.on('exit', async () => {
await client.end();
console.log('Disconnected from PostgreSQL');
});
bunx drizzle-kit generate
bunx tax src/migrate.ts
drizzle-kit studio
drizzle-kit studio --port 3000