31 lines
944 B
Rust
31 lines
944 B
Rust
use sqlite::Connection;
|
|
|
|
pub struct DataBase {
|
|
connection: Connection,
|
|
}
|
|
|
|
impl DataBase {
|
|
pub fn open(name: String) -> DataBase {
|
|
let connection = sqlite::open(name + ".db").unwrap();
|
|
DataBase { connection }
|
|
}
|
|
|
|
pub fn data_execute(&self, arg: String){
|
|
match self.connection.execute(arg){
|
|
OK => println!("Ok"),
|
|
Err(e) => panic!("Error : {}",e),
|
|
}
|
|
}
|
|
|
|
pub fn create_table(&self, table: &str, var: &str){
|
|
self.data_execute("CREATE TABLE ".to_owned() + &table.to_string() + "(" + &var.to_string() + ");");
|
|
}
|
|
|
|
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() + ")" + ";");
|
|
}
|
|
} |