Use the DB instead of a .csv (not working)

This commit is contained in:
Clayzxr
2025-01-17 15:37:27 +01:00
parent 416aad06ea
commit 6df75e0604
11 changed files with 91 additions and 188 deletions
+12
View File
@@ -0,0 +1,12 @@
CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY AUTOINCREMENT,
firstName TEXT NOT NULL,
lastName TEXT NOT NULL,
email TEXT NOT NULL,
promotion TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS promotions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
year INTEGER NOT NULL
);
+22
View File
@@ -0,0 +1,22 @@
import { Database } from "@db/sqlite";
export default async function insertIntoMobility(data: Array<{ firstName: string; lastName: string; email: string }>, promoName: string) {
try {
const databasePath = "databases/data/mobility.db";
const db = new Database(databasePath);
db.transaction(() => {
for (const student of data) {
db.query(
"INSERT INTO students (firstName, lastName, email, promotion) VALUES (?, ?, ?, ?)",
[student.firstName, student.lastName, student.email, promoName]
);
}
})();
db.close();
console.log(`Data for promotion ${promoName} inserted successfully.`);
} catch (error) {
console.error("Error inserting data into mobility database:", error);
}
}