made a sanity version of surveyed data appear in frontend@

This commit is contained in:
Jun-te Kim 2025-05-29 14:56:44 +00:00
parent 254aeb647e
commit f2c2abc4da
3 changed files with 63 additions and 6 deletions

View file

@ -5,7 +5,5 @@ if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is not defined in environment variables");
}
const queryClient = postgres(process.env.DATABASE_URL);
const db = drizzle({ client: queryClient });
const result = await db.execute('select 1');
const sqlClient = postgres(process.env.DATABASE_URL);
export const db = drizzle(sqlClient);

View file

@ -0,0 +1,10 @@
import { pgTable, text, uuid } from 'drizzle-orm/pg-core';
export const buildings = pgTable('buildings', {
id: uuid('id').defaultRandom().primaryKey(),
address: text('address').notNull(),
postcode: text('postcode').notNull(),
UPRN: text('UPRN').notNull(),
landlordId: text('landlord_id').notNull(),
domnaId: text('domna_id').notNull(),
});

View file

@ -1,6 +1,55 @@
// app/page.tsx
import { db } from './db/db'; // adjust path if needed
import { buildings } from './db/schema/buildings';
type Building = {
id: string;
address: string;
postcode: string;
uprn: string;
landlordId: string;
domnaId: string;
};
export default async function Home() {
const buildingRows = await db.select().from(buildings);
const buildingsData: Building[] = buildingRows.map((b) => ({
id: b.id.toString(),
address: b.address,
postcode: b.postcode,
uprn: b.UPRN,
landlordId: b.landlordId,
domnaId: b.domnaId,
}));
export default function Home() {
return (
<h1>Hello Next.js!</h1>
<>
<h1>Buildings List</h1>
<table border={1} cellPadding={8} cellSpacing={0}>
<thead>
<tr>
<th>ID</th>
<th>Address</th>
<th>Postcode</th>
<th>UPRN</th>
<th>Landlord ID</th>
<th>Domna ID</th>
</tr>
</thead>
<tbody>
{buildingsData.map((b) => (
<tr key={b.id}>
<td>{b.id}</td>
<td>{b.address}</td>
<td>{b.postcode}</td>
<td>{b.uprn}</td>
<td>{b.landlordId}</td>
<td>{b.domnaId}</td>
</tr>
))}
</tbody>
</table>
</>
);
}