Skip to content

Commit

Permalink
Merge pull request #1 from FloCheru/save-expenses-in-database
Browse files Browse the repository at this point in the history
Save expenses in mySQL database + frontend/backend split
  • Loading branch information
FloCheru authored Oct 18, 2024
2 parents 8271bec + 8142607 commit 0620146
Show file tree
Hide file tree
Showing 1,192 changed files with 195,291 additions and 213 deletions.
16 changes: 16 additions & 0 deletions Backend/dataBase/dbConnexion.js
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");
43 changes: 43 additions & 0 deletions Backend/dataBase/functionsDB/addDataToDatabase.ts
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
Empty file added Backend/dataBase/sql.sql
Empty file.
File renamed without changes.
16 changes: 16 additions & 0 deletions Backend/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Backend/node_modules/.bin/mime.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Backend/node_modules/.bin/mime.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Backend/node_modules/.bin/nodemon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Backend/node_modules/.bin/nodemon.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Backend/node_modules/.bin/nodemon.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Backend/node_modules/.bin/nodetouch

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Backend/node_modules/.bin/nodetouch.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Backend/node_modules/.bin/nodetouch.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Backend/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Backend/node_modules/.bin/semver.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Backend/node_modules/.bin/semver.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0620146

Please sign in to comment.