33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { pgTable, serial, varchar, integer, pgEnum, primaryKey } from 'drizzle-orm/pg-core';
|
|
import { relations } from 'drizzle-orm';
|
|
|
|
//#region Enums
|
|
export const BookTypeEnum = pgEnum("book_type", ["novel", "fanfic"]);
|
|
export const LeadingGenderEnum = pgEnum("leading_gender", ["male", "female"]);
|
|
//#endregion Enums
|
|
|
|
//#region Genre
|
|
export const Genre = pgTable("genres", {
|
|
id: serial("id").primaryKey(),
|
|
name: varchar("name").notNull(),
|
|
description: varchar("description").notNull(),
|
|
});
|
|
export const GenreTranslation = pgTable("genre_translations", {
|
|
id: integer("id"),
|
|
locale: varchar("locale").notNull(),
|
|
name: varchar("name").notNull(),
|
|
description: varchar("description"),
|
|
}, (t) => ([
|
|
primaryKey({ columns: [t.id, t.locale] }),
|
|
]));
|
|
// Relations
|
|
export const GenreRelations = relations(Genre, ({ many }) => ({
|
|
translations: many(GenreTranslation)
|
|
}));
|
|
export const GenreTranslationRelations = relations(GenreTranslation, ({ one }) => ({
|
|
genre: one(Genre, {
|
|
fields: [GenreTranslation.id],
|
|
references: [Genre.id],
|
|
}),
|
|
}));
|
|
//#endregion Genre
|