Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
# add rust nightly
container:
image: rust:latest
image: rustlang/rust:nightly

steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-sql-gui-ui"
version = "1.0.0-alpha.2"
version = "1.0.0-alpha.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -16,8 +16,9 @@ leptos_icons = { version = "0.1.0", features = ["HiBars4OutlineLg", "HiCircleSta
serde_json = "1.0.108"
wasm-bindgen-futures = "0.4.39"
monaco = "0.4.0"
# tauri = { version = "1.5.3", features = ["dialog"] }
thaw = "0.1.3"
common = { path = "common" }


[workspace]
members = ["src-tauri"]
members = ["src-tauri", "common"]
7 changes: 7 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "common"
version = "1.0.0-alpha.3"
edition = "2021"

[dependencies]
serde = "1.0.193"
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod project;
10 changes: 10 additions & 0 deletions common/src/project.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct ProjectDetails {
pub name: String,
pub user: String,
pub password: String,
pub host: String,
pub port: String,
}
64 changes: 0 additions & 64 deletions public/leptos.svg

This file was deleted.

6 changes: 0 additions & 6 deletions public/tauri.svg

This file was deleted.

3 changes: 2 additions & 1 deletion 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.2"
version = "1.0.0-alpha.3"
description = "PostgreSQL GUI written in Rust"
authors = ["you"]
license = ""
Expand All @@ -20,6 +20,7 @@ tokio = "1.34.0"
tokio-postgres = "0.7.10"
chrono = "0.4.31"
sled = "0.34.7"
common = { path = "../common" }



Expand Down
Binary file modified src-tauri/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/128x128@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square107x107Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square142x142Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square150x150Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square284x284Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square30x30Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square310x310Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square71x71Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square89x89Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/icon.icns
Binary file not shown.
Binary file modified src-tauri/icons/icon.ico
Binary file not shown.
Binary file modified src-tauri/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 5 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ mod utils;

use constant::{PROJECT_DB_PATH, QUERY_DB_PATH};
use postgres::{pg_connector, select_schema_tables, select_sql_result};
use project_db::{delete_project, select_project_details, select_projects};
use project_db::{delete_project, insert_project, select_projects};
use query_db::{delete_query, insert_query, select_queries};
use sled::Db;
use std::sync::Arc;
use std::{collections::BTreeMap, sync::Arc};
use tauri::Manager;
use tokio::sync::Mutex;
use tokio_postgres::Client;
use utils::create_or_open_local_db;

pub struct AppState {
pub connection_strings: Arc<Mutex<String>>,
pub client: Arc<Mutex<Option<Client>>>,
pub client: Arc<Mutex<Option<BTreeMap<String, Client>>>>,
pub project_db: Arc<Mutex<Option<Db>>>,
pub query_db: Arc<Mutex<Option<Db>>>,
}

