diff --git a/app/tables/page.tsx b/app/tables/page.tsx new file mode 100644 index 0000000..917c29a --- /dev/null +++ b/app/tables/page.tsx @@ -0,0 +1,27 @@ +import { getTable, listTables } from "@/repository/database"; +import Link from "next/link"; + +export default async function Dossiers({ + searchParams, +}: { + searchParams: { table: string }; +}) { + const tables = await listTables(); + const dossier = await getTable(searchParams.table ?? ""); + // TODO: match old website url ":id/dossiers/:id" + return ( +
+ +
+

{searchParams.table}

+
{JSON.stringify(dossier, null, 2)}
+
+
+ ); +} diff --git a/repository/database.ts b/repository/database.ts index 31adf36..ade6182 100644 --- a/repository/database.ts +++ b/repository/database.ts @@ -1,39 +1,54 @@ -import knex from 'knex'; -import config from './knexfile'; +import knex from "knex"; +import config from "./knexfile"; const db = knex(config.development); export async function listTables() { - try { - const result = await db.raw("SELECT table_name FROM information_schema.tables WHERE table_schema='public'"); - return result.rows.map((row: any) => row.table_name); - } catch (error) { - console.error('Error listing tables:', error); - throw error; - } + try { + const result = await db.raw( + "SELECT table_name FROM information_schema.tables WHERE table_schema='public'" + ); + return result.rows.map((row: any) => row.table_name).sort(); + } catch (error) { + console.error("Error listing tables:", error); + throw error; + } } interface DossierRow { - uid: string; - xsiType: string; - legislature: string; - senatChemin: string; - titre: string; - titreChemin: string; - theme: string | null; - codeProcedure: string; - libelleProcedure: string; - causeFusionDossier: string | null; - dossierAbsorbantRefUid: string | null; - organeRefUid: string | null; + uid: string; + xsiType: string; + legislature: string; + senatChemin: string; + titre: string; + titreChemin: string; + theme: string | null; + codeProcedure: string; + libelleProcedure: string; + causeFusionDossier: string | null; + dossierAbsorbantRefUid: string | null; + organeRefUid: string | null; } export async function getDossiers(limit = 10): Promise { - try { - const rows = await db.select('*').from('Dossier').limit(limit); - return rows; - } catch (error) { - console.error('Error fetching rows from Dossier:', error); - throw error; - } -} \ No newline at end of file + try { + const rows = await db.select("*").from("Dossier").limit(limit); + return rows; + } catch (error) { + console.error("Error fetching rows from Dossier:", error); + throw error; + } +} + +export async function getTable( + table: string, + limit = 10 +): Promise { + try { + const rows = await db.select("*").from(table).limit(limit); + return rows; + } catch (error) { + console.error("Error fetching rows from Dossier:", error); + throw error; + } +}