Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
30a8b45
feat: improve error handling
dancixx May 9, 2024
21df842
feat: add error modal
dancixx May 9, 2024
e995fb4
fix: connection error state
dancixx May 10, 2024
584d090
refactor: postgres driver
dancixx May 10, 2024
76923fb
refactor: local db-s
dancixx May 11, 2024
5a6f5d5
refactor: driver connection logic and performance
dancixx May 11, 2024
05f1535
feat: add conditional render based on driver
dancixx May 11, 2024
df2e27c
raefactor: schemas
dancixx May 11, 2024
e6b52bf
refactor: driver handling
dancixx May 12, 2024
a31e691
fix: add clippy fixes
dancixx May 12, 2024
86a7f54
refactor: table handling
dancixx May 12, 2024
3f3179b
feat: add db performance panel
dancixx May 12, 2024
e297a67
refactor: add better foldering
dancixx May 12, 2024
fd206c3
fix: remove sticky temporarly
dancixx May 12, 2024
4f372b6
refactor: activetab, selectedtab and qp state
dancixx May 12, 2024
e289098
refactor: tabs
dancixx May 18, 2024
daad8c3
refactor: tabs manager
dancixx May 18, 2024
24a2c2d
refactor: tabs
dancixx May 19, 2024
2160549
refactor: table default query
dancixx May 19, 2024
6540757
feat: add query performance history
dancixx May 19, 2024
74c13d0
chore: add some clippy fix
dancixx May 19, 2024
2388cc4
refactor: new tab addition
dancixx May 19, 2024
bdd9204
refactor: tabs handling
dancixx May 19, 2024
883f2a6
refactor: custom query loading
dancixx May 19, 2024
d30b9ed
refactor: finalize query store api
dancixx May 19, 2024
7ffb0fe
refactor: query loading
dancixx May 19, 2024
510921d
chore: bump version
dancixx May 19, 2024
e5a8334
feat: make queries more general
dancixx May 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "rust-sql-gui-ui"
version = "1.0.0-alpha.9"
name = "rsql"
version = "1.0.0-beta.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
leptos = { version = "0.6.8", features = ["csr", "nightly"] }
leptos = { version = "0.6.11", features = ["csr", "nightly"] }
leptos_devtools = { git = "https://github.com/luoxiaozero/leptos-devtools" }
serde = { version = "1.0.192", features = ["derive"] }
serde-wasm-bindgen = "0.6.3"
wasm-bindgen = { version ="0.2.91", features = ["serde-serialize"] }
js-sys = "0.3.68"
leptos-use = { version = "0.10.9", features = ["serde", "serde_json"]}
leptos-use = { version = "0.10.10", features = ["serde", "serde_json"]}
leptos_icons = "0.3.0" # https://carlosted.github.io/icondata/
serde_json = "1.0.113"
wasm-bindgen-futures = "0.4.39"
Expand All @@ -22,6 +22,16 @@ common = { path = "common" }
futures = "0.3.30"
async-stream = "0.3.5"
icondata = "0.3.0"
ahash = { version = "0.8.11", features = ["serde"] }
leptos_toaster = { version = "0.1.6", features = ["builtin_toast"] }
proc-macro2 = "1.0.82"
quote = "1.0.36"
syn = { version = "2.0.64", features = ["full"] }
chrono = "0.4.38"


[workspace]
members = ["src-tauri", "common"]

[lib]
proc-macro = true
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "common"
version = "1.0.0-alpha.9"
version = "1.0.0-beta.0"
edition = "2021"

[dependencies]
Expand Down
1 change: 0 additions & 1 deletion common/src/drivers/mod.rs

This file was deleted.

20 changes: 0 additions & 20 deletions common/src/drivers/postgresql.rs

This file was deleted.

59 changes: 49 additions & 10 deletions common/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,68 @@ use std::fmt::Display;

use serde::{Deserialize, Serialize};

use super::projects::postgresql::Postgresql;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Project {
POSTGRESQL(Postgresql),
}

#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Copy, Serialize, Deserialize, Default)]
pub enum Drivers {
POSTGRESQL,
#[default]
PGSQL,
}

impl Display for Drivers {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Drivers::POSTGRESQL => write!(f, "POSTGRESQL"),
Drivers::PGSQL => write!(f, "PGSQL"),
}
}
}

