getCount.ts16 lines · main
1import { query, type Ctx } from '@briven/cli/server';
2
3interface Args {
4 id?: string;
5}
6
7/**
8 * Reactive query — returns the current count for the named counter.
9 * A missing row is treated as 0 so the first subscriber doesn't need
10 * to seed the counters table first.
11 */
12export default query(async (ctx: Ctx, args: Args) => {
13 const id = args.id ?? 'default';
14 const [row] = await ctx.db('counters').select(['count']).where({ id }).limit(1);
15 return { id, count: row ? Number(row.count) : 0 };
16});