Skip to content
File

Blob: src/worker/lib/page-access.ts

typescript22 lines
1import { eq, and, isNull } from "drizzle-orm";
2import { pages } from "@/worker/db/d1/schema";
3import type { Db } from "@/worker/db/d1/client";
4 
5/**
6 * Look up a non-archived page by id, optionally scoped to a workspace.
7 * Returns the page row or null.
8 */
9export async function getPage(db: Db, pageId: string, workspaceId?: string) {
10 const conditions = [eq(pages.id, pageId), isNull(pages.archived_at)];
11 if (workspaceId) {
12 conditions.push(eq(pages.workspace_id, workspaceId));
13 }
14 return (
15 db
16 .select()
17 .from(pages)
18 .where(and(...conditions))
19 .get() ?? null
20 );
21}