-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
177 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,32 @@ | ||
// Prevents additional console window on Windows in release, DO NOT REMOVE!! | ||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] | ||
use query_noir::{database::database, state}; | ||
use query_noir::methods::connections::{add_connection, get_all_connections, delete_connection, update_connection}; | ||
use query_noir::{database::database, state, utils::init}; | ||
|
||
use state::{AppState, ServiceAccess}; | ||
use tauri::{AppHandle, Manager, State}; | ||
|
||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command | ||
#[tauri::command] | ||
fn greet(app_handle: AppHandle, name: &str) -> String { | ||
// Should handle errors instead of unwrapping here | ||
app_handle.db(|db| database::add_item(name, db)).unwrap(); | ||
|
||
let items = app_handle.db(|db| database::get_all(db)).unwrap(); | ||
|
||
let items_string = items.join(" | "); | ||
|
||
format!("Your name log: {}", items_string) | ||
} | ||
use state::AppState; | ||
use tauri::{Manager, State}; | ||
|
||
fn main() { | ||
tauri::Builder::default() | ||
.invoke_handler(tauri::generate_handler![greet]) | ||
.manage(AppState { | ||
db: Default::default(), | ||
}) | ||
.setup(|app| { | ||
init::init_app()?; | ||
let handle = app.handle(); | ||
|
||
let app_state: State<AppState> = handle.state(); | ||
let db = | ||
database::initialize_database(&handle).expect("Database initialize should succeed"); | ||
let db = database::initialize_database().expect("Database initialize should succeed"); | ||
*app_state.db.lock().unwrap() = Some(db); | ||
|
||
Ok(()) | ||
}) | ||
.invoke_handler(tauri::generate_handler![ | ||
add_connection, | ||
get_all_connections, | ||
delete_connection, | ||
update_connection, | ||
]) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
pub mod database; | ||
pub mod credentials; | ||
pub mod app; | ||
pub mod queries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use anyhow::Result; | ||
use rusqlite::{named_params, Connection}; | ||
|
||
use crate::methods::connections::{Credentials, DBConnection}; | ||
|
||
pub fn add_connection(conn: &DBConnection, db: &Connection) -> Result<()> { | ||
let mut statement = db.prepare("INSERT INTO connections (name, color, credentials, default_db, save_password, metadata) VALUES (:name, :color, :credentials, :default_db, :save_password, :metadata)")?; | ||
let credentials = serde_json::to_string(&conn.credentials)?; | ||
let metadata = serde_json::to_string(&conn.metadata)?; | ||
statement.execute(named_params! { | ||
":name": conn.name, | ||
":color": conn.color, | ||
":credentials": credentials, | ||
":default_db": conn.default_db, | ||
":save_password": conn.save_password, | ||
":metadata": metadata, | ||
})?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn update_connection(conn: &DBConnection, db: &Connection) -> Result<()> { | ||
let mut statement = db.prepare("INSERT INTO connections (name, color, credentials, default_db, save_password, metadata) VALUES (:name, :color, :credentials, :default_db, :save_password, :metadata) where id = :id")?; | ||
let credentials = serde_json::to_string(&conn.credentials)?; | ||
let metadata = serde_json::to_string(&conn.metadata)?; | ||
statement.execute(named_params! { | ||
":name": conn.name, | ||
":color": conn.color, | ||
":credentials": credentials, | ||
":default_db": conn.default_db, | ||
":save_password": conn.save_password, | ||
":metadata": metadata, | ||
":id": conn.id, | ||
})?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn delete_connection(conn: &DBConnection, db: &Connection) -> Result<()> { | ||
let mut statement = db.prepare("DELETE FROM connections where id = :id")?; | ||
statement.execute(named_params! {":id": conn.id})?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn get_all_connections(db: &Connection) -> Result<Vec<DBConnection>> { | ||
let mut statement = db.prepare("SELECT * FROM connections")?; | ||
let mut rows = statement.query([])?; | ||
let mut items = Vec::new(); | ||
while let Some(row) = rows.next()? { | ||
let credentials: String = row.get("credentials")?; | ||
let credentials: Credentials = serde_json::from_str(&credentials)?; | ||
let metadata: String = row.get("metadata")?; | ||
let metadata: Option<String> = serde_json::from_str(&metadata).ok(); | ||
|
||
items.push(DBConnection { | ||
id: row.get("id")?, | ||
name: row.get("name")?, | ||
color: row.get("color")?, | ||
credentials, | ||
default_db: row.get("default_db")?, | ||
save_password: row.get("save_password")?, | ||
metadata, | ||
}); | ||
} | ||
|
||
Ok(items) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod state; | ||
pub mod database; | ||
pub mod utils; | ||
pub mod methods; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::{database::queries, state}; | ||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use state::ServiceAccess; | ||
use tauri::AppHandle; | ||
|
||
pub struct DSN {} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Credentials { | ||
pub scheme: String, | ||
pub username: String, | ||
pub password: Option<String>, | ||
pub host: String, | ||
pub port: u16, | ||
pub dbname: String, | ||
pub params: Option<Vec<String>>, | ||
} | ||
|
||
pub struct DBConnection { | ||
pub id: u32, | ||
pub name: String, | ||
pub color: String, | ||
pub credentials: Credentials, | ||
pub default_db: String, | ||
pub save_password: bool, | ||
pub metadata: Option<String>, | ||
} | ||
|
||
pub fn add_connection(app_handle: AppHandle, conn: DBConnection) -> Result<()> { | ||
return app_handle.db(|db| queries::add_connection(&conn, db)); | ||
} | ||
|
||
pub fn get_all_connections(app_handle: AppHandle) -> Result<Vec<DBConnection>> { | ||
return app_handle.db(|db| queries::get_all_connections(db)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod connections; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
|
||
function Connections() { | ||
return ( | ||
<div>Connections</div> | ||
) | ||
} | ||
|
||
export default Connections |