21 lines
643 B
TypeScript
21 lines
643 B
TypeScript
import { executeQuerySingle } from '@/lib/clickhouse';
|
|
import { StatsOverview } from '../types';
|
|
|
|
/**
|
|
* Get overview statistics for links
|
|
*/
|
|
export async function findStatsOverview(): Promise<StatsOverview | null> {
|
|
const query = `
|
|
WITH
|
|
toUInt64(count()) as total_links,
|
|
toUInt64(countIf(is_active = true)) as active_links
|
|
FROM links
|
|
SELECT
|
|
total_links as totalLinks,
|
|
active_links as activeLinks,
|
|
(SELECT count() FROM link_events) as totalVisits,
|
|
(SELECT count() FROM link_events) / NULLIF(total_links, 0) as conversionRate
|
|
`;
|
|
|
|
return await executeQuerySingle<StatsOverview>(query);
|
|
} |