···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { Tool } from './equipment'
44import type { Feat } from './feat'
···1010} from '../schemas/dnd/background'
1111import { tool } from '../schemas/dnd/equipment'
1212import { feat } from '../schemas/dnd/feat'
1313-import {
1414- queryCount,
1515- querySingle,
1616- selectColumns,
1717- type TableColumnNames,
1818- type UpdateQueryParams,
1919-} from '../utils'
1313+import { querySingle, selectColumns, type TableColumnNames, type UpdateQueryParams } from '../utils'
20142115export type BackgroundTable = typeof background
2216export type Background = InferSelectModel<BackgroundTable>
···126120 }
127121128122 public async getCount(): Promise<number> {
129129- return await this.db.select({ count: count() }).from(background).then(queryCount)
123123+ return await this.db.$count(background)
130124 }
131125}
+3-3
app/src/lib/server/db/repos/class-feature.ts
···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { RepositoryCountable } from './repo'
44import { characterClassFeature } from '../schemas/dnd/class'
55-import { queryCount, querySingle } from '../utils'
55+import { querySingle } from '../utils'
6677export type ClassFeatureTable = typeof characterClassFeature
88export type ClassFeature = InferSelectModel<ClassFeatureTable>
···2525 }
26262727 public async getCount(): Promise<number> {
2828- return await this.db.select({ count: count() }).from(characterClassFeature).then(queryCount)
2828+ return await this.db.$count(characterClassFeature)
2929 }
3030}
+3-9
app/src/lib/server/db/repos/class.ts
···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { RepositoryCountable } from './repo'
44import { characterClass } from '../schemas/dnd/class'
55import { sourcebook } from '../schemas/dnd/sourcebook'
66-import {
77- queryCount,
88- querySingle,
99- selectColumns,
1010- type TableColumnNames,
1111- type UpdateQueryParams,
1212-} from '../utils'
66+import { querySingle, selectColumns, type TableColumnNames, type UpdateQueryParams } from '../utils'
137148export type ClassTable = typeof characterClass
159export type Class = InferSelectModel<ClassTable>
···5347 }
54485549 public async getCount(): Promise<number> {
5656- return this.db.select({ count: count() }).from(characterClass).then(queryCount)
5050+ return this.db.$count(characterClass)
5751 }
5852}
+3-3
app/src/lib/server/db/repos/condition.ts
···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { RepositoryCountable } from './repo'
44import { condition } from '../schemas/dnd/mechanic'
55import { sourcebook } from '../schemas/dnd/sourcebook'
66-import { queryCount, querySingle, type UpdateQueryParams } from '../utils'
66+import { querySingle, type UpdateQueryParams } from '../utils'
7788export type ConditionTable = typeof condition
99export type Condition = InferSelectModel<ConditionTable>
···3939 }
40404141 public async getCount(): Promise<number> {
4242- return await this.db.select({ count: count() }).from(condition).then(queryCount)
4242+ return await this.db.$count(condition)
4343 }
4444}
+3-9
app/src/lib/server/db/repos/equipment.ts
···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { RepositoryCountable } from './repo'
44import { equipment, tool } from '../schemas/dnd/equipment'
55import { sourcebook } from '../schemas/dnd/sourcebook'
66-import {
77- queryCount,
88- querySingle,
99- selectColumns,
1010- type TableColumnNames,
1111- type UpdateQueryParams,
1212-} from '../utils'
66+import { querySingle, selectColumns, type TableColumnNames, type UpdateQueryParams } from '../utils'
137148export type EquipmentTable = typeof equipment
159export type Equipment = InferSelectModel<EquipmentTable>
···5751 }
58525953 public async getCount(): Promise<number> {
6060- return await this.db.select({ count: count() }).from(equipment).then(queryCount)
5454+ return await this.db.$count(equipment)
6155 }
6256}
+3-9
app/src/lib/server/db/repos/faction.ts
···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { RepositoryCountable } from './repo'
33import { type DatabaseConn } from '..'
44import { faction } from '../schemas/dnd/faction'
55import { sourcebook } from '../schemas/dnd/sourcebook'
66-import {
77- queryCount,
88- querySingle,
99- selectColumns,
1010- type TableColumnNames,
1111- type UpdateQueryParams,
1212-} from '../utils'
66+import { querySingle, selectColumns, type TableColumnNames, type UpdateQueryParams } from '../utils'
137148export type FactionTable = typeof faction
159export type Faction = InferSelectModel<FactionTable>
···5044 }
51455246 public async getCount(): Promise<number> {
5353- return await this.db.select({ count: count() }).from(faction).then(queryCount)
4747+ return await this.db.$count(faction)
5448 }
5549}
+3-9
app/src/lib/server/db/repos/feat.ts
···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { RepositoryCountable } from './repo'
44import { feat } from '../schemas/dnd/feat'
55-import {
66- queryCount,
77- querySingle,
88- selectColumns,
99- type TableColumnNames,
1010- type UpdateQueryParams,
1111-} from '../utils'
55+import { querySingle, selectColumns, type TableColumnNames, type UpdateQueryParams } from '../utils'
126137export type FeatTable = typeof feat
148export type Feat = InferSelectModel<FeatTable>
···4337 }
44384539 public async getCount(): Promise<number> {
4646- return await this.db.select({ count: count() }).from(feat).then(queryCount)
4040+ return await this.db.$count(feat)
4741 }
4842}
+4-8
app/src/lib/server/db/repos/language.ts
···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { RepositoryCountable, RepositoryCountableWithSourceBook } from './repo'
44import type { SourceBook } from './source-book'
55import { language } from '../schemas/dnd/language'
66import { sourcebook } from '../schemas/dnd/sourcebook'
77-import { queryCount, querySingle, type UpdateQueryParams } from '../utils'
77+import { querySingle, type UpdateQueryParams } from '../utils'
8899export type LanguageTable = typeof language
1010export type Language = InferSelectModel<LanguageTable>
···4141 }
42424343 public async getCount(): Promise<number> {
4444- return await this.db.select({ count: count() }).from(language).then(queryCount)
4444+ return await this.db.$count(language)
4545 }
46464747 public async getCountFromSourceBook(id: SourceBook['id']): Promise<number> {
4848- return await this.db
4949- .select({ count: count() })
5050- .from(language)
5151- .where(eq(language.sourcebookId, id))
5252- .then(queryCount)
4848+ return await this.db.$count(language, eq(language.sourcebookId, id))
5349 }
5450}
+4-8
app/src/lib/server/db/repos/monster.ts
···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { RepositoryCountable, RepositoryCountableWithSourceBook } from './repo'
44import type { SourceBook } from './source-book'
···1010 monsterDmgVulnerability,
1111} from '../schemas/dnd/monster'
1212import { sourcebook } from '../schemas/dnd/sourcebook'
1313-import { queryCount, querySingle, selectColumns, type TableColumnNames } from '../utils'
1313+import { querySingle, selectColumns, type TableColumnNames } from '../utils'
1414import {
1515 MonsterDefenseRepository,
1616 type NewMonsterImmunity,
···115115 }
116116117117 public async getCount(): Promise<number> {
118118- return await this.db.select({ count: count() }).from(monster).then(queryCount)
118118+ return await this.db.$count(monster)
119119 }
120120121121 public async getCountFromSourceBook(id: SourceBook['id']): Promise<number> {
122122- return await this.db
123123- .select({ count: count() })
124124- .from(monster)
125125- .where(eq(monster.sourcebookId, id))
126126- .then(queryCount)
122122+ return await this.db.$count(monster, eq(monster.sourcebookId, id))
127123 }
128124}
+3-10
app/src/lib/server/db/repos/source-book.ts
···11-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { RepositoryCountable } from './repo'
44-import { monster } from '../schemas/dnd/monster'
54import { sourcebook } from '../schemas/dnd/sourcebook'
66-import {
77- queryCount,
88- querySingle,
99- selectColumns,
1010- type TableColumnNames,
1111- type UpdateQueryParams,
1212-} from '../utils'
55+import { querySingle, selectColumns, type TableColumnNames, type UpdateQueryParams } from '../utils'
136147export type SourceBookTable = typeof sourcebook
158export type SourceBook = InferSelectModel<SourceBookTable>
···7467 }
75687669 public async getCount(): Promise<number> {
7777- return await this.db.select({ count: count() }).from(monster).then(queryCount)
7070+ return await this.db.$count(sourcebook)
7871 }
7972}
+3-9
app/src/lib/server/db/repos/species.ts
···11-import { count, eq, type InferSelectModel } from 'drizzle-orm'
11+import { eq, type InferSelectModel } from 'drizzle-orm'
22import type { DatabaseConn } from '..'
33import type { RepositoryCountable } from './repo'
44import { sourcebook } from '../schemas/dnd/sourcebook'
55import { species } from '../schemas/dnd/species'
66-import {
77- queryCount,
88- querySingle,
99- selectColumns,
1010- type TableColumnNames,
1111- type UpdateQueryParams,
1212-} from '../utils'
66+import { querySingle, selectColumns, type TableColumnNames, type UpdateQueryParams } from '../utils'
137148export type SpeciesTable = typeof species
159export type Species = InferSelectModel<SpeciesTable>
···5246 }
53475448 public async getCount(): Promise<number> {
5555- return await this.db.select({ count: count() }).from(species).then(queryCount)
4949+ return await this.db.$count(species)
5650 }
5751}
+3-9
app/src/lib/server/db/repos/spell.ts
···11import type { SpellDuration } from '@starlight/types/dnd'
22-import { count, eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
22+import { eq, type InferInsertModel, type InferSelectModel } from 'drizzle-orm'
33import type { DatabaseConn } from '..'
44import type { RepositoryCountable } from './repo'
55import { damage } from '../schemas/dnd/mechanic'
66import { sourcebook } from '../schemas/dnd/sourcebook'
77import { spell } from '../schemas/dnd/spell'
88-import {
99- queryCount,
1010- querySingle,
1111- selectColumns,
1212- type TableColumnNames,
1313- type UpdateQueryParams,
1414-} from '../utils'
88+import { querySingle, selectColumns, type TableColumnNames, type UpdateQueryParams } from '../utils'
1591610export type SpellTable = typeof spell
1711export type Spell = Omit<InferSelectModel<SpellTable>, 'duration'> & {
···5953 }
60546155 public async getCount(): Promise<number> {
6262- return await this.db.select({ count: count() }).from(spell).then(queryCount)
5656+ return await this.db.$count(spell)
6357 }
6458}
-4
app/src/lib/server/db/utils.ts
···2626 return results.at(0) ?? null
2727}
28282929-export function queryCount<T extends { count: number }>(results: T[]): number {
3030- return results[0].count
3131-}
3232-3329export type UpdateQueryParams<Id, Model> = {
3430 id: Id
3531 model: Model