Use api for DB

This commit is contained in:
Clayzxr
2025-01-20 16:33:06 +01:00
parent 4057bb488c
commit a49683c10e
11 changed files with 106 additions and 128 deletions
-31
View File
@@ -1,31 +0,0 @@
import { DB } from "https://deno.land/x/sqlite/mod.ts";
export default function insertIntoMobility(
data: Array<{ firstName: string; lastName: string; email: string }>,
promoName: string
) {
try {
const db = new DB("databases/data/mobility.db");
db.execute(`
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
);
`);
const insertQuery = "INSERT INTO students (firstName, lastName, email, promotion) VALUES (?, ?, ?, ?)";
for (const student of data) {
db.query(insertQuery, [student.firstName, student.lastName, student.email, promoName]);
}
console.log(`Data for promotion ${promoName} inserted successfully.`);
db.close();
} catch (error) {
console.error("Error inserting data into mobility database:", error);
}
}