Skip to content

Commit c126636

Browse files
committed
fix: pgsql connection string
1 parent 4ffed93 commit c126636

File tree

10 files changed

+70
-13
lines changed

10 files changed

+70
-13
lines changed

src-tauri/src/drivers/pgsql.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{utils::reflective_get, AppState};
1313
#[tauri::command(rename_all = "snake_case")]
1414
pub async fn pgsql_connector(
1515
project_id: &str,
16-
key: Option<[&str; 4]>,
16+
key: Option<[&str; 5]>,
1717
app: AppHandle,
1818
) -> Result<ProjectConnectionStatus> {
1919
let app_state = app.state::<AppState>();
@@ -27,8 +27,8 @@ pub async fn pgsql_connector(
2727

2828
let key = match key {
2929
Some(key) => format!(
30-
"user={} password={} host={} port={}",
31-
key[0], key[1], key[2], key[3]
30+
"postgresql://{}:{}@{}:{}/{}",
31+
key[0], key[1], key[3], key[4], key[2]
3232
),
3333
None => {
3434
let projects_db = app_state.project_db.lock().await;
@@ -39,8 +39,12 @@ pub async fn pgsql_connector(
3939
_ => Vec::new(),
4040
};
4141
let project_details = format!(
42-
"user={} password={} host={} port={}",
43-
project_details[1], project_details[2], project_details[3], project_details[4]
42+
"postgresql://{}:{}@{}:{}/{}",
43+
project_details[1],
44+
project_details[2],
45+
project_details[4],
46+
project_details[5],
47+
project_details[3],
4448
);
4549
project_details
4650
}

src/dashboard/query_editor.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn QueryEditor(index: usize) -> impl IntoView {
2626
let active_project = move || tabs_store.selected_projects.get().get(index).cloned();
2727
let projects_store = expect_context::<ProjectsStore>();
2828
let project_driver = projects_store.select_driver_by_project(active_project().as_deref());
29+
let project_database = projects_store.select_database_by_project(active_project().as_deref());
2930
let tabs_store_rc = Rc::new(RefCell::new(tabs_store));
3031
let show = create_rw_signal(false);
3132
let _ = use_event_listener(use_document(), ev::keydown, move |event| {
@@ -92,6 +93,7 @@ pub fn QueryEditor(index: usize) -> impl IntoView {
9293
show=show
9394
project_id=active_project().unwrap()
9495
driver=project_driver
96+
database=project_database.to_owned()
9597
/>
9698
<div class="appearance-auto py-1 px-2 border-1 border-neutral-200 bg-white hover:bg-neutral-200 rounded-md">
9799
{active_project}

src/databases/pgsql/driver.rs

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct Pgsql<'a> {
2626
pub project_id: RwSignal<String>,
2727
user: Option<&'a str>,
2828
password: Option<&'a str>,
29+
database: Option<&'a str>,
2930
host: Option<&'a str>,
3031
port: Option<&'a str>,
3132
pub status: RwSignal<ProjectConnectionStatus>,
@@ -42,6 +43,7 @@ impl<'a> Pgsql<'a> {
4243
tables: RwSignal::default(),
4344
user: None,
4445
password: None,
46+
database: None,
4547
host: None,
4648
port: None,
4749
}
@@ -58,6 +60,7 @@ impl<'a> Pgsql<'a> {
5860
key: Some([
5961
self.user.unwrap(),
6062
self.password.unwrap(),
63+
self.database.unwrap(),
6164
self.host.unwrap(),
6265
self.port.unwrap(),
6366
]),
@@ -156,11 +159,13 @@ impl<'a> Pgsql<'a> {
156159
&mut self,
157160
user: &'a str,
158161
password: &'a str,
162+
database: &'a str,
159163
host: &'a str,
160164
port: &'a str,
161165
) {
162166
self.user = Some(user);
163167
self.password = Some(password);
168+
self.database = Some(database);
164169
self.host = Some(host);
165170
self.port = Some(port);
166171
}
@@ -171,6 +176,7 @@ impl<'a> Pgsql<'a> {
171176
prev.project_id = self.project_id.get().clone();
172177
prev.user = self.user.unwrap().to_string();
173178
prev.password = self.password.unwrap().to_string();
179+
prev.database = self.database.unwrap().to_string();
174180
prev.host = self.host.unwrap().to_string();
175181
prev.port = self.port.unwrap().to_string();
176182
});

src/databases/pgsql/index.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn Pgsql(project_id: String) -> impl IntoView {
2626
&project_details[2],
2727
&project_details[3],
2828
&project_details[4],
29+
&project_details[5],
2930
);
3031
}
3132
let show = create_rw_signal(false);

src/invoke.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl AsRef<str> for Invoke {
6262
#[derive(Serialize, Deserialize)]
6363
pub struct InvokePgsqlConnectorArgs<'a> {
6464
pub project_id: &'a str,
65-
pub key: Option<[&'a str; 4]>,
65+
pub key: Option<[&'a str; 5]>,
6666
}
6767

6868
#[derive(Serialize, Deserialize)]

src/modals/add_custom_query.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,32 @@ use thaw::{Modal, ModalFooter};
77
use crate::store::queries::QueriesStore;
88

99
#[component]
10-
pub fn AddCustomQuery(show: RwSignal<bool>, project_id: String, driver: Drivers) -> impl IntoView {
10+
pub fn AddCustomQuery(
11+
show: RwSignal<bool>,
12+
project_id: String,
13+
driver: Drivers,
14+
database: String,
15+
) -> impl IntoView {
1116
let project_id = Rc::new(project_id);
1217
let project_id_clone = project_id.clone();
1318
let query_store = expect_context::<QueriesStore>();
1419
let (title, set_title) = create_signal(String::new());
1520
let insert_query = create_action(
16-
move |(query_db, project_id, title, driver): &(QueriesStore, String, String, Drivers)| {
21+
move |(query_db, project_id, title, driver, database): &(
22+
QueriesStore,
23+
String,
24+
String,
25+
Drivers,
26+
String,
27+
)| {
1728
let query_db_clone = *query_db;
1829
let project_id = project_id.clone();
1930
let title = title.clone();
2031
let driver = *driver;
32+
let database = database.clone();
2133
async move {
2234
query_db_clone
23-
.insert_query(&project_id, &title, &driver)
35+
.insert_query(&project_id, &title, &driver, &database)
2436
.await;
2537
}
2638
},
@@ -45,9 +57,16 @@ pub fn AddCustomQuery(show: RwSignal<bool>, project_id: String, driver: Drivers)
4557
class="px-4 py-2 border-1 border-neutral-200 hover:bg-neutral-200 rounded-md"
4658
on:click={
4759
let project_id = project_id.clone();
60+
let database = database.clone();
4861
move |_| {
4962
insert_query
50-
.dispatch((query_store, project_id.to_string(), title(), driver));
63+
.dispatch((
64+
query_store,
65+
project_id.to_string(),
66+
title(),
67+
driver,
68+
database.to_string(),
69+
));
5170
show.set(false);
5271
}
5372
}

src/modals/add_pgsql_connection.rs

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ pub fn AddPgsqlConnection(show: RwSignal<bool>) -> impl IntoView {
4949
on:input=move |e| params.update(|p| p.password = event_target_value(&e))
5050
/>
5151

52+
<input
53+
class="border-1 border-neutral-200 p-1 rounded-md"
54+
type="text"
55+
value=params.get().database
56+
placeholder="database"
57+
on:input=move |e| params.update(|p| p.database = event_target_value(&e))
58+
/>
59+
5260
<input
5361
class="border-1 border-neutral-200 p-1 rounded-md"
5462
type="text"
@@ -79,6 +87,7 @@ pub fn AddPgsqlConnection(show: RwSignal<bool>) -> impl IntoView {
7987
params.get().driver.to_string(),
8088
params.get().user,
8189
params.get().password,
90+
params.get().database,
8291
params.get().host,
8392
params.get().port,
8493
],

src/store/atoms.rs

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub struct PgsqlConnectionDetailsAtom {
3939
pub driver: Drivers,
4040
pub user: String,
4141
pub password: String,
42+
pub database: String,
4243
pub host: String,
4344
pub port: String,
4445
}
@@ -50,6 +51,7 @@ impl Default for PgsqlConnectionDetailsAtom {
5051
driver: Drivers::PGSQL,
5152
user: String::new(),
5253
password: String::new(),
54+
database: String::new(),
5355
host: String::new(),
5456
port: String::new(),
5557
}

src/store/projects.rs

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ impl ProjectsStore {
5050
}
5151
}
5252

53+
pub fn select_database_by_project(&self, project_id: Option<&str>) -> String {
54+
if project_id.is_none() {
55+
return String::new();
56+
}
57+
58+
let project = self.select_project_by_name(project_id.unwrap()).unwrap();
59+
project.get(3).unwrap().clone()
60+
}
61+
5362
pub async fn load_projects(&self) {
5463
let projects =
5564
invoke::<_, BTreeMap<String, Vec<String>>>(Invoke::ProjectDbSelect.as_ref(), &())

src/store/queries.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use super::tabs::TabsStore;
1414
#[derive(Clone, Copy, Debug)]
1515
pub struct QueriesStore(pub RwSignal<BTreeStore>);
1616

17-
1817
impl Deref for QueriesStore {
1918
type Target = RwSignal<BTreeStore>;
2019

@@ -44,13 +43,19 @@ impl QueriesStore {
4443
});
4544
}
4645

47-
pub async fn insert_query(&self, project_id: &str, title: &str, driver: &Drivers) {
46+
pub async fn insert_query(
47+
&self,
48+
project_id: &str,
49+
title: &str,
50+
driver: &Drivers,
51+
database: &str,
52+
) {
4853
let tabs_store = expect_context::<TabsStore>();
4954
let sql = tabs_store.select_active_editor_value();
5055
let _ = invoke::<_, ()>(
5156
Invoke::QueryDbInsert.as_ref(),
5257
&InvokeQueryDbInsertArgs {
53-
query_id: &format!("{}:{}:{}", project_id, driver, title),
58+
query_id: &format!("{}:{}:{}:{}", project_id, database, driver, title),
5459
sql: &sql,
5560
},
5661
)

0 commit comments

Comments
 (0)