100 lines
2.2 KiB
TypeScript
100 lines
2.2 KiB
TypeScript
import { defineRelations } from 'drizzle-orm';
|
|
import * as schema from './schema';
|
|
|
|
export const relations = defineRelations(schema, (r) => ({
|
|
// ── Progress ──────────────────────────────────
|
|
tasks: {
|
|
tasksToTopics: r.many.tasksToTopics()
|
|
},
|
|
topics: {
|
|
topicsToTasks: r.many.tasksToTopics()
|
|
},
|
|
tasksToTopics: {
|
|
task: r.one.tasks({
|
|
from: r.tasksToTopics.taskId,
|
|
to: r.tasks.id
|
|
}),
|
|
topic: r.one.topics({
|
|
from: r.tasksToTopics.topicId,
|
|
to: r.topics.id
|
|
})
|
|
},
|
|
|
|
// ── CatchEmAll ────────────────────────────────
|
|
game: {
|
|
entries: r.many.pokemonGameEntry()
|
|
},
|
|
pokemon: {
|
|
entry: r.many.pokemonGameEntry()
|
|
},
|
|
pokemonGameEntry: {
|
|
game: r.one.game({
|
|
from: r.pokemonGameEntry.gameId,
|
|
to: r.game.id
|
|
}),
|
|
pokemon: r.one.pokemon({
|
|
from: r.pokemonGameEntry.pokemonId,
|
|
to: r.pokemon.id
|
|
}),
|
|
userEntries: r.many.userEntry()
|
|
},
|
|
userEntry: {
|
|
pokemonGameEntry: r.one.pokemonGameEntry({
|
|
from: r.userEntry.pokemonGameEntryId,
|
|
to: r.pokemonGameEntry.id
|
|
}),
|
|
user: r.one.user({
|
|
from: r.userEntry.userId,
|
|
to: r.user.id
|
|
})
|
|
},
|
|
userGame: {
|
|
user: r.one.user({
|
|
from: r.userGame.userId,
|
|
to: r.user.id
|
|
}),
|
|
game: r.one.game({
|
|
from: r.userGame.gameId,
|
|
to: r.game.id
|
|
})
|
|
},
|
|
|
|
// ── Auth ──────────────────────────────────────
|
|
user: {
|
|
sessions: r.many.session(),
|
|
accounts: r.many.account(),
|
|
entries: r.many.userEntry(),
|
|
games: r.many.userGame()
|
|
},
|
|
session: {
|
|
user: r.one.user({
|
|
from: r.session.userId,
|
|
to: r.user.id
|
|
})
|
|
},
|
|
account: {
|
|
user: r.one.user({
|
|
from: r.account.userId,
|
|
to: r.user.id
|
|
})
|
|
},
|
|
|
|
// ── Animaldex ─────────────────────────────────
|
|
animals: {
|
|
sightings: r.many.sightings()
|
|
},
|
|
sightings: {
|
|
animal: r.one.animals({
|
|
from: r.sightings.animalId,
|
|
to: r.animals.id
|
|
}),
|
|
photos: r.many.photos()
|
|
},
|
|
photos: {
|
|
sighting: r.one.sightings({
|
|
from: r.photos.sightingId,
|
|
to: r.sightings.id
|
|
})
|
|
}
|
|
}));
|