forked from drizzle-team/drizzle-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request drizzle-team#3879 from drizzle-team/beta
Beta
- Loading branch information
Showing
17 changed files
with
1,596 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# New features | ||
|
||
## Drizzle Relations support | ||
|
||
The `seed` function can now accept Drizzle Relations objects and treat them as foreign key constraints | ||
|
||
|
||
```ts | ||
// schema.ts | ||
import { integer, serial, text, pgTable } from 'drizzle-orm/pg-core'; | ||
import { relations } from 'drizzle-orm'; | ||
export const users = pgTable('users', { | ||
id: serial('id').primaryKey(), | ||
name: text('name').notNull(), | ||
}); | ||
export const usersRelations = relations(users, ({ many }) => ({ | ||
posts: many(posts), | ||
})); | ||
export const posts = pgTable('posts', { | ||
id: serial('id').primaryKey(), | ||
content: text('content').notNull(), | ||
authorId: integer('author_id').notNull(), | ||
}); | ||
export const postsRelations = relations(posts, ({ one }) => ({ | ||
author: one(users, { fields: [posts.authorId], references: [users.id] }), | ||
})); | ||
``` | ||
|
||
```ts | ||
// index.ts | ||
import { seed } from "drizzle-seed"; | ||
import * as schema from './schema.ts' | ||
|
||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, schema); | ||
} | ||
|
||
main(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.