mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Define relations on evj
This commit is contained in:
parent
2588eef23b
commit
fabf6b6863
@ -1,6 +1,6 @@
|
||||
import { type SQL, and, eq, exists, sql } from "drizzle-orm";
|
||||
import { Elysia, t } from "elysia";
|
||||
import { entries, entryVideoJoint, showTranslations, shows } from "~/db/schema";
|
||||
import { entries, entryVideoJoin, showTranslations, shows } from "~/db/schema";
|
||||
import { getColumns, sqlarr } from "~/db/utils";
|
||||
import { KError } from "~/models/error";
|
||||
import { bubble } from "~/models/examples";
|
||||
@ -81,8 +81,8 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
exists(
|
||||
db
|
||||
.select()
|
||||
.from(entryVideoJoint)
|
||||
.where(eq(entries.pk, entryVideoJoint.entry)),
|
||||
.from(entryVideoJoin)
|
||||
.where(eq(entries.pk, entryVideoJoin.entry)),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -258,8 +258,8 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
exists(
|
||||
db
|
||||
.select()
|
||||
.from(entryVideoJoint)
|
||||
.where(eq(entries.pk, entryVideoJoint.entry)),
|
||||
.from(entryVideoJoin)
|
||||
.where(eq(entries.pk, entryVideoJoin.entry)),
|
||||
),
|
||||
)
|
||||
.as("video");
|
||||
|
@ -3,7 +3,7 @@ import { db } from "~/db";
|
||||
import {
|
||||
entries,
|
||||
entryTranslations,
|
||||
entryVideoJoint as entryVideoJoin,
|
||||
entryVideoJoin,
|
||||
videos,
|
||||
} from "~/db/schema";
|
||||
import { conflictUpdateAllExcept, values } from "~/db/utils";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import {
|
||||
check,
|
||||
date,
|
||||
@ -14,6 +14,7 @@ import {
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { shows } from "./shows";
|
||||
import { image, language, schema } from "./utils";
|
||||
import { entryVideoJoin } from "./videos";
|
||||
|
||||
export const entryType = schema.enum("entry_type", [
|
||||
"unknown",
|
||||
@ -92,3 +93,16 @@ export const entryTranslations = schema.table(
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.pk, t.language] })],
|
||||
);
|
||||
|
||||
export const entryRelations = relations(entries, ({ many }) => ({
|
||||
translations: many(entryTranslations, { relationName: "entryTranslations" }),
|
||||
evj: many(entryVideoJoin, { relationName: "evj_entry" }),
|
||||
}));
|
||||
|
||||
export const entryTrRelations = relations(entryTranslations, ({ one }) => ({
|
||||
entry: one(entries, {
|
||||
relationName: "entryTranslations",
|
||||
fields: [entryTranslations.pk],
|
||||
references: [entries.pk],
|
||||
}),
|
||||
}));
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import {
|
||||
check,
|
||||
integer,
|
||||
@ -33,7 +33,7 @@ export const videos = schema.table(
|
||||
],
|
||||
);
|
||||
|
||||
export const entryVideoJoint = schema.table(
|
||||
export const entryVideoJoin = schema.table(
|
||||
"entry_video_jointure",
|
||||
{
|
||||
entry: integer()
|
||||
@ -46,3 +46,22 @@ export const entryVideoJoint = schema.table(
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.entry, t.video] })],
|
||||
);
|
||||
|
||||
export const videosRelations = relations(videos, ({ many }) => ({
|
||||
evj: many(entryVideoJoin, {
|
||||
relationName: "evj_video",
|
||||
}),
|
||||
}));
|
||||
|
||||
export const evjRelations = relations(entryVideoJoin, ({ one }) => ({
|
||||
video: one(videos, {
|
||||
relationName: "evj_video",
|
||||
fields: [entryVideoJoin.video],
|
||||
references: [videos.pk],
|
||||
}),
|
||||
entry: one(entries, {
|
||||
relationName: "evj_entry",
|
||||
fields: [entryVideoJoin.entry],
|
||||
references: [entries.pk],
|
||||
}),
|
||||
}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user