an app to share curated trails
sidetrail.app
1import { drizzle, type NodePgDatabase } from "drizzle-orm/node-postgres";
2import { eq } from "drizzle-orm";
3import pg from "pg";
4import { ingestionCursor } from "@sidetrail/db";
5
6const { Pool } = pg;
7
8const pool = new Pool({
9 connectionString: process.env.DATABASE_URL,
10});
11
12export const db: NodePgDatabase = drizzle(pool);
13
14export async function getCursor(): Promise<number | undefined> {
15 const result = await db.select().from(ingestionCursor).where(eq(ingestionCursor.id, 1));
16 const cursor = result[0]?.cursorUs;
17 return cursor && cursor !== 0 ? cursor : undefined;
18}
19
20export async function setCursor(cursorUs: number): Promise<void> {
21 await db
22 .update(ingestionCursor)
23 .set({ cursorUs, updatedAt: new Date() })
24 .where(eq(ingestionCursor.id, 1));
25}