-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Save expenses in mySQL database + frontend/backend split
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// const sqlite3 = require("sqlite3").verbose(); | ||
|
||
// const db = new sqlite3.Database("db.sqlite", (err) => { | ||
// if (err) { | ||
// console.error("Error opening database", err.message); | ||
// } else { | ||
// console.log("Connected to the SQLite database."); | ||
// } | ||
// }); | ||
|
||
// module.exports = db; | ||
|
||
// const Database = require("better-sqlite3"); | ||
// const db = new Database("mydatabase.db"); | ||
|
||
const db = require("better-sqlite3")("db.sqlite"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import db from "../dbConnexion.js"; | ||
|
||
interface Expense { | ||
name: string; | ||
montant: number; | ||
catégorie: string; | ||
maPart: number; | ||
réglé: boolean; | ||
type: string; | ||
tricount: string; | ||
mois: string; | ||
date: number; | ||
paiement: string; | ||
} | ||
|
||
export function addDataToDatabase(data: Expense[]): void { | ||
console.log("ehoh"); | ||
data.forEach((expense) => { | ||
const query = | ||
"INSERT INTO account (name, montant, catégorie, maPart, réglé, type, tricount, mois, date, paiement)VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; | ||
const values = [ | ||
expense.name, | ||
expense.montant, | ||
expense.catégorie, | ||
expense.maPart, | ||
expense.réglé, | ||
expense.type, | ||
expense.tricount, | ||
expense.mois, | ||
expense.date, | ||
expense.paiement, | ||
]; | ||
db.run(query, values, function (err) { | ||
if (err) { | ||
console.error("Error inserting data: ", err.message); | ||
} else { | ||
console.log(`A row has been inserted with row id ${this.lastID}`); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
//pour tester la fonction |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.