···11import { DATABASE_URL } from '$env/static/private'
22import { drizzle } from 'drizzle-orm/node-postgres'
33import * as authSchemas from './schemas/auth'
44-import * as dndSchemas from './schemas/dnd'
44+import * as dndCampaignSchemas from './schemas/dnd/campaign'
55+import * as dndCharacterSchemas from './schemas/dnd/character'
66+import * as dndClassSchemas from './schemas/dnd/class'
77+import * as dndEquipmentSchemas from './schemas/dnd/equipment'
88+import * as dndFactionSchemas from './schemas/dnd/faction'
99+import * as dndLanguageSchemas from './schemas/dnd/language'
1010+import * as dndConditionSchemas from './schemas/dnd/mechanic'
1111+import * as dndOriginSchemas from './schemas/dnd/origin'
1212+import * as dndSourcebookSchemas from './schemas/dnd/sourcebook'
1313+import * as dndSpellSchemas from './schemas/dnd/spell'
514615if (DATABASE_URL === '') throw new Error('DATABASE_URL is not set')
716817export const db = drizzle(DATABASE_URL, {
99- schema: { ...dndSchemas, ...authSchemas },
1818+ schema: {
1919+ ...dndCampaignSchemas,
2020+ ...dndCharacterSchemas,
2121+ ...dndClassSchemas,
2222+ ...dndConditionSchemas,
2323+ ...dndEquipmentSchemas,
2424+ ...dndFactionSchemas,
2525+ ...dndLanguageSchemas,
2626+ ...dndOriginSchemas,
2727+ ...dndSourcebookSchemas,
2828+ ...dndSpellSchemas,
2929+ ...authSchemas,
3030+ },
1031})
1132export type DatabaseConn = typeof db
+1-1
app/src/lib/server/db/repos/background.ts
···11import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33-import { background } from '../schemas/dnd'
33+import { background } from '../schemas/dnd/origin'
44import { selectColumns, querySingle, type TableColumnNames } from '../utils'
5566export type BackgroundTable = typeof background
+1-1
app/src/lib/server/db/repos/campaign-member.ts
···22import type { DatabaseConn } from '..'
33import type { Campaign } from './campaign'
44import { user } from '../schemas/auth'
55-import { campaignMember } from '../schemas/dnd'
55+import { campaignMember } from '../schemas/dnd/campaign'
6677export type CampaignMemberTable = typeof campaignMember
88export type CampaignMember = InferSelectModel<CampaignMemberTable>
+2-1
app/src/lib/server/db/repos/campaign.ts
···11import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import { user } from '../schemas/auth'
44-import { campaign, campaignSession, campaignSourceMaterial, sourceBook } from '../schemas/dnd'
44+import { campaign, campaignSession, campaignSourceMaterial } from '../schemas/dnd/campaign'
55+import { sourceBook } from '../schemas/dnd/sourcebook'
56import { querySingle, selectColumns, type TableColumnNames } from '../utils'
6778export type CampaignTable = typeof campaign
···11import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33-import type { User, UserId } from './auth'
33+import type { UserId } from './auth'
44import { user } from '../schemas/auth'
55-import { character, background, species } from '../schemas/dnd'
55+import { character, characterLanguage } from '../schemas/dnd/character'
66+import { language } from '../schemas/dnd/language'
77+import { background, species } from '../schemas/dnd/origin'
68import { querySingle } from '../utils'
79810export type CharacterTable = typeof character
···3537 .then(querySingle)
3638 }
37393838- public async getCharactersByUser(userId: UserId): Promise<
3939- {
4040- character: Character
4141- user: User | null
4242- }[]
4343- > {
4040+ public async getCharactersByUser(userId: UserId) {
4441 return await this.db
4542 .select()
4643 .from(character)
···50475148 public async updateCharacter(id: Character['id'], update: UpdateCharacter) {
5249 return await this.db.update(character).set(update).where(eq(character.id, id))
5050+ }
5151+5252+ public async getLanguages(id: Character['id']) {
5353+ return await this.db
5454+ .select()
5555+ .from(characterLanguage)
5656+ .where(eq(characterLanguage.characterId, id))
5757+ .leftJoin(language, eq(language.id, characterLanguage.languageId))
5358 }
5459}
+23
app/src/lib/server/db/repos/condition.ts
···11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22+import type { DatabaseConn } from '..'
33+import { condition } from '../schemas/dnd/mechanic'
44+55+export type ConditionTable = typeof condition
66+export type Condition = InferSelectModel<ConditionTable>
77+export type NewCondition = InferInsertModel<ConditionTable>
88+export type UpdateCondition = Partial<Omit<NewCondition, 'id'>>
99+1010+export class ConditionRepository {
1111+ private db: DatabaseConn
1212+ public constructor(db: DatabaseConn) {
1313+ this.db = db
1414+ }
1515+1616+ public async createCondition(model: NewCondition) {
1717+ return await this.db.insert(condition).values(model)
1818+ }
1919+2020+ public async getCondition(id: Condition['id']) {
2121+ return await this.db.select().from(condition).where(eq(condition.id, id))
2222+ }
2323+}
+2-1
app/src/lib/server/db/repos/equipment.ts
···11import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33-import { equipment, sourceBook } from '../schemas/dnd'
33+import { equipment } from '../schemas/dnd/equipment'
44+import { sourceBook } from '../schemas/dnd/sourcebook'
45import { querySingle, selectColumns, type TableColumnNames } from '../utils'
5667export type EquipmentTable = typeof equipment
+2-1
app/src/lib/server/db/repos/faction.ts
···11import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import { type DatabaseConn } from '..'
33-import { faction, sourceBook } from '../schemas/dnd'
33+import { faction } from '../schemas/dnd/faction'
44+import { sourceBook } from '../schemas/dnd/sourcebook'
45import { querySingle, selectColumns, type TableColumnNames } from '../utils'
5667export type FactionTable = typeof faction
+1-1
app/src/lib/server/db/repos/source-book.ts
···11import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33-import { sourceBook } from '../schemas/dnd'
33+import { sourceBook } from '../schemas/dnd/sourcebook'
44import { querySingle, selectColumns, type TableColumnNames } from '../utils'
5566export type SourceBookTable = typeof sourceBook
+2-1
app/src/lib/server/db/repos/species.ts
···11import { eq, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33-import { sourceBook, species } from '../schemas/dnd'
33+import { species } from '../schemas/dnd/origin'
44+import { sourceBook } from '../schemas/dnd/sourcebook'
45import { querySingle, selectColumns, type TableColumnNames } from '../utils'
5667export type SpeciesTable = typeof species
+2-1
app/src/lib/server/db/repos/spell.ts
···11import type { SpellDuration } from '@starlight/types/dnd'
22import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
33import type { DatabaseConn } from '..'
44-import { sourceBook, spell, spellDamage } from '../schemas/dnd'
44+import { sourceBook } from '../schemas/dnd/sourcebook'
55+import { spell, spellDamage } from '../schemas/dnd/spell'
56import { querySingle, selectColumns, type TableColumnNames } from '../utils'
6778export type SpellTable = typeof spell