Use the DB instead of a .csv (not working)
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user