
โ Self Reference
export const postReplies = pgTable("post_replies", {
post_reply_id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity(),
post_id: bigint({ mode: "number" }).references(() => posts.post_id, {
onDelete: "cascade",
}),
parent_id: bigint({ mode: "number" }).references(
(): AnyPgColumn => postReplies.post_reply_id, // AnyPgColumn์ ์์ฒด ์ฐธ์กฐ๋ฅผ ํ๊ธฐ ์ํด ํ์(ํ์
์์ ์ฑ)
{
onDelete: "cascade",
},
),
profile_id: uuid()
.references(() => profiles.profile_id, {
onDelete: "cascade",
})
.notNull(),
reply: text().notNull(),
created_at: timestamp().notNull().defaultNow(),
updated_at: timestamp().notNull().defaultNow(),
});
์ฌ๊ธฐ์ AnyPgColumn์ Self Reference๋ฅผ ํ๊ธฐ ์ํด ํ์ํ ํ์ ์ด๋ค.
https://orm.drizzle.team/docs/indexes-constraints#foreign-key
Drizzle ORM - Indexes & Constraints
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
orm.drizzle.team
'๐งฉ SQL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| SQL - Supabase & Drizzle (0) | 2026.05.22 |
|---|---|
| SQL - Drizzle(ORM) (0) | 2026.04.13 |
| SQL - SQL with Python (0) | 2026.04.13 |
| SQL - SQL Injection (0) | 2026.04.09 |
| SQL - PostgreSQL, Extensions (0) | 2026.04.06 |