impl Default for AppState {
fn default() -> Self {
Self {
connection_strings: Arc::new(Mutex::new(String::new())),
client: Arc::new(Mutex::new(None)),
client: Arc::new(Mutex::new(Some(BTreeMap::new()))),
project_db: Arc::new(Mutex::new(None)),
query_db: Arc::new(Mutex::new(None)),
}
Expand Down Expand Up @@ -64,10 +62,10 @@ fn main() {
.invoke_handler(tauri::generate_handler![
delete_project,
delete_query,
insert_project,
insert_query,
pg_connector,
select_projects,
select_project_details,
select_queries,
select_schema_tables,
select_sql_result,
Expand Down
17 changes: 9 additions & 8 deletions src-tauri/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ pub async fn pg_connector(project: &str, key: &str, app: AppHandle) -> Result<Ve
.await
.unwrap();
let schemas = schemas.iter().map(|r| r.get(0)).collect();

*app_state.connection_strings.lock().await = key.to_string();
*app_state.client.lock().await = Some(client);
let mut clients = app_state.client.lock().await;
let clients = clients.as_mut().unwrap();
clients.insert(project.to_string(), client);

Ok(schemas)
}

#[tauri::command]
pub async fn select_schema_tables(
project: &str,
schema: &str,
app_state: State<'_, AppState>,
) -> Result<Vec<(String, String)>> {
let client = app_state.client.lock().await;
let client = client.as_ref().unwrap();
let clients = app_state.client.lock().await;
let client = clients.as_ref().unwrap().get(project).unwrap();
let tables = client
.query(
r#"
Expand All @@ -70,12 +71,12 @@ pub async fn select_schema_tables(

#[tauri::command]
pub async fn select_sql_result(
project: &str,
sql: String,
app_state: State<'_, AppState>,
) -> Result<(Vec<String>, Vec<Vec<String>>)> {
let client = app_state.client.lock().await;
let client = client.as_ref().unwrap();

let clients = app_state.client.lock().await;
let client = clients.as_ref().unwrap().get(project).unwrap();
let rows = client.query(sql.as_str(), &[]).await.unwrap();

if rows.is_empty() {
Expand Down
82 changes: 41 additions & 41 deletions src-tauri/src/project_db.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
use serde::Serialize;
use common::project::ProjectDetails;
use tauri::{Result, State};

use crate::AppState;

#[derive(Default, Serialize)]
pub struct ProjectDetails {
pub user: String,
pub password: String,
pub host: String,
pub port: String,
}

#[tauri::command]
pub async fn select_projects(app_state: State<'_, AppState>) -> Result<Vec<String>> {
pub async fn select_projects(app_state: State<'_, AppState>) -> Result<Vec<ProjectDetails>> {
let project_db = app_state.project_db.lock().await;
let mut projects = project_db
.clone()
.unwrap()
.iter()
.map(|r| {
let (project, _) = r.unwrap();
String::from_utf8(project.to_vec()).unwrap()
let (project, connection_string) = r.unwrap();
let project = String::from_utf8(project.to_vec()).unwrap();
let connection_string = connection_string.to_vec();
let connection_string = String::from_utf8(connection_string).unwrap();
let connection_string = connection_string.split(' ').collect::<Vec<&str>>();

let mut project_details = ProjectDetails {
name: project,
..Default::default()
};

for connection_string in connection_string {
let connection_string = connection_string.split('=').collect::<Vec<&str>>();
let key = connection_string[0];
let value = connection_string[1];

match key {
"user" => project_details.user = value.to_string(),
"password" => project_details.password = value.to_string(),
"host" => project_details.host = value.to_string(),
"port" => project_details.port = value.to_string(),
_ => (),
}
}

project_details
})
.collect::<Vec<String>>();
projects.sort();
.collect::<Vec<ProjectDetails>>();
projects.sort_by(|a, b| a.name.cmp(&b.name));
Ok(projects)
}

#[tauri::command]
pub async fn select_project_details(
project: String,
pub async fn insert_project(
project: ProjectDetails,
app_state: State<'_, AppState>,
) -> Result<ProjectDetails> {
let db = app_state.project_db.lock().await;
let db = db.clone().unwrap();
let connection_string = db.get(project).unwrap();
let mut project_details = ProjectDetails::default();

if let Some(connection_string) = connection_string {
let connection_string = connection_string.to_vec();
let connection_string = String::from_utf8(connection_string).unwrap();
let connection_string = connection_string.split(' ').collect::<Vec<&str>>();

for connection_string in connection_string {
let connection_string = connection_string.split('=').collect::<Vec<&str>>();
let key = connection_string[0];
let value = connection_string[1];

match key {
"user" => project_details.user = value.to_string(),
"password" => project_details.password = value.to_string(),
"host" => project_details.host = value.to_string(),
"port" => project_details.port = value.to_string(),
_ => (),
}
}
}
Ok(project_details)
let project_db = app_state.project_db.lock().await;
let ref mut db = project_db.clone().unwrap();
let connection_string = format!(
"user={} password={} host={} port={}",
project.user, project.password, project.host, project.port,
);
db.insert(project.name.clone(), connection_string.as_str())
.unwrap();
Ok(project)
}

#[tauri::command]
Expand Down
7 changes: 0 additions & 7 deletions src-tauri/src/query_db.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
use std::collections::BTreeMap;

use serde::Serialize;
use tauri::{AppHandle, Manager, Result, State};

use crate::AppState;

#[derive(Default, Serialize)]
pub struct QueryDetails {
pub title: String,
pub sql: String,
}

#[tauri::command]
pub async fn insert_query(key: &str, sql: &str, app: AppHandle) -> Result<()> {
let app_state = app.state::<AppState>();
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "RSQL",
"version": "1.0.0-alpha.1"
"version": "1.0.0-alpha.3"
},
"tauri": {
"allowlist": {
Expand Down
23 changes: 14 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ use std::vec;

use crate::{
enums::QueryTableLayout,
layout::layout,
query_editor::query_editor,
query_table::query_table,
store::{db::DBStore, editor::EditorState, query::QueryState},
layout, query_editor, query_table,
store::{
active_project::ActiveProjectStore, editor::EditorStore, projects::ProjectsStore,
query::QueryStore,
},
};
use leptos::*;

pub fn app() -> impl IntoView {
provide_context(DBStore::default());
provide_context(EditorState::default());
provide_context(QueryState::default());
provide_context(EditorStore::default());
provide_context(QueryStore::default());
provide_context(ProjectsStore::default());
provide_context(create_rw_signal(QueryTableLayout::Grid));
provide_context(ActiveProjectStore::default());

layout(Children::to_children(move || {
Fragment::new(vec![query_editor().into_view(), query_table().into_view()])
layout::component(Children::to_children(move || {
Fragment::new(vec![
query_editor::component().into_view(),
query_table::component().into_view(),
])
}))
}
Loading