Skip to content

Commit

Permalink
sql index 貼り
Browse files Browse the repository at this point in the history
  • Loading branch information
a01sa01to committed Mar 23, 2024
1 parent 9247f84 commit 413e1de
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 152 deletions.
44 changes: 25 additions & 19 deletions workspaces/schema/src/models/author.ts
@@ -1,26 +1,32 @@
/* eslint-disable sort/object-properties */
import { randomUUID } from 'node:crypto';

import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { index, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const author = sqliteTable('author', {
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),
export const author = sqliteTable(
'author',
{
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),

// columns
name: text('name').notNull(),
description: text('description').notNull(),
// columns
name: text('name').notNull(),
description: text('description').notNull(),

// relations
imageId: text('image_id').notNull(),
// relations
imageId: text('image_id').notNull(),

// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
});
// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
},
(table) => ({
createdAtIdx: index('created_at_idx').on(table.createdAt),
}),
);
50 changes: 28 additions & 22 deletions workspaces/schema/src/models/book.ts
@@ -1,29 +1,35 @@
/* eslint-disable sort/object-properties */
import { randomUUID } from 'node:crypto';

import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { index, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const book = sqliteTable('book', {
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),
export const book = sqliteTable(
'book',
{
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),

// columns
description: text('description').notNull(),
name: text('name').notNull(),
nameRuby: text('name_ruby').notNull(),
// columns
description: text('description').notNull(),
name: text('name').notNull(),
nameRuby: text('name_ruby').notNull(),

// relations
imageId: text('image_id').notNull(),
authorId: text('author_id').notNull(),
releaseId: text('release_id').notNull(),
// relations
imageId: text('image_id').notNull(),
authorId: text('author_id').notNull(),
releaseId: text('release_id').notNull(),

// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
});
// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
},
(table) => ({
createdAtIdx: index('created_at_idx').on(table.createdAt),
}),
);
50 changes: 28 additions & 22 deletions workspaces/schema/src/models/episode.ts
@@ -1,29 +1,35 @@
/* eslint-disable sort/object-properties */
import { randomUUID } from 'node:crypto';

import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const episode = sqliteTable('episode', {
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),
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(),
// 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(),
// 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()),
});
// 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),
}),
);
44 changes: 25 additions & 19 deletions workspaces/schema/src/models/episodePage.ts
@@ -1,26 +1,32 @@
/* eslint-disable sort/object-properties */
import { randomUUID } from 'node:crypto';

import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const episodePage = sqliteTable('episode_page', {
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),
export const episodePage = sqliteTable(
'episode_page',
{
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),

// columns
page: integer('page').notNull(),
// columns
page: integer('page').notNull(),

// relations
episodeId: text('episode_id').notNull(),
imageId: text('image_id').notNull(),
// relations
episodeId: text('episode_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()),
});
// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
},
(table) => ({
episodePageIdx: index('episode_page_idx').on(table.episodeId, table.page),
}),
);
36 changes: 20 additions & 16 deletions workspaces/schema/src/models/feature.ts
@@ -1,22 +1,26 @@
/* eslint-disable sort/object-properties */
import { randomUUID } from 'node:crypto';

import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { index, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const feature = sqliteTable('feature', {
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),
export const feature = sqliteTable(
'feature',
{
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),

// relations
bookId: text('book_id').notNull(),
// relations
bookId: text('book_id').notNull(),

// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
});
// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
},
(table) => ({ createdAtIdx: index('created_at_idx').on(table.createdAt) }),
);
40 changes: 22 additions & 18 deletions workspaces/schema/src/models/ranking.ts
@@ -1,25 +1,29 @@
/* eslint-disable sort/object-properties */
import { randomUUID } from 'node:crypto';

import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const ranking = sqliteTable('ranking', {
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),
export const ranking = sqliteTable(
'ranking',
{
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),

// columns
rank: integer('rank').notNull(),
// columns
rank: integer('rank').notNull(),

// relations
bookId: text('book_id').notNull(),
// relations
bookId: text('book_id').notNull(),

// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
});
// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
},
(table) => ({ rankIdx: index('rank_idx').on(table.rank) }),
);
38 changes: 22 additions & 16 deletions workspaces/schema/src/models/release.ts
@@ -1,22 +1,28 @@
/* eslint-disable sort/object-properties */
import { randomUUID } from 'node:crypto';

import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { index, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const release = sqliteTable('release', {
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),
export const release = sqliteTable(
'release',
{
// primary key
id: text('id')
.primaryKey()
.$defaultFn(() => randomUUID()),

// columns
dayOfWeek: text('day_of_week').notNull(),
// columns
dayOfWeek: text('day_of_week').notNull(),

// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
});
// metadata
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
},
(table) => ({
dayOfWeekIdx: index('day_of_week_idx').on(table.dayOfWeek),
}),
);

0 comments on commit 413e1de

Please sign in to comment.