db: remove table suffix from schemas
This commit is contained in:
@@ -1,11 +1,5 @@
|
||||
import { desc, eq, like } from "drizzle-orm";
|
||||
import {
|
||||
animeSongLinksTable,
|
||||
animeTable,
|
||||
artistsTable,
|
||||
groupsTable,
|
||||
songsTable,
|
||||
} from "$lib/db/schema";
|
||||
import { anime, animeSongLinks, artists, groups, songs } from "$lib/db/schema";
|
||||
import type { ClientDb } from "./index";
|
||||
|
||||
/**
|
||||
@@ -31,18 +25,14 @@ export async function getAnimeList(db: ClientDb, limit = DEFAULT_LIST_LIMIT) {
|
||||
// Explicit selection keeps payload small and gives a stable, inferred return type
|
||||
return db
|
||||
.select({
|
||||
annId: animeTable.annId,
|
||||
mainName: animeTable.mainName,
|
||||
year: animeTable.year,
|
||||
seasonId: animeTable.seasonId,
|
||||
malId: animeTable.malId,
|
||||
annId: anime.annId,
|
||||
mainName: anime.mainName,
|
||||
year: anime.year,
|
||||
seasonId: anime.seasonId,
|
||||
malId: anime.malId,
|
||||
})
|
||||
.from(animeTable)
|
||||
.orderBy(
|
||||
desc(animeTable.year),
|
||||
desc(animeTable.seasonId),
|
||||
desc(animeTable.annId),
|
||||
)
|
||||
.from(anime)
|
||||
.orderBy(desc(anime.year), desc(anime.seasonId), desc(anime.annId))
|
||||
.limit(safeLimit);
|
||||
}
|
||||
|
||||
@@ -65,19 +55,15 @@ export async function searchAnimeByName(
|
||||
|
||||
return db
|
||||
.select({
|
||||
annId: animeTable.annId,
|
||||
mainName: animeTable.mainName,
|
||||
year: animeTable.year,
|
||||
seasonId: animeTable.seasonId,
|
||||
malId: animeTable.malId,
|
||||
annId: anime.annId,
|
||||
mainName: anime.mainName,
|
||||
year: anime.year,
|
||||
seasonId: anime.seasonId,
|
||||
malId: anime.malId,
|
||||
})
|
||||
.from(animeTable)
|
||||
.where(like(animeTable.mainName, pattern))
|
||||
.orderBy(
|
||||
desc(animeTable.year),
|
||||
desc(animeTable.seasonId),
|
||||
desc(animeTable.annId),
|
||||
)
|
||||
.from(anime)
|
||||
.where(like(anime.mainName, pattern))
|
||||
.orderBy(desc(anime.year), desc(anime.seasonId), desc(anime.annId))
|
||||
.limit(safeLimit);
|
||||
}
|
||||
|
||||
@@ -93,43 +79,37 @@ export async function searchAnimeByName(
|
||||
export async function getAnimeWithSongsByAnnId(db: ClientDb, annId: number) {
|
||||
const animeRows = await db
|
||||
.select({
|
||||
annId: animeTable.annId,
|
||||
mainName: animeTable.mainName,
|
||||
year: animeTable.year,
|
||||
seasonId: animeTable.seasonId,
|
||||
malId: animeTable.malId,
|
||||
annId: anime.annId,
|
||||
mainName: anime.mainName,
|
||||
year: anime.year,
|
||||
seasonId: anime.seasonId,
|
||||
malId: anime.malId,
|
||||
})
|
||||
.from(animeTable)
|
||||
.where(eq(animeTable.annId, annId))
|
||||
.from(anime)
|
||||
.where(eq(anime.annId, annId))
|
||||
.limit(1);
|
||||
|
||||
const anime = animeRows[0];
|
||||
if (!anime) return null;
|
||||
const foundAnime = animeRows[0];
|
||||
if (!foundAnime) return null;
|
||||
|
||||
const rows = await db
|
||||
.select({
|
||||
annSongId: animeSongLinksTable.annSongId,
|
||||
type: animeSongLinksTable.type,
|
||||
number: animeSongLinksTable.number,
|
||||
annSongId: animeSongLinks.annSongId,
|
||||
type: animeSongLinks.type,
|
||||
number: animeSongLinks.number,
|
||||
|
||||
songName: songsTable.name,
|
||||
fileName: songsTable.fileName,
|
||||
songName: songs.name,
|
||||
fileName: songs.fileName,
|
||||
|
||||
artistName: artistsTable.name,
|
||||
groupName: groupsTable.name,
|
||||
artistName: artists.name,
|
||||
groupName: groups.name,
|
||||
})
|
||||
.from(animeSongLinksTable)
|
||||
.innerJoin(
|
||||
songsTable,
|
||||
eq(songsTable.annSongId, animeSongLinksTable.annSongId),
|
||||
)
|
||||
.leftJoin(
|
||||
artistsTable,
|
||||
eq(artistsTable.songArtistId, songsTable.songArtistId),
|
||||
)
|
||||
.leftJoin(groupsTable, eq(groupsTable.songGroupId, songsTable.songGroupId))
|
||||
.where(eq(animeSongLinksTable.annId, annId))
|
||||
.orderBy(desc(animeSongLinksTable.type), desc(animeSongLinksTable.number));
|
||||
.from(animeSongLinks)
|
||||
.innerJoin(songs, eq(songs.annSongId, animeSongLinks.annSongId))
|
||||
.leftJoin(artists, eq(artists.songArtistId, songs.songArtistId))
|
||||
.leftJoin(groups, eq(groups.songGroupId, songs.songGroupId))
|
||||
.where(eq(animeSongLinks.annId, annId))
|
||||
.orderBy(desc(animeSongLinks.type), desc(animeSongLinks.number));
|
||||
|
||||
return {
|
||||
anime,
|
||||
|
||||
Reference in New Issue
Block a user