27 lines
866 B
TypeScript
27 lines
866 B
TypeScript
import { getDatabase } from '$lib/server/database';
|
|
import { databaseCategories } from '$lib/database/categories';
|
|
import type { PageServerLoad } from './$types';
|
|
|
|
const tables = {
|
|
gear: 'gear',
|
|
weapons: 'weapons',
|
|
'weapon-mods': 'weapon_mods',
|
|
'gear-mods': 'gear_mods',
|
|
'os-protocols': 'os_protocols',
|
|
talents: 'talents',
|
|
brands: 'brand_sets',
|
|
'skill-chips': 'skill_chip_sets'
|
|
} as const;
|
|
|
|
export const load: PageServerLoad = async () => {
|
|
const database = await getDatabase();
|
|
const counts = await Promise.all(databaseCategories.map(async (category) => {
|
|
const row = await (await database.prepare(`SELECT COUNT(*) AS count FROM ${tables[category.slug]} WHERE active=1`)).get();
|
|
return { ...category, count: Number(row?.count ?? 0) };
|
|
}));
|
|
return {
|
|
registries: counts,
|
|
total: counts.reduce((total, registry) => total + registry.count, 0)
|
|
};
|
|
};
|