mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-01 20:54:13 -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 { type SQL, and, eq, exists, sql } from "drizzle-orm";
|
||||||
import { Elysia, t } from "elysia";
|
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 { getColumns, sqlarr } from "~/db/utils";
|
||||||
import { KError } from "~/models/error";
|
import { KError } from "~/models/error";
|
||||||
import { bubble } from "~/models/examples";
|
import { bubble } from "~/models/examples";
|
||||||
@ -81,8 +81,8 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
exists(
|
exists(
|
||||||
db
|
db
|
||||||
.select()
|
.select()
|
||||||
.from(entryVideoJoint)
|
.from(entryVideoJoin)
|
||||||
.where(eq(entries.pk, entryVideoJoint.entry)),
|
.where(eq(entries.pk, entryVideoJoin.entry)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -258,8 +258,8 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
exists(
|
exists(
|
||||||
db
|
db
|
||||||
.select()
|
.select()
|
||||||
.from(entryVideoJoint)
|
.from(entryVideoJoin)
|
||||||
.where(eq(entries.pk, entryVideoJoint.entry)),
|
.where(eq(entries.pk, entryVideoJoin.entry)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.as("video");
|
.as("video");
|
||||||
|
@ -3,7 +3,7 @@ import { db } from "~/db";
|
|||||||
import {
|
import {
|
||||||
entries,
|
entries,
|
||||||
entryTranslations,
|
entryTranslations,
|
||||||
entryVideoJoint as entryVideoJoin,
|
entryVideoJoin,
|
||||||
videos,
|
videos,
|
||||||
} from "~/db/schema";
|
} from "~/db/schema";
|
||||||
import { conflictUpdateAllExcept, values } from "~/db/utils";
|
import { conflictUpdateAllExcept, values } from "~/db/utils";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { sql } from "drizzle-orm";
|
import { relations, sql } from "drizzle-orm";
|
||||||
import {
|
import {
|
||||||
check,
|
check,
|
||||||
date,
|
date,
|
||||||
@ -14,6 +14,7 @@ import {
|
|||||||
} from "drizzle-orm/pg-core";
|
} from "drizzle-orm/pg-core";
|
||||||
import { shows } from "./shows";
|
import { shows } from "./shows";
|
||||||
import { image, language, schema } from "./utils";
|
import { image, language, schema } from "./utils";
|
||||||
|
import { entryVideoJoin } from "./videos";
|
||||||
|
|
||||||
export const entryType = schema.enum("entry_type", [
|
export const entryType = schema.enum("entry_type", [
|
||||||
"unknown",
|
"unknown",
|
||||||
@ -92,3 +93,16 @@ export const entryTranslations = schema.table(
|
|||||||
},
|
},
|
||||||
(t) => [primaryKey({ columns: [t.pk, t.language] })],
|
(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 {
|
import {
|
||||||
check,
|
check,
|
||||||
integer,
|
integer,
|
||||||
@ -33,7 +33,7 @@ export const videos = schema.table(
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
export const entryVideoJoint = schema.table(
|
export const entryVideoJoin = schema.table(
|
||||||
"entry_video_jointure",
|
"entry_video_jointure",
|
||||||
{
|
{
|
||||||
entry: integer()
|
entry: integer()
|
||||||
@ -46,3 +46,22 @@ export const entryVideoJoint = schema.table(
|
|||||||
},
|
},
|
||||||
(t) => [primaryKey({ columns: [t.entry, t.video] })],
|
(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