/** * D1 Database Query Helpers * * Type-safe wrappers for common D1 query patterns. * "Less, but better" - one place for database typing. */ import type { Paper } from '../types/paper.js'; export interface CategoryStat { name: string; slug: string; count: number; } export interface CategoryRow { category: string; count: number; } export interface ExperimentStats { total_executions: number; completed_count: number; avg_time_seconds: number; avg_errors: number; total_errors: number; completion_rate?: number; fastest_time?: number; slowest_time?: number; } type D1Database = { prepare(query: string): D1PreparedStatement; }; type D1PreparedStatement = { bind(...values: unknown[]): D1PreparedStatement; all(): Promise>; first(colName?: string): Promise; run(): Promise>; }; type D1Result = { results?: T[]; success: boolean; meta: object; }; /** * Standard columns for Paper queries. * Matches the Paper interface from types/paper.ts */ export declare const PAPER_COLUMNS = "\n\tid, title, category, content, html_content, reading_time,\n\tdifficulty_level, technical_focus, published_on, excerpt_short,\n\texcerpt_long, slug, featured, published, is_hidden, archived,\n\tdate, excerpt, description, thumbnail_image, featured_card_image,\n\tfeatured_image, video_walkthrough_url, interactive_demo_url,\n\tresource_downloads, prerequisites, meta_title, meta_description,\n\tfocus_keywords, ascii_art, ascii_thumbnail, created_at, updated_at,\n\tpublished_at, pathway, \"order\", summary, code_snippet\n"; /** * Fetch all published papers */ export declare function fetchPublishedPapers(db: D1Database): Promise; /** * Fetch a single paper by slug */ export declare function fetchPaperBySlug(db: D1Database, slug: string): Promise; /** * Fetch related papers by category, excluding current paper */ export declare function fetchRelatedPapers(db: D1Database, category: string, excludeId: string, limit?: number): Promise; /** * Fetch papers by category */ export declare function fetchPapersByCategory(db: D1Database, category: string): Promise; /** * Fetch category statistics */ export declare function fetchCategoryStats(db: D1Database): Promise; /** * Fetch experiment execution statistics */ export declare function fetchExperimentStats(db: D1Database, paperId: string): Promise; /** * Safe query wrapper that handles errors gracefully */ export declare function safeQuery(queryFn: () => Promise, fallback: T): Promise; export {};