All files / plainweb/src/admin/database/routes index.tsx

85.71% Statements 12/14
50% Branches 1/2
100% Functions 1/1
85.71% Lines 12/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x 1x     1x   1x 1x   1x 1x 1x 1x   1x       1x 1x  
import { config } from "admin/config";
import { sql } from "drizzle-orm";
import type { BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
import type { Handler } from "handler";
import { redirect } from "plain-response";
 
export const GET: Handler = async ({ req, res }) => {
  const db = res.locals.database as BetterSQLite3Database;
 
  const tables = await db
    .select({ name: sql<string>`name` })
    .from(sql`sqlite_master`)
    .where(sql`type=${"table"} AND name NOT LIKE ${"sqlite_%"}`);
 
  if (!tables[0]) {
    return <div>No tables found</div>;
  }
 
  return redirect(`${config.adminBasePath}/database/${tables[0].name}`);
};