We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
` import { relations } from "drizzle-orm" import { pgTable, serial, text, timestamp, unique, varchar, } from "drizzle-orm/pg-core"
const userTable = pgTable("users", { id: text("id").primaryKey(), name: text("name").notNull(), email: text("email").unique().notNull(), image: varchar("image").notNull(), bio: text("bio").default("").notNull(), website: varchar("website").default("").notNull(), username: varchar("username").unique().notNull(), })
const postTable = pgTable("posts", { id: serial("id").primaryKey(), content: text("content").notNull(), createdAt: timestamp("created_at").defaultNow().notNull(), userId: text("user_id") .notNull() .references(() => userTable.id), })
const likeTable = pgTable( "likes", { userId: text("user_id") .notNull() .references(() => userTable.id), postId: serial("post_id") .notNull() .references(() => postTable.id), createdAt: timestamp("created_at").defaultNow().notNull(), }, (table) => { return { unq: unique().on(table.userId, table.postId), } }, )
const usersRelations = relations(userTable, ({ many }) => ({ posts: many(postTable), likes: many(likeTable), }))
const postsRelations = relations(postTable, ({ one, many }) => ({ user: one(userTable, { fields: [postTable.userId], references: [userTable.id], }), likes: many(likeTable), }))
type Post = typeof postTable.$inferSelect & { user: User } type User = typeof userTable.$inferSelect & { posts: Post[] }
export { likeTable, postTable, postsRelations, userTable, usersRelations } export type { Post, User }
`
The text was updated successfully, but these errors were encountered:
No branches or pull requests
`
import { relations } from "drizzle-orm"
import {
pgTable,
serial,
text,
timestamp,
unique,
varchar,
} from "drizzle-orm/pg-core"
const userTable = pgTable("users", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").unique().notNull(),
image: varchar("image").notNull(),
bio: text("bio").default("").notNull(),
website: varchar("website").default("").notNull(),
username: varchar("username").unique().notNull(),
})
const postTable = pgTable("posts", {
id: serial("id").primaryKey(),
content: text("content").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
userId: text("user_id")
.notNull()
.references(() => userTable.id),
})
const likeTable = pgTable(
"likes",
{
userId: text("user_id")
.notNull()
.references(() => userTable.id),
postId: serial("post_id")
.notNull()
.references(() => postTable.id),
createdAt: timestamp("created_at").defaultNow().notNull(),
},
(table) => {
return {
unq: unique().on(table.userId, table.postId),
}
},
)
const usersRelations = relations(userTable, ({ many }) => ({
posts: many(postTable),
likes: many(likeTable),
}))
const postsRelations = relations(postTable, ({ one, many }) => ({
user: one(userTable, {
fields: [postTable.userId],
references: [userTable.id],
}),
likes: many(likeTable),
}))
type Post = typeof postTable.$inferSelect & {
user: User
}
type User = typeof userTable.$inferSelect & {
posts: Post[]
}
export { likeTable, postTable, postsRelations, userTable, usersRelations }
export type { Post, User }
`
The text was updated successfully, but these errors were encountered: