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:
Binary file not shown.
@@ -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")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Queryable, Selectable, Debug)]
|
||||
#[derive(Queryable, Selectable, Debug, Insertable, Serialize, Deserialize)]
|
||||
#[diesel(table_name = crate::db::schema::app)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct App {
|
||||
@@ -11,7 +12,7 @@ pub struct App {
|
||||
pub ssh_address: Option<String>, // default to normal address
|
||||
}
|
||||
|
||||
#[derive(Queryable, Selectable, Debug)]
|
||||
#[derive(Queryable, Selectable, Debug, Serialize, Deserialize)]
|
||||
#[diesel(table_name = crate::db::schema::blog)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Blog {
|
||||
@@ -21,7 +22,7 @@ pub struct Blog {
|
||||
pub reference: Option<String>, // uuid
|
||||
}
|
||||
|
||||
#[derive(Queryable, Selectable, Debug)]
|
||||
#[derive(Queryable, Selectable, Debug, Serialize, Deserialize)]
|
||||
#[diesel(table_name = crate::db::schema::identities)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Identity {
|
||||
|
||||
+16
-16
@@ -1,31 +1,31 @@
|
||||
use db::models::App;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::db::{create_app, establish_connection, get_apps};
|
||||
mod db;
|
||||
|
||||
#[tauri::command]
|
||||
fn new_app(
|
||||
name: String,
|
||||
address: String,
|
||||
description: Option<String>,
|
||||
ssh_address: Option<String>,
|
||||
) {
|
||||
let uuid = Uuid::new_v4();
|
||||
let app = App {
|
||||
id: uuid.to_string(),
|
||||
name,
|
||||
description,
|
||||
address,
|
||||
ssh_address,
|
||||
};
|
||||
fn new_app(name: &str, address: &str, description: Option<&str>, ssh_address: Option<&str>) -> App {
|
||||
let mut conn = &mut establish_connection();
|
||||
let app = create_app(&mut conn, name, address, description, ssh_address);
|
||||
|
||||
println!("{:#?}", app);
|
||||
app
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn get_app() -> Vec<App> {
|
||||
let mut conn = &mut establish_connection();
|
||||
let apps = get_apps(&mut conn);
|
||||
|
||||
println!("{:#?}", apps);
|
||||
apps
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![new_app])
|
||||
.invoke_handler(tauri::generate_handler![new_app, get_app])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user