Sifa professional network API (Fastify, AT Protocol, Jetstream)
sifa.id/
1import type { Database } from '../db/index.js';
2import { jetstreamCursor } from '../db/schema/index.js';
3import { eq } from 'drizzle-orm';
4
5export function createCursorManager(db: Database, id = 'main') {
6 return {
7 async get(): Promise<bigint | undefined> {
8 const rows = await db
9 .select()
10 .from(jetstreamCursor)
11 .where(eq(jetstreamCursor.id, id))
12 .limit(1);
13 return rows[0]?.cursor;
14 },
15 async save(cursor: bigint): Promise<void> {
16 await db
17 .insert(jetstreamCursor)
18 .values({ id, cursor, updatedAt: new Date() })
19 .onConflictDoUpdate({
20 target: jetstreamCursor.id,
21 set: { cursor, updatedAt: new Date() },
22 });
23 },
24 };
25}