보조기억장치
Drizzle ORM with NeonDB 본문
Install
npm i drizzle-orm @neondatabase/serverless
npm i -D drizzle-kit
npm i pg
PostgreSQL(lib/db/index.ts) 연결
import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
neonConfig.fetchConnectionCache = true;
const sql = neon(process.env.DRIZZLE_DATABASE_URL!);
const db = drizzle(sql);
const result = await db.select().from(...);
스키마 (lib/db/schema.ts)
import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
export const $notes = pgTable("notes", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
imageUrl: text("imageUrl"),
userId: text("user_id").notNull(),
editorState: text("editor_state"),
});
export type NoteType = typeof $notes.$inferInsert;
// drizzle-orm
// drizzle-kit
--
npx drizzle-kit push:pg
npx drizzle-kit studio
'IT' 카테고리의 다른 글
VMware Workstation 17.6.3 Pro 릴리스 노트 (0) | 2025.03.07 |
---|---|
Node Exporter를 사용하여 Linux 호스트 메트릭 모니터링 (0) | 2024.12.19 |
VS Code에서 GitHub Copilot에 대한 1억 5천만 명의 개발자와 새로운 무료 계층 발표 (3) | 2024.12.19 |
DSM 7.2.1-69057 Update 3 (0) | 2023.11.25 |
Filebeat 설치 (0) | 2023.04.18 |