-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from alexfauquette/explor-tabs
- Loading branch information
Showing
2 changed files
with
71 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div style={{ display: "flex" }}> | ||
<ul> | ||
{tables.map((tableName: string) => ( | ||
<li key={tableName}> | ||
<a href={`/tables/?table=${tableName}`}>{tableName}</a> | ||
</li> | ||
))} | ||
</ul> | ||
<div> | ||
<p>{searchParams.table}</p> | ||
<pre>{JSON.stringify(dossier, null, 2)}</pre> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DossierRow[]> { | ||
try { | ||
const rows = await db.select('*').from('Dossier').limit(limit); | ||
return rows; | ||
} catch (error) { | ||
console.error('Error fetching rows from Dossier:', error); | ||
throw error; | ||
} | ||
} | ||
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<DossierRow[]> { | ||
try { | ||
const rows = await db.select("*").from(table).limit(limit); | ||
return rows; | ||
} catch (error) { | ||
console.error("Error fetching rows from Dossier:", error); | ||
throw error; | ||
} | ||
} |