forked from CyberAgentHack/web-speed-hackathon-2024
/
episode.ts
35 lines (30 loc) · 921 Bytes
/
episode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable sort/object-properties */
import { randomUUID } from 'node:crypto';
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
export const episode = sqliteTable(
'episode',
{
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),
// columns
name: text('name').notNull(),
nameRuby: text('name_ruby').notNull(),
description: text('description').notNull(),
chapter: integer('chapter').notNull(),
// relations
bookId: text('book_id').notNull(),
imageId: text('image_id').notNull(),
// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
},
(table) => ({
bookChapIdx: index('book_chap_idx').on(table.bookId, table.chapter),
}),
);