impl AsRef<str> for Drivers {
fn as_ref(&self) -> &str {
match self {
Drivers::PGSQL => "PGSQL",
}
}
}

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub enum ProjectConnectionStatus {
Connected,
Connecting,
#[default]
Disconnected,
Failed,
}

impl std::error::Error for ProjectConnectionStatus {}
impl Display for ProjectConnectionStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ProjectConnectionStatus::Connected => write!(f, "Connected"),
ProjectConnectionStatus::Connecting => write!(f, "Connecting"),
ProjectConnectionStatus::Disconnected => write!(f, "Disconnected"),
ProjectConnectionStatus::Failed => write!(f, "Failed"),
}
}
}

use std::fmt;

#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub enum PostgresqlError {
ConnectionTimeout,
ConnectionError,
QueryTimeout,
QueryError,
}

impl std::error::Error for PostgresqlError {}
impl fmt::Display for PostgresqlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
PostgresqlError::ConnectionTimeout => write!(f, "ConnectionTimeout"),
PostgresqlError::ConnectionError => write!(f, "ConnectionError"),
PostgresqlError::QueryTimeout => write!(f, "QueryTimeout"),
PostgresqlError::QueryError => write!(f, "QueryError"),
}
}
}

4 changes: 2 additions & 2 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod drivers;
pub mod enums;
pub mod projects;
pub mod types;

1 change: 0 additions & 1 deletion common/src/projects/mod.rs

This file was deleted.

36 changes: 0 additions & 36 deletions common/src/projects/postgresql.rs

This file was deleted.

2 changes: 2 additions & 0 deletions common/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod pgsql;

4 changes: 4 additions & 0 deletions common/src/types/pgsql.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub type PgsqlLoadSchemas = Vec<String>;
pub type PgsqlLoadTables = Vec<(String, String)>;
pub type PgsqlRunQuery = (Vec<String>, Vec<Vec<String>>, f32);

14 changes: 9 additions & 5 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-sql-gui"
version = "1.0.0-alpha.9"
name = "rsql_tauri"
version = "1.0.0-beta.0"
description = "PostgreSQL GUI written in Rust"
authors = ["Daniel Boros"]
license = ""
Expand All @@ -10,17 +10,21 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = { version = "1.5.1", features = [] }
tauri-build = { version = "1.5.2", features = [] }

[dependencies]
common = { path = "../common" }
tauri = { version = "1.6.0", features = [ "shell-open", "fs-all"] }
tauri = { version = "1.6.5", features = ["shell-open", "fs-all"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
tokio = "1.36.0"
tokio = "1.37.0"
tokio-postgres = "0.7.10"
chrono = "0.4.31"
sled = "0.34.7"
anyhow = "1.0.83"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
ahash = { version = "0.8.11", features = ["serde"] }



Expand Down
85 changes: 27 additions & 58 deletions src-tauri/src/dbs/project.rs
Original file line number Diff line number Diff line change
@@ -1,80 +1,49 @@
use common::{
drivers::postgresql::Postgresql as PostgresqlDriver,
enums::{Drivers, Project},
projects::postgresql::Postgresql,
};
use std::collections::BTreeMap;

use tauri::{Result, State};

use crate::AppState;

#[tauri::command(rename_all = "snake_case")]
pub async fn select_projects(app_state: State<'_, AppState>) -> Result<Vec<(String, Project)>> {
pub async fn project_db_select(app_state: State<'_, AppState>) -> Result<BTreeMap<String, String>> {
let project_db = app_state.project_db.lock().await;
let mut projects = project_db
.clone()
.unwrap()
.iter()
.map(|r| {
let (project, connection_string) = r.unwrap();
let project = String::from_utf8(project.to_vec()).unwrap();
let connection_string = String::from_utf8(connection_string.to_vec()).unwrap();
let connection_string = connection_string.split(':').collect::<Vec<&str>>();
let _driver = connection_string[0].to_string();
let _driver = _driver.split('=').collect::<Vec<&str>>()[1];
let project_details = match _driver {
d if d == Drivers::POSTGRESQL.to_string() => {
let mut driver = PostgresqlDriver::default();
let db = project_db.clone().unwrap();
let mut projects = BTreeMap::new();

for c in connection_string[1..].iter() {
let c = c.split('=').collect::<Vec<&str>>();
let key = c[0];
let value = c[1];
if db.is_empty() {
tracing::info!("No projects found in the database");
return Ok(projects);
}

match key {
"user" => driver.user = value.to_string(),
"password" => driver.password = value.to_string(),
"host" => driver.host = value.to_string(),
"port" => driver.port = value.to_string(),
_ => (),
}
}
for p in db.iter() {
let project = p.unwrap();

Project::POSTGRESQL(Postgresql {
name: project.clone(),
driver,
..Postgresql::default()
})
}
_ => unreachable!(),
};
(project, project_details)
})
.collect::<Vec<(String, Project)>>();
projects.sort_by(|a, b| a.0.cmp(&b.0));
let project = (
String::from_utf8(project.0.to_vec()).unwrap(),
String::from_utf8(project.1.to_vec()).unwrap(),
);
projects.insert(project.0, project.1);
}
Ok(projects)
}

#[tauri::command(rename_all = "snake_case")]
pub async fn insert_project(project: Project, app_state: State<'_, AppState>) -> Result<Project> {
pub async fn project_db_insert(
project_id: &str,
project_details: &str,
app_state: State<'_, AppState>,
) -> Result<()> {
let project_db = app_state.project_db.lock().await;
let db = project_db.clone().unwrap();
match project {
Project::POSTGRESQL(project) => {
let driver = &project.driver;
let connection_string = format!(
"driver=POSTGRESQL:user={}:password={}:host={}:port={}",
driver.user, driver.password, driver.host, driver.port,
);
db.insert(&project.name, &*connection_string).unwrap();
Ok(Project::POSTGRESQL(project))
}
}
db.insert(project_id, project_details).unwrap();
Ok(())
}

#[tauri::command(rename_all = "snake_case")]
pub async fn delete_project(project_name: &str, app_state: State<'_, AppState>) -> Result<()> {
pub async fn project_db_delete(project_id: &str, app_state: State<'_, AppState>) -> Result<()> {
let db = app_state.project_db.lock().await;
let db = db.clone().unwrap();
db.remove(project_name).unwrap();
db.remove(project_id).unwrap();
Ok(())
}

27 changes: 14 additions & 13 deletions src-tauri/src/dbs/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@ use tauri::{AppHandle, Manager, Result, State};
use crate::AppState;

#[tauri::command(rename_all = "snake_case")]
pub async fn insert_query(key: &str, sql: &str, app: AppHandle) -> Result<()> {
let app_state = app.state::<AppState>();
let db = app_state.query_db.lock().await;
if let Some(ref db_instance) = *db {
db_instance.insert(key, sql).unwrap();
}
Ok(())
}

#[tauri::command(rename_all = "snake_case")]
pub async fn select_queries(app_state: State<'_, AppState>) -> Result<BTreeMap<String, String>> {
pub async fn query_db_select(app_state: State<'_, AppState>) -> Result<BTreeMap<String, String>> {
let query_db = app_state.query_db.lock().await;
let mut queries = BTreeMap::new();
if let Some(ref query_db) = *query_db {
Expand All @@ -30,10 +20,21 @@ pub async fn select_queries(app_state: State<'_, AppState>) -> Result<BTreeMap<S
}

#[tauri::command(rename_all = "snake_case")]
pub async fn delete_query(key: &str, app_state: State<'_, AppState>) -> Result<()> {
pub async fn query_db_insert(query_id: &str, sql: &str, app: AppHandle) -> Result<()> {
let app_state = app.state::<AppState>();
let db = app_state.query_db.lock().await;
if let Some(ref db_instance) = *db {
db_instance.insert(query_id, sql).unwrap();
}
Ok(())
}

#[tauri::command(rename_all = "snake_case")]
pub async fn query_db_delete(query_id: &str, app_state: State<'_, AppState>) -> Result<()> {
let query_db = app_state.query_db.lock().await;
if let Some(ref query_db) = *query_db {
query_db.remove(key).unwrap();
query_db.remove(query_id).unwrap();
};
Ok(())
}

3 changes: 2 additions & 1 deletion src-tauri/src/drivers/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod postgresql;
pub mod pgsql;

Loading