/* * clippr: a social bookmarking service for the AT Protocol * Copyright (c) 2025 clippr contributors. * SPDX-License-Identifier: AGPL-3.0-only */ import type { AppviewStatsQuery } from "./types.js"; import { Database } from "../db/database.js"; import { clipsTable, tagsTable, usersTable } from "../db/schema.js"; import { count } from "drizzle-orm"; const db = Database.getInstance().getDb(); export async function getStats(): Promise { const clipCount = await db.select({ count: count() }).from(clipsTable); const tagCount = await db.select({ count: count() }).from(tagsTable); const userCount = await db.select({ count: count() }).from(usersTable); if ( clipCount[0] === undefined || tagCount[0] === undefined || userCount[0] === undefined ) { return { knownClips: 0, knownTags: 0, knownUsers: 0, }; } return { knownClips: clipCount[0].count, knownTags: tagCount[0].count, knownUsers: userCount[0].count, }; }