mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add ?with=studios in movies & series
This commit is contained in:
parent
6cf8947c80
commit
750434465d
20
api/drizzle/0011_join_rename.sql
Normal file
20
api/drizzle/0011_join_rename.sql
Normal file
@ -0,0 +1,20 @@
|
||||
ALTER TABLE "kyoo"."show_studio_join" RENAME COLUMN "show" TO "show_pk";--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."show_studio_join" RENAME COLUMN "studio" TO "studio_pk";--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."entry_video_join" RENAME COLUMN "entry" TO "entry_pk";--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."entry_video_join" RENAME COLUMN "video" TO "video_pk";--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."show_studio_join" DROP CONSTRAINT "show_studio_join_show_shows_pk_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."show_studio_join" DROP CONSTRAINT "show_studio_join_studio_studios_pk_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."entry_video_join" DROP CONSTRAINT "entry_video_join_entry_entries_pk_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."entry_video_join" DROP CONSTRAINT "entry_video_join_video_videos_pk_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."show_studio_join" DROP CONSTRAINT "show_studio_join_show_studio_pk";--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."entry_video_join" DROP CONSTRAINT "entry_video_join_entry_video_pk";--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."show_studio_join" ADD CONSTRAINT "show_studio_join_show_pk_studio_pk_pk" PRIMARY KEY("show_pk","studio_pk");--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."entry_video_join" ADD CONSTRAINT "entry_video_join_entry_pk_video_pk_pk" PRIMARY KEY("entry_pk","video_pk");--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."show_studio_join" ADD CONSTRAINT "show_studio_join_show_pk_shows_pk_fk" FOREIGN KEY ("show_pk") REFERENCES "kyoo"."shows"("pk") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."show_studio_join" ADD CONSTRAINT "show_studio_join_studio_pk_studios_pk_fk" FOREIGN KEY ("studio_pk") REFERENCES "kyoo"."studios"("pk") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."entry_video_join" ADD CONSTRAINT "entry_video_join_entry_pk_entries_pk_fk" FOREIGN KEY ("entry_pk") REFERENCES "kyoo"."entries"("pk") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."entry_video_join" ADD CONSTRAINT "entry_video_join_video_pk_videos_pk_fk" FOREIGN KEY ("video_pk") REFERENCES "kyoo"."videos"("pk") ON DELETE cascade ON UPDATE no action;
|
1265
api/drizzle/meta/0011_snapshot.json
Normal file
1265
api/drizzle/meta/0011_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -78,6 +78,13 @@
|
||||
"when": 1740950531468,
|
||||
"tag": "0010_studios",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 11,
|
||||
"version": "7",
|
||||
"when": 1741014917375,
|
||||
"tag": "0011_join_rename",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -141,8 +141,8 @@ export const insertEntries = async (
|
||||
.select(
|
||||
db
|
||||
.select({
|
||||
entry: sql<number>`vids.entryPk::integer`.as("entry"),
|
||||
video: sql`${videos.pk}`.as("video"),
|
||||
entryPk: sql<number>`vids.entryPk::integer`.as("entry"),
|
||||
videoPk: sql`${videos.pk}`.as("video"),
|
||||
slug: computeVideoSlug(
|
||||
sql`${show.slug}::text`,
|
||||
sql`vids.needRendering::boolean`,
|
||||
@ -154,7 +154,7 @@ export const insertEntries = async (
|
||||
.onConflictDoNothing()
|
||||
.returning({
|
||||
slug: entryVideoJoin.slug,
|
||||
entryPk: entryVideoJoin.entry,
|
||||
entryPk: entryVideoJoin.entryPk,
|
||||
});
|
||||
|
||||
return retEntries.map((entry) => ({
|
||||
|
@ -48,7 +48,7 @@ export const insertStudios = async (seed: SeedStudio[], showPk: number) => {
|
||||
|
||||
await tx
|
||||
.insert(showStudioJoin)
|
||||
.values(ret.map((studio) => ({ show: showPk, studio: studio.pk })))
|
||||
.values(ret.map((studio) => ({ showPk: showPk, studioPk: studio.pk })))
|
||||
.onConflictDoNothing();
|
||||
return ret;
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { StaticDecode } from "@sinclair/typebox";
|
||||
import { type SQL, and, eq, sql } from "drizzle-orm";
|
||||
import { db } from "~/db";
|
||||
import { showTranslations, shows } from "~/db/schema";
|
||||
import { showTranslations, shows, studioTranslations } from "~/db/schema";
|
||||
import { getColumns, sqlarr } from "~/db/utils";
|
||||
import type { MovieStatus } from "~/models/movie";
|
||||
import { SerieStatus } from "~/models/serie";
|
||||
@ -12,6 +12,7 @@ import {
|
||||
Sort,
|
||||
isUuid,
|
||||
keysetPaginate,
|
||||
selectTranslationQuery,
|
||||
sortToSql,
|
||||
} from "~/models/utils";
|
||||
|
||||
@ -130,7 +131,7 @@ export async function getShow(
|
||||
}: {
|
||||
languages: string[];
|
||||
preferOriginal: boolean | undefined;
|
||||
relations: ("translations" | "videos")[];
|
||||
relations: ("translations" | "studios" | "videos")[];
|
||||
filters: SQL | undefined;
|
||||
},
|
||||
) {
|
||||
@ -141,18 +142,7 @@ export async function getShow(
|
||||
},
|
||||
where: and(isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id), filters),
|
||||
with: {
|
||||
selectedTranslation: {
|
||||
columns: {
|
||||
pk: false,
|
||||
},
|
||||
where: !languages.includes("*")
|
||||
? eq(showTranslations.language, sql`any(${sqlarr(languages)})`)
|
||||
: undefined,
|
||||
orderBy: [
|
||||
sql`array_position(${sqlarr(languages)}, ${showTranslations.language})`,
|
||||
],
|
||||
limit: 1,
|
||||
},
|
||||
selectedTranslation: selectTranslationQuery(showTranslations, languages),
|
||||
originalTranslation: {
|
||||
columns: {
|
||||
poster: true,
|
||||
@ -175,6 +165,23 @@ export async function getShow(
|
||||
},
|
||||
},
|
||||
}),
|
||||
...(relations.includes("studios") && {
|
||||
studios: {
|
||||
with: {
|
||||
studio: {
|
||||
columns: {
|
||||
pk: false,
|
||||
},
|
||||
with: {
|
||||
selectedTranslation: selectTranslationQuery(
|
||||
studioTranslations,
|
||||
languages,
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
if (!ret) return null;
|
||||
@ -198,6 +205,12 @@ export async function getShow(
|
||||
),
|
||||
),
|
||||
}),
|
||||
...(ret.studios && {
|
||||
studios: ret.studios.map((x: any) => ({
|
||||
...x.studio,
|
||||
...x.studio.selectedTranslation[0],
|
||||
})),
|
||||
}),
|
||||
};
|
||||
return { show, language: translation.language };
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
preferOriginal: t.Optional(
|
||||
t.Boolean({ description: desc.preferOriginal }),
|
||||
),
|
||||
with: t.Array(t.UnionEnum(["translations", "videos"]), {
|
||||
with: t.Array(t.UnionEnum(["translations", "studios", "videos"]), {
|
||||
default: [],
|
||||
description: "Include related resources in the response.",
|
||||
}),
|
||||
|
@ -65,7 +65,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
||||
preferOriginal: t.Optional(
|
||||
t.Boolean({ description: desc.preferOriginal }),
|
||||
),
|
||||
with: t.Array(t.UnionEnum(["translations"]), {
|
||||
with: t.Array(t.UnionEnum(["translations", "studios"]), {
|
||||
default: [],
|
||||
description: "Include related resources in the response.",
|
||||
}),
|
||||
|
@ -22,6 +22,7 @@ import {
|
||||
isUuid,
|
||||
keysetPaginate,
|
||||
processLanguages,
|
||||
selectTranslationQuery,
|
||||
sortToSql,
|
||||
} from "~/models/utils";
|
||||
import { desc } from "~/models/utils/descriptions";
|
||||
@ -47,16 +48,10 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
|
||||
const ret = await db.query.studios.findFirst({
|
||||
where: isUuid(id) ? eq(studios.id, id) : eq(studios.slug, id),
|
||||
with: {
|
||||
selectedTranslation: {
|
||||
columns: { pk: false },
|
||||
where: !languages.includes("*")
|
||||
? eq(studioTranslations.language, sql`any(${sqlarr(langs)})`)
|
||||
: undefined,
|
||||
orderBy: [
|
||||
sql`array_position(${sqlarr(langs)}, ${studioTranslations.language})`,
|
||||
],
|
||||
limit: 1,
|
||||
},
|
||||
selectedTranslation: selectTranslationQuery(
|
||||
studioTranslations,
|
||||
langs,
|
||||
),
|
||||
...(relations.includes("translations") && {
|
||||
translations: {
|
||||
columns: {
|
||||
@ -150,7 +145,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
|
||||
.get(
|
||||
"",
|
||||
async ({
|
||||
query: { limit, after, query, sort, filter },
|
||||
query: { limit, after, query, sort },
|
||||
headers: { "accept-language": languages },
|
||||
request: { url },
|
||||
}) => {
|
||||
@ -271,8 +266,8 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
|
||||
.from(showStudioJoin)
|
||||
.where(
|
||||
and(
|
||||
eq(showStudioJoin.studio, studio.pk),
|
||||
eq(showStudioJoin.show, shows.pk),
|
||||
eq(showStudioJoin.studioPk, studio.pk),
|
||||
eq(showStudioJoin.showPk, shows.pk),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -331,8 +326,8 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
|
||||
.from(showStudioJoin)
|
||||
.where(
|
||||
and(
|
||||
eq(showStudioJoin.studio, studio.pk),
|
||||
eq(showStudioJoin.show, shows.pk),
|
||||
eq(showStudioJoin.studioPk, studio.pk),
|
||||
eq(showStudioJoin.showPk, shows.pk),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -391,8 +386,8 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
|
||||
.from(showStudioJoin)
|
||||
.where(
|
||||
and(
|
||||
eq(showStudioJoin.studio, studio.pk),
|
||||
eq(showStudioJoin.show, shows.pk),
|
||||
eq(showStudioJoin.studioPk, studio.pk),
|
||||
eq(showStudioJoin.showPk, shows.pk),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -42,78 +42,77 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
return error(201, oldRet);
|
||||
|
||||
// TODO: this is a huge untested wip
|
||||
// biome-ignore lint/correctness/noUnreachable: leave me alone
|
||||
const vidsI = db.$with("vidsI").as(
|
||||
db.insert(videos).values(body).onConflictDoNothing().returning({
|
||||
pk: videos.pk,
|
||||
id: videos.id,
|
||||
path: videos.path,
|
||||
guess: videos.guess,
|
||||
}),
|
||||
);
|
||||
|
||||
const findEntriesQ = db
|
||||
.select({
|
||||
guess: videos.guess,
|
||||
entryPk: entries.pk,
|
||||
showSlug: shows.slug,
|
||||
// TODO: handle extras here
|
||||
// guessit can't know if an episode is a special or not. treat specials like a normal episode.
|
||||
kind: sql`
|
||||
case when ${entries.kind} = 'movie' then 'movie' else 'episode' end
|
||||
`.as("kind"),
|
||||
season: entries.seasonNumber,
|
||||
episode: entries.episodeNumber,
|
||||
})
|
||||
.from(entries)
|
||||
.leftJoin(entryVideoJoin, eq(entryVideoJoin.entry, entries.pk))
|
||||
.leftJoin(videos, eq(videos.pk, entryVideoJoin.video))
|
||||
.leftJoin(shows, eq(shows.pk, entries.showPk))
|
||||
.as("find_entries");
|
||||
|
||||
const hasRenderingQ = db
|
||||
.select()
|
||||
.from(entryVideoJoin)
|
||||
.where(eq(entryVideoJoin.entry, findEntriesQ.entryPk));
|
||||
|
||||
const ret = await db
|
||||
.with(vidsI)
|
||||
.insert(entryVideoJoin)
|
||||
.select(
|
||||
db
|
||||
.select({
|
||||
entry: findEntriesQ.entryPk,
|
||||
video: vidsI.pk,
|
||||
slug: computeVideoSlug(
|
||||
findEntriesQ.showSlug,
|
||||
sql`exists(${hasRenderingQ})`,
|
||||
),
|
||||
})
|
||||
.from(vidsI)
|
||||
.leftJoin(
|
||||
findEntriesQ,
|
||||
and(
|
||||
eq(
|
||||
sql`${findEntriesQ.guess}->'title'`,
|
||||
sql`${vidsI.guess}->'title'`,
|
||||
),
|
||||
// TODO: find if @> with a jsonb created on the fly is
|
||||
// better than multiples checks
|
||||
sql`${vidsI.guess} @> {"kind": }::jsonb`,
|
||||
inArray(findEntriesQ.kind, sql`${vidsI.guess}->'type'`),
|
||||
inArray(findEntriesQ.episode, sql`${vidsI.guess}->'episode'`),
|
||||
inArray(findEntriesQ.season, sql`${vidsI.guess}->'season'`),
|
||||
),
|
||||
),
|
||||
)
|
||||
.onConflictDoNothing()
|
||||
.returning({
|
||||
slug: entryVideoJoin.slug,
|
||||
entryPk: entryVideoJoin.entry,
|
||||
id: vidsI.id,
|
||||
path: vidsI.path,
|
||||
});
|
||||
return error(201, ret as any);
|
||||
// const vidsI = db.$with("vidsI").as(
|
||||
// db.insert(videos).values(body).onConflictDoNothing().returning({
|
||||
// pk: videos.pk,
|
||||
// id: videos.id,
|
||||
// path: videos.path,
|
||||
// guess: videos.guess,
|
||||
// }),
|
||||
// );
|
||||
//
|
||||
// const findEntriesQ = db
|
||||
// .select({
|
||||
// guess: videos.guess,
|
||||
// entryPk: entries.pk,
|
||||
// showSlug: shows.slug,
|
||||
// // TODO: handle extras here
|
||||
// // guessit can't know if an episode is a special or not. treat specials like a normal episode.
|
||||
// kind: sql`
|
||||
// case when ${entries.kind} = 'movie' then 'movie' else 'episode' end
|
||||
// `.as("kind"),
|
||||
// season: entries.seasonNumber,
|
||||
// episode: entries.episodeNumber,
|
||||
// })
|
||||
// .from(entries)
|
||||
// .leftJoin(entryVideoJoin, eq(entryVideoJoin.entry, entries.pk))
|
||||
// .leftJoin(videos, eq(videos.pk, entryVideoJoin.video))
|
||||
// .leftJoin(shows, eq(shows.pk, entries.showPk))
|
||||
// .as("find_entries");
|
||||
//
|
||||
// const hasRenderingQ = db
|
||||
// .select()
|
||||
// .from(entryVideoJoin)
|
||||
// .where(eq(entryVideoJoin.entry, findEntriesQ.entryPk));
|
||||
//
|
||||
// const ret = await db
|
||||
// .with(vidsI)
|
||||
// .insert(entryVideoJoin)
|
||||
// .select(
|
||||
// db
|
||||
// .select({
|
||||
// entry: findEntriesQ.entryPk,
|
||||
// video: vidsI.pk,
|
||||
// slug: computeVideoSlug(
|
||||
// findEntriesQ.showSlug,
|
||||
// sql`exists(${hasRenderingQ})`,
|
||||
// ),
|
||||
// })
|
||||
// .from(vidsI)
|
||||
// .leftJoin(
|
||||
// findEntriesQ,
|
||||
// and(
|
||||
// eq(
|
||||
// sql`${findEntriesQ.guess}->'title'`,
|
||||
// sql`${vidsI.guess}->'title'`,
|
||||
// ),
|
||||
// // TODO: find if @> with a jsonb created on the fly is
|
||||
// // better than multiples checks
|
||||
// sql`${vidsI.guess} @> {"kind": }::jsonb`,
|
||||
// inArray(findEntriesQ.kind, sql`${vidsI.guess}->'type'`),
|
||||
// inArray(findEntriesQ.episode, sql`${vidsI.guess}->'episode'`),
|
||||
// inArray(findEntriesQ.season, sql`${vidsI.guess}->'season'`),
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// .onConflictDoNothing()
|
||||
// .returning({
|
||||
// slug: entryVideoJoin.slug,
|
||||
// entryPk: entryVideoJoin.entry,
|
||||
// id: vidsI.id,
|
||||
// path: vidsI.path,
|
||||
// });
|
||||
// return error(201, ret as any);
|
||||
},
|
||||
{
|
||||
body: t.Array(SeedVideo),
|
||||
|
@ -5,7 +5,6 @@ import {
|
||||
date,
|
||||
index,
|
||||
integer,
|
||||
jsonb,
|
||||
primaryKey,
|
||||
smallint,
|
||||
text,
|
||||
@ -15,7 +14,8 @@ import {
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { entries } from "./entries";
|
||||
import { seasons } from "./seasons";
|
||||
import { image, language, schema } from "./utils";
|
||||
import { showStudioJoin } from "./studios";
|
||||
import { externalid, image, language, schema } from "./utils";
|
||||
|
||||
export const showKind = schema.enum("show_kind", [
|
||||
"serie",
|
||||
@ -54,20 +54,6 @@ export const genres = schema.enum("genres", [
|
||||
"talk",
|
||||
]);
|
||||
|
||||
export const externalid = () =>
|
||||
jsonb()
|
||||
.$type<
|
||||
Record<
|
||||
string,
|
||||
{
|
||||
dataId: string;
|
||||
link: string | null;
|
||||
}
|
||||
>
|
||||
>()
|
||||
.notNull()
|
||||
.default({});
|
||||
|
||||
export const shows = schema.table(
|
||||
"shows",
|
||||
{
|
||||
@ -144,6 +130,7 @@ export const showsRelations = relations(shows, ({ many, one }) => ({
|
||||
}),
|
||||
entries: many(entries, { relationName: "show_entries" }),
|
||||
seasons: many(seasons, { relationName: "show_seasons" }),
|
||||
studios: many(showStudioJoin, { relationName: "ssj_show" }),
|
||||
}));
|
||||
export const showsTrRelations = relations(showTranslations, ({ one }) => ({
|
||||
show: one(shows, {
|
||||
|
@ -8,8 +8,8 @@ import {
|
||||
uuid,
|
||||
varchar,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { externalid, shows } from "./shows";
|
||||
import { image, language, schema } from "./utils";
|
||||
import { shows } from "./shows";
|
||||
import { externalid, image, language, schema } from "./utils";
|
||||
|
||||
export const studios = schema.table("studios", {
|
||||
pk: integer().primaryKey().generatedAlwaysAsIdentity(),
|
||||
@ -44,14 +44,14 @@ export const studioTranslations = schema.table(
|
||||
export const showStudioJoin = schema.table(
|
||||
"show_studio_join",
|
||||
{
|
||||
show: integer()
|
||||
showPk: integer()
|
||||
.notNull()
|
||||
.references(() => shows.pk, { onDelete: "cascade" }),
|
||||
studio: integer()
|
||||
studioPk: integer()
|
||||
.notNull()
|
||||
.references(() => studios.pk, { onDelete: "cascade" }),
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.show, t.studio] })],
|
||||
(t) => [primaryKey({ columns: [t.showPk, t.studioPk] })],
|
||||
);
|
||||
|
||||
export const studioRelations = relations(studios, ({ many }) => ({
|
||||
@ -61,7 +61,7 @@ export const studioRelations = relations(studios, ({ many }) => ({
|
||||
selectedTranslation: many(studioTranslations, {
|
||||
relationName: "studio_selected_translation",
|
||||
}),
|
||||
showsJoin: many(showStudioJoin, { relationName: "show_studios" }),
|
||||
showsJoin: many(showStudioJoin, { relationName: "ssj_studio" }),
|
||||
}));
|
||||
export const studioTrRelations = relations(studioTranslations, ({ one }) => ({
|
||||
studio: one(studios, {
|
||||
@ -78,12 +78,12 @@ export const studioTrRelations = relations(studioTranslations, ({ one }) => ({
|
||||
export const ssjRelations = relations(showStudioJoin, ({ one }) => ({
|
||||
show: one(shows, {
|
||||
relationName: "ssj_show",
|
||||
fields: [showStudioJoin.show],
|
||||
fields: [showStudioJoin.showPk],
|
||||
references: [shows.pk],
|
||||
}),
|
||||
studio: one(studios, {
|
||||
relationName: "ssj_studio",
|
||||
fields: [showStudioJoin.studio],
|
||||
fields: [showStudioJoin.studioPk],
|
||||
references: [studios.pk],
|
||||
}),
|
||||
}));
|
||||
|
@ -6,3 +6,18 @@ export const language = () => varchar({ length: 255 });
|
||||
|
||||
export const image = () =>
|
||||
jsonb().$type<{ id: string; source: string; blurhash: string }>();
|
||||
|
||||
export const externalid = () =>
|
||||
jsonb()
|
||||
.$type<
|
||||
Record<
|
||||
string,
|
||||
{
|
||||
dataId: string;
|
||||
link: string | null;
|
||||
}
|
||||
>
|
||||
>()
|
||||
.notNull()
|
||||
.default({});
|
||||
|
||||
|
@ -39,15 +39,15 @@ export const videos = schema.table(
|
||||
export const entryVideoJoin = schema.table(
|
||||
"entry_video_join",
|
||||
{
|
||||
entry: integer()
|
||||
entryPk: integer()
|
||||
.notNull()
|
||||
.references(() => entries.pk, { onDelete: "cascade" }),
|
||||
video: integer()
|
||||
videoPk: integer()
|
||||
.notNull()
|
||||
.references(() => videos.pk, { onDelete: "cascade" }),
|
||||
slug: varchar({ length: 255 }).notNull().unique(),
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.entry, t.video] })],
|
||||
(t) => [primaryKey({ columns: [t.entryPk, t.videoPk] })],
|
||||
);
|
||||
|
||||
export const videosRelations = relations(videos, ({ many }) => ({
|
||||
@ -59,12 +59,12 @@ export const videosRelations = relations(videos, ({ many }) => ({
|
||||
export const evjRelations = relations(entryVideoJoin, ({ one }) => ({
|
||||
video: one(videos, {
|
||||
relationName: "evj_video",
|
||||
fields: [entryVideoJoin.video],
|
||||
fields: [entryVideoJoin.videoPk],
|
||||
references: [videos.pk],
|
||||
}),
|
||||
entry: one(entries, {
|
||||
relationName: "evj_entry",
|
||||
fields: [entryVideoJoin.entry],
|
||||
fields: [entryVideoJoin.entryPk],
|
||||
references: [entries.pk],
|
||||
}),
|
||||
}));
|
||||
|
@ -2,7 +2,7 @@ import { t } from "elysia";
|
||||
import type { Prettify } from "~/utils";
|
||||
import { SeedCollection } from "./collections";
|
||||
import { bubble, bubbleImages, registerExamples } from "./examples";
|
||||
import { SeedStudio } from "./studio";
|
||||
import { SeedStudio, Studio } from "./studio";
|
||||
import {
|
||||
DbMetadata,
|
||||
ExternalId,
|
||||
@ -68,6 +68,7 @@ export const FullMovie = t.Intersect([
|
||||
t.Object({
|
||||
translations: t.Optional(TranslationRecord(MovieTranslation)),
|
||||
videos: t.Optional(t.Array(Video)),
|
||||
studios: t.Optional(t.Array(Studio)),
|
||||
}),
|
||||
]);
|
||||
export type FullMovie = Prettify<typeof FullMovie.static>;
|
||||
|
@ -4,7 +4,7 @@ import { SeedCollection } from "./collections";
|
||||
import { SeedEntry, SeedExtra } from "./entry";
|
||||
import { bubbleImages, madeInAbyss, registerExamples } from "./examples";
|
||||
import { SeedSeason } from "./season";
|
||||
import { SeedStudio } from "./studio";
|
||||
import { SeedStudio, Studio } from "./studio";
|
||||
import {
|
||||
DbMetadata,
|
||||
ExternalId,
|
||||
@ -76,6 +76,7 @@ export const FullSerie = t.Intersect([
|
||||
Serie,
|
||||
t.Object({
|
||||
translations: t.Optional(TranslationRecord(SerieTranslation)),
|
||||
studios: t.Optional(t.Array(Studio)),
|
||||
}),
|
||||
]);
|
||||
export type FullMovie = Prettify<typeof FullSerie.static>;
|
||||
|
@ -4,7 +4,9 @@ import {
|
||||
type TSchema,
|
||||
type TString,
|
||||
} from "@sinclair/typebox";
|
||||
import { type Column, type Table, eq, sql } from "drizzle-orm";
|
||||
import { t } from "elysia";
|
||||
import { sqlarr } from "~/db/utils";
|
||||
import { comment } from "../../utils";
|
||||
import { KErrorT } from "../error";
|
||||
|
||||
@ -106,3 +108,19 @@ export const AcceptLanguage = ({
|
||||
`
|
||||
: ""),
|
||||
});
|
||||
|
||||
export const selectTranslationQuery = (
|
||||
translationTable: Table & { language: Column },
|
||||
languages: string[],
|
||||
) => ({
|
||||
columns: {
|
||||
pk: false,
|
||||
} as const,
|
||||
where: !languages.includes("*")
|
||||
? eq(translationTable.language, sql`any(${sqlarr(languages)})`)
|
||||
: undefined,
|
||||
orderBy: [
|
||||
sql`array_position(${sqlarr(languages)}, ${translationTable.language})`,
|
||||
],
|
||||
limit: 1,
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user