From 4c1a439319e9bdfb404f03a25aa0a44f475e2a1b Mon Sep 17 00:00:00 2001 From: yanis lamliji Date: Tue, 31 Mar 2026 09:22:43 +0200 Subject: [PATCH] update and add insert command in user.rs file --- backend/user.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/user.rs b/backend/user.rs index 3e15478..35380c5 100644 --- a/backend/user.rs +++ b/backend/user.rs @@ -10,15 +10,22 @@ impl DataBase { DataBase { connection } } - fn data_execute(&self, arg: String){ - self.connection.execute(arg).unwrap(); + pub fn data_execute(&self, arg: String){ + match self.connection.execute(arg){ + OK => println!("Ok"), + Err(e) => panic!("Error : {}",e), + } } - fn create_table(&self, table: String, var: String){ - self.data_execute("CREATE TABLE ".to_owned() + &table + "(" + &var + ");"); + pub fn create_table(&self, table: &str, var: &str){ + self.data_execute("CREATE TABLE ".to_owned() + &table.to_string() + "(" + &var.to_string() + ");"); } - fn add_column(&self, table: String, arg: String){ - self.data_execute("ALTER TABLE ".to_owned() + &table + " ADD " + &arg + ";"); + pub fn add_column(&self, table: &str, arg: &str){ + self.data_execute("ALTER TABLE ".to_owned() + &table.to_string() + " ADD " + &arg.to_string() + ";"); + } + + pub fn insert(&self, table: &str, arg: &str){ + self.data_execute("INSERT INTO ".to_owned() + &table.to_string() + " VALUES (" + &arg.to_string() + ")" + ";"); } } \ No newline at end of file