social bookmarking for atproto
1/*
2 * clippr: a social bookmarking service for the AT Protocol
3 * Copyright (c) 2025 clippr contributors.
4 * SPDX-License-Identifier: AGPL-3.0-only
5 */
6
7import type { AppviewStatsQuery } from "./types.js";
8import { Database } from "../db/database.js";
9import { clipsTable, tagsTable, usersTable } from "../db/schema.js";
10import { count } from "drizzle-orm";
11
12const db = Database.getInstance().getDb();
13
14export async function getStats(): Promise<AppviewStatsQuery> {
15 const clipCount = await db.select({ count: count() }).from(clipsTable);
16 const tagCount = await db.select({ count: count() }).from(tagsTable);
17 const userCount = await db.select({ count: count() }).from(usersTable);
18
19 if (
20 clipCount[0] === undefined ||
21 tagCount[0] === undefined ||
22 userCount[0] === undefined
23 ) {
24 return {
25 knownClips: 0,
26 knownTags: 0,
27 knownUsers: 0,
28 };
29 }
30
31 return {
32 knownClips: clipCount[0].count,
33 knownTags: tagCount[0].count,
34 knownUsers: userCount[0].count,
35 };
36}