add sql rust interaction file
This commit is contained in:
52
backend/user.rs
Normal file
52
backend/user.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
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 }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn data_execute(&self, arg: String){
|
||||||
|
self.connection.execute(arg).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_table(&self, table: String){
|
||||||
|
self.data_execute("CREATE TABLE ".to_owned() + &table + ";");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_column(&self, table: String, arg: String){
|
||||||
|
self.data_execute("ALTER TABLE ".to_owned() + &table + " ADD " + &arg + ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let db = DataBase::open(String::from("test"));
|
||||||
|
db.create_table("test".to_string());
|
||||||
|
db.add_column("test".to_string(), "name TEXT".to_string());
|
||||||
|
// println!("Hello, world!");
|
||||||
|
|
||||||
|
// let connection = sqlite::open("test.db").unwrap();
|
||||||
|
|
||||||
|
// let query = "
|
||||||
|
// CREATE TABLE users (name TEXT, age INTEGER);
|
||||||
|
// INSERT INTO users VALUES ('Alice', 42);
|
||||||
|
// INSERT INTO users VALUES ('Bob', 69);
|
||||||
|
// ";
|
||||||
|
|
||||||
|
// connection.execute(query).unwrap();
|
||||||
|
}
|
||||||
|
// struct User {
|
||||||
|
// name : string,
|
||||||
|
// level : int,
|
||||||
|
// }
|
||||||
|
|
||||||
|
// impl User {
|
||||||
|
// fn Create(&self){
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
Reference in New Issue
Block a user