Apps
Code
Launchpad
CodeIncluded
csv.tszip.tsSearch the repo
1import { db } from "@/server/db";23/** One table as CSV, header row first. */4export async function tableToCsv(table: string) {5 const rows = await db.select(table);6 const header = Object.keys(rows[0] ?? {});7 const lines = rows.map((r) => header.map((h) => escape(r[h])).join(","));8 return [header.join(","), ...lines].join("\n");9}1011function escape(v: unknown) {12 const text = String(v ?? "");13 return /[",\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;14}
Browse, search and edit the repository without leaving the project. On your machine it is the real checkout.