Skip to content

Commit 2e63671

Browse files
committed
fix: project persist issue
1 parent 05ef8cf commit 2e63671

File tree

14 files changed

+79
-90
lines changed

14 files changed

+79
-90
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust-sql-gui-ui"
3-
version = "1.0.0-alpha.3"
3+
version = "1.0.0-alpha.4"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "common"
3-
version = "1.0.0-alpha.3"
3+
version = "1.0.0-alpha.4"
44
edition = "2021"
55

66
[dependencies]

common/src/drivers/postgresql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
#[derive(Clone, Default, PartialEq, Serialize, Deserialize)]
3+
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
44
pub struct Postgresql {
55
pub user: String,
66
pub password: String,

common/src/enums.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
44

55
use super::projects::postgresql::Postgresql;
66

7-
#[derive(Clone, PartialEq, Serialize, Deserialize)]
7+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
88
pub enum Project {
99
POSTGRESQL(Postgresql),
1010
}
@@ -22,7 +22,7 @@ impl Display for Drivers {
2222
}
2323
}
2424

25-
#[derive(Clone, Default, PartialEq, Serialize, Deserialize)]
25+
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
2626
pub enum ProjectConnectionStatus {
2727
Connected,
2828
#[default]

common/src/projects/postgresql.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::collections::BTreeMap;
33

44
use crate::{drivers::postgresql::Postgresql as PostgresqlDriver, enums::ProjectConnectionStatus};
55

6-
#[derive(Clone, PartialEq, Serialize, Deserialize)]
6+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
77
pub struct Postgresql {
88
pub name: String,
99
pub driver: PostgresqlDriver,
10-
pub schmemas: Option<Vec<String>>,
10+
pub schemas: Option<Vec<String>>,
1111
pub tables: Option<BTreeMap<String, Vec<(String, String)>>>,
1212
pub connection_status: ProjectConnectionStatus,
1313
}
@@ -17,7 +17,7 @@ impl Default for Postgresql {
1717
Self {
1818
name: String::default(),
1919
driver: PostgresqlDriver::default(),
20-
schmemas: None,
20+
schemas: None,
2121
tables: None,
2222
connection_status: ProjectConnectionStatus::Disconnected,
2323
}

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust-sql-gui"
3-
version = "1.0.0-alpha.3"
3+
version = "1.0.0-alpha.4"
44
description = "PostgreSQL GUI written in Rust"
55
authors = ["Daniel Boros"]
66
license = ""

src-tauri/src/dbs/project.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub async fn select_projects(app_state: State<'_, AppState>) -> Result<Vec<(Stri
2020
let connection_string = String::from_utf8(connection_string.to_vec()).unwrap();
2121
let connection_string = connection_string.split(':').collect::<Vec<&str>>();
2222
let _driver = connection_string[0].to_string();
23+
let _driver = _driver.split('=').collect::<Vec<&str>>()[1];
2324
let project_details = match _driver {
2425
d if d == Drivers::POSTGRESQL.to_string() => {
2526
let mut driver = PostgresqlDriver::default();

src-tauri/src/drivers/postgresql.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub async fn postgresql_connector(
1111
) -> Result<Vec<String>> {
1212
let app_state = app.state::<AppState>();
1313
let (client, connection) = connect(key, NoTls).await.expect("connection error");
14-
1514
tokio::spawn(async move {
1615
if let Err(e) = connection.await {
1716
eprintln!("connection error: {}", e);
@@ -33,18 +32,17 @@ pub async fn postgresql_connector(
3332
let mut clients = app_state.client.lock().await;
3433
let clients = clients.as_mut().unwrap();
3534
clients.insert(project_name.to_string(), client);
36-
3735
Ok(schemas)
3836
}
3937

4038
#[tauri::command(rename_all = "snake_case")]
4139
pub async fn select_schema_tables(
42-
project: &str,
40+
project_name: &str,
4341
schema: &str,
4442
app_state: State<'_, AppState>,
4543
) -> Result<Vec<(String, String)>> {
4644
let clients = app_state.client.lock().await;
47-
let client = clients.as_ref().unwrap().get(project).unwrap();
45+
let client = clients.as_ref().unwrap().get(project_name).unwrap();
4846
let tables = client
4947
.query(
5048
r#"
@@ -66,18 +64,17 @@ pub async fn select_schema_tables(
6664
.iter()
6765
.map(|r| (r.get(0), r.get(1)))
6866
.collect::<Vec<(String, String)>>();
69-
7067
Ok(tables)
7168
}
7269

7370
#[tauri::command(rename_all = "snake_case")]
7471
pub async fn select_sql_result(
75-
project: &str,
72+
project_name: &str,
7673
sql: String,
7774
app_state: State<'_, AppState>,
7875
) -> Result<(Vec<String>, Vec<Vec<String>>)> {
7976
let clients = app_state.client.lock().await;
80-
let client = clients.as_ref().unwrap().get(project).unwrap();
77+
let client = clients.as_ref().unwrap().get(project_name).unwrap();
8178
let rows = client.query(sql.as_str(), &[]).await.unwrap();
8279

8380
if rows.is_empty() {

src/invoke.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ pub struct InvokeSchemaTablesArgs<'a> {
4545
}
4646

4747
#[derive(Serialize, Deserialize)]
48-
pub struct InvokeSqlResultArgs {
49-
pub project: String,
50-
pub sql: String,
48+
pub struct InvokeSqlResultArgs<'a> {
49+
pub project_name: &'a str,
50+
pub sql: &'a str,
5151
}
5252

5353
#[derive(Serialize, Deserialize)]
@@ -59,20 +59,20 @@ pub struct InvokeInsertProjectArgs {
5959
}
6060

6161
#[derive(Serialize, Deserialize)]
62-
pub struct InvokeDeleteProjectArgs {
63-
pub project: String,
62+
pub struct InvokeDeleteProjectArgs<'a> {
63+
pub project_name: &'a str,
6464
}
6565

6666
#[derive(Serialize, Deserialize)]
67-
pub struct InvokeInsertQueryArgs {
68-
pub key: String,
69-
pub sql: String,
67+
pub struct InvokeInsertQueryArgs<'a> {
68+
pub key: &'a str,
69+
pub sql: &'a str,
7070
}
7171

7272
#[derive(Serialize, Deserialize)]
7373
pub struct InvokeSelectQueriesArgs;
7474

7575
#[derive(Serialize, Deserialize)]
76-
pub struct InvokeDeleteQueryArgs {
77-
pub key: String,
76+
pub struct InvokeDeleteQueryArgs<'a> {
77+
pub key: &'a str,
7878
}

src/modals/custom_query.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
use leptos::{html::*, *};
22
use thaw::{Modal, ModalFooter, ModalProps};
33

4-
use crate::store::{projects::ProjectsStore, query::QueryStore};
4+
use crate::store::{
5+
active_project::ActiveProjectStore, projects::ProjectsStore, query::QueryStore,
6+
};
57

68
pub fn component(show: RwSignal<bool>) -> impl IntoView {
79
let projects_store = use_context::<ProjectsStore>().unwrap();
810
let query_store = use_context::<QueryStore>().unwrap();
911
let (query_title, set_query_title) = create_signal(String::new());
1012
let projects = create_memo(move |_| projects_store.get_projects().unwrap());
11-
let (project, set_project) = create_signal(String::new());
13+
let active_project = use_context::<ActiveProjectStore>().unwrap();
14+
let (project_name, set_project_name) =
15+
create_signal(active_project.0.get_untracked().unwrap_or_default());
16+
create_effect(move |_| {
17+
if !projects.get().is_empty() {
18+
set_project_name(projects.get()[0].clone());
19+
}
20+
});
21+
1222
let insert_query = create_action(
13-
move |(query_db, key, project): &(QueryStore, String, String)| {
23+
move |(query_db, key, project_name): &(QueryStore, String, String)| {
1424
let query_db_clone = *query_db;
1525
let key = key.clone();
16-
let project = project.clone();
26+
let project_name = project_name.clone();
1727
async move {
18-
query_db_clone.insert_query(&key, &project).await.unwrap();
28+
query_db_clone
29+
.insert_query(&key, &project_name)
30+
.await
31+
.unwrap();
1932
}
2033
},
2134
);
@@ -29,18 +42,21 @@ pub fn component(show: RwSignal<bool>) -> impl IntoView {
2942
.child(
3043
select()
3144
.classes("border-1 border-neutral-200 p-1 rounded-md w-full bg-white appearance-none")
45+
.prop("value", project_name)
46+
.prop("default_value", "teszt")
47+
.prop("placeholder", "Select project..")
3248
.child(For(ForProps {
3349
each: move || projects.get(),
3450
key: |project| project.clone(),
3551
children: move |p| {
3652
option()
3753
.prop("value", &p)
38-
.prop("selected", p == project())
54+
.prop("selected", project_name() == p)
3955
.child(&p)
4056
},
4157
}))
4258
.on(ev::change, move |e| {
43-
set_project(event_target_value(&e));
59+
set_project_name(event_target_value(&e));
4460
}),
4561
)
4662
.child(
@@ -63,7 +79,7 @@ pub fn component(show: RwSignal<bool>) -> impl IntoView {
6379
button()
6480
.classes("px-4 py-2 border-1 border-neutral-200 hover:bg-neutral-200 rounded-md")
6581
.on(ev::click, move |_| {
66-
insert_query.dispatch((query_store, query_title(), project()));
82+
insert_query.dispatch((query_store, query_title(), project_name()));
6783
show.set(false);
6884
})
6985
.child("Save"),

0 commit comments

Comments
 (0)