Minor fix for DB (working)

This commit is contained in:
Clayzxr
2025-01-22 11:00:18 +01:00
parent 5e75c688c8
commit d767cb0898
3 changed files with 8 additions and 7 deletions
+3 -2
View File
@@ -1,5 +1,6 @@
create table promotions (
id integer primary key autoincrement,
name text,
endyear integer,
current integer
);
@@ -9,6 +10,6 @@ create table students (
firstName text,
lastName text,
mail text,
promo integer,
foreign key(promo) references promo(id)
promotionId integer,
foreign key(promotionId) references promotions(id)
);
@@ -9,7 +9,7 @@ interface Student {
id: number;
firstName: string;
lastName: string;
email: string;
mail: string;
promotionId: number;
promotionName: string;
}
@@ -43,7 +43,7 @@ export default function ConsultStudents() {
{error && <p className="error">{error}</p>}
{data?.promotions.map((promo) => (
<div key={promo.id}>
<h3>Promotion: {promo.name}</h3>
<h3>Promotion: {promo.id}</h3>
<table>
<thead>
<tr>
@@ -61,7 +61,7 @@ export default function ConsultStudents() {
<td>{student.id}</td>
<td>{student.firstName}</td>
<td>{student.lastName}</td>
<td>{student.email}</td>
<td>{student.mail}</td>
</tr>
))}
</tbody>
@@ -12,7 +12,7 @@ export const handler: Handlers = {
const students = connection.database
.prepare(
`select userId, firstName, lastName, mail, promo from students`,
`select userId, firstName, lastName, mail, promotionId from students`,
)
.all();
@@ -56,7 +56,7 @@ export const handler: Handlers = {
console.log(`Promotion ID for "${promoName}":`, promoId);
const insertQuery = connection.database.prepare(
"INSERT INTO students (firstName, lastName, email, promotionId) VALUES (?, ?, ?, ?)",
"INSERT INTO students (firstName, lastName, mail, promotionId) VALUES (?, ?, ?, ?)",
);
for (const student of data) {