diff --git a/src-tauri/src/database/connections.rs b/src-tauri/src/database/connections.rs index d17b50e..762496b 100644 --- a/src-tauri/src/database/connections.rs +++ b/src-tauri/src/database/connections.rs @@ -34,7 +34,7 @@ pub enum Dialect { } impl Dialect { - fn as_str(&self) -> &'static str { + pub fn as_str(&self) -> &'static str { match self { Dialect::Mysql => "mysql", Dialect::Postgres => "postgres", diff --git a/src-tauri/src/handlers/queries.rs b/src-tauri/src/handlers/queries.rs index d2c195e..cc12cd9 100644 --- a/src-tauri/src/handlers/queries.rs +++ b/src-tauri/src/handlers/queries.rs @@ -6,7 +6,7 @@ use crate::{ use anyhow::anyhow; use serde::{Deserialize, Serialize}; use serde_json::Value; -use sqlparser::dialect::GenericDialect; +use sqlparser::{dialect::dialect_from_str, parser::Parser}; use tauri::{command, AppHandle, State}; use tracing::info; @@ -19,20 +19,21 @@ pub async fn enqueue_query( _auto_limit: bool, ) -> CommandResult { info!(sql, conn_id, tab_id, "enqueue_query"); + let binding = async_state.connections.lock().await; + let conn = binding.get(&conn_id); + let dialect = conn.unwrap().config.dialect.as_str(); let statements: Result, Error> = - match sqlparser::parser::Parser::parse_sql(&GenericDialect {}, sql) { + match Parser::parse_sql(dialect_from_str(dialect).unwrap().as_ref(), sql) { Ok(statements) => Ok(statements.into_iter().map(|s| s.to_string()).collect()), Err(e) => Err(Error::from(e)), }; match statements { Ok(statements) => { - let binding = async_state.connections.lock().await; - let conn = binding.get(&conn_id); - let async_proc_input_tx = async_state.tasks.lock().await; if let Some(conn) = conn { - for statement in statements { - println!("Got statement {:?}", statement.to_string()); - let task = QueryTask::new(conn.clone(), &tab_id, &statement); + let async_proc_input_tx = async_state.tasks.lock().await; + for (idx, statement) in statements.iter().enumerate() { + info!("Got statement {:?}", statement.to_string()); + let task = QueryTask::new(conn.clone(), &tab_id, &statement, idx); let res = async_proc_input_tx.send(task.clone()).await; if let Err(e) = res { return Err(Error::from(e)); diff --git a/src-tauri/src/queues/query.rs b/src-tauri/src/queues/query.rs index 6a2a258..38f97cc 100644 --- a/src-tauri/src/queues/query.rs +++ b/src-tauri/src/queues/query.rs @@ -25,20 +25,22 @@ impl Default for QueryTaskStatus { pub struct QueryTask { pub conn: ConnectedConnection, pub query: String, - pub tab_number: String, + pub tab_id: String, pub id: String, pub status: QueryTaskStatus, + pub query_idx: usize, } impl QueryTask { - pub fn new(conn: ConnectedConnection, tab_number: &str, query: &str) -> Self { + pub fn new(conn: ConnectedConnection, tab_id: &str, query: &str, query_idx: usize) -> Self { let id = Uuid::new_v4(); QueryTask { conn, - tab_number: tab_number.to_string(), + tab_id: tab_id.to_string(), query: query.to_string(), id: id.to_string(), status: QueryTaskStatus::Queued, + query_idx, } } } @@ -64,28 +66,28 @@ pub async fn async_process_model( ) -> Result<(), Box> { while let Some(input) = input_rx.recv().await { let task = input; - // match task.conn.execute_query(task.query).await { - // Ok(_res) => { - // output_tx - // .send(QueryTaskResult { - // success: false, - // id: "asd".to_string(), - // path: "asd".to_string(), - // error: None, - // }) - // .await?; - // } - // Err(e) => { - // output_tx - // .send(QueryTaskResult { - // success: false, - // id: "asd".to_string(), - // path: "asd".to_string(), - // error: Some(e.to_string()), - // }) - // .await?; - // } - // } + match task.conn.execute_query(task.query).await { + Ok(_res) => { + output_tx + .send(QueryTaskResult { + success: false, + id: "asd".to_string(), + path: "asd".to_string(), + error: None, + }) + .await?; + } + Err(e) => { + output_tx + .send(QueryTaskResult { + success: false, + id: "asd".to_string(), + path: "asd".to_string(), + error: Some(e.to_string()), + }) + .await?; + } + } } Ok(()) }