removed db from gitignore + made it so that the app cards render dynamically + delete dialog + add actually works + no crashing
This commit is contained in:
@@ -12,3 +12,36 @@ pub fn establish_connection() -> SqliteConnection {
|
||||
SqliteConnection::establish(&database_url)
|
||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||
}
|
||||
|
||||
pub fn create_app(
|
||||
conn: &mut SqliteConnection,
|
||||
name: &str,
|
||||
address: &str,
|
||||
description: Option<&str>,
|
||||
ssh_address: Option<&str>,
|
||||
) -> models::App {
|
||||
use crate::db::schema::app;
|
||||
|
||||
let new_app = models::App {
|
||||
id: uuid::Uuid::new_v4().to_string(),
|
||||
name: name.to_string(),
|
||||
description: description.map(|d| d.to_string()),
|
||||
address: address.to_string(),
|
||||
ssh_address: ssh_address.map(|s| s.to_string()),
|
||||
};
|
||||
|
||||
diesel::insert_into(app::table)
|
||||
.values(&new_app)
|
||||
.execute(conn)
|
||||
.expect("Error saving new app");
|
||||
|
||||
new_app
|
||||
}
|
||||
|
||||
pub fn get_apps(conn: &mut SqliteConnection) -> Vec<models::App> {
|
||||
use crate::db::schema::app;
|
||||
|
||||
app::table
|
||||
.load::<models::App>(conn)
|
||||
.expect("Error loading apps")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user