-
Notifications
You must be signed in to change notification settings - Fork 2
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 #1 from BriefHQ/relationships
Relationships
- Loading branch information
Showing
29 changed files
with
1,845 additions
and
509 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 |
---|---|---|
@@ -1,20 +1,39 @@ | ||
import { pgTable, text } from "drizzle-orm/pg-core"; | ||
import { boolean } from "drizzle-orm/pg-core"; | ||
import { relations } from "drizzle-orm"; | ||
import { boolean, pgTable, text } from "drizzle-orm/pg-core"; | ||
|
||
export const user = pgTable("user", { | ||
export const userTable = pgTable("user", { | ||
id: text("id").primaryKey(), | ||
name: text("name").notNull(), | ||
partner: boolean("partner").notNull(), | ||
}); | ||
|
||
export const medium = pgTable("medium", { | ||
export const userRelations = relations(userTable, ({ many }) => ({ | ||
messages: many(messageTable), | ||
})); | ||
|
||
export const mediumTable = pgTable("medium", { | ||
id: text("id").primaryKey(), | ||
name: text("name").notNull(), | ||
}); | ||
|
||
export const message = pgTable("message", { | ||
export const mediumRelations = relations(mediumTable, ({ many }) => ({ | ||
messages: many(messageTable), | ||
})); | ||
|
||
export const messageTable = pgTable("message", { | ||
id: text("id").primaryKey(), | ||
senderId: text("senderId").references(() => user.id), | ||
mediumId: text("mediumId").references(() => medium.id), | ||
senderId: text("senderId").references(() => userTable.id), | ||
mediumId: text("mediumId").references(() => mediumTable.id), | ||
body: text("body").notNull(), | ||
}); | ||
|
||
export const messageRelations = relations(messageTable, ({ one }) => ({ | ||
medium: one(mediumTable, { | ||
fields: [messageTable.mediumId], | ||
references: [mediumTable.id], | ||
}), | ||
sender: one(userTable, { | ||
fields: [messageTable.senderId], | ||
references: [userTable.id], | ||
}), | ||
})); |
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
Oops, something went wrong.