fix(grid): Enter 键优先选中自动补全建议项 (closes #202)
WHERE 和 ORDER BY 输入框中,有自动补全建议显示时按 Enter 键 现在会选中当前高亮的建议项,而不是直接执行查询。
This commit is contained in:
parent
22453f9097
commit
9413df686e
|
|
@ -258,6 +258,15 @@ pub fn list_triggers(client: &DmClient, schema: &str, table: &str) -> Result<Vec
|
|||
.collect())
|
||||
}
|
||||
|
||||
pub fn execute_query_with_schema_sync(client: &DmClient, schema: &str, sql: &str) -> Result<QueryResult, String> {
|
||||
let set_schema = format!("SET SCHEMA \"{}\"", schema);
|
||||
client.conn.execute(&set_schema, (), None).map_err(|e| {
|
||||
log::error!("[dameng] set schema failed: {e}");
|
||||
e.to_string()
|
||||
})?;
|
||||
execute_query_sync(client, sql)
|
||||
}
|
||||
|
||||
pub fn execute_query_sync(client: &DmClient, sql: &str) -> Result<QueryResult, String> {
|
||||
let start = Instant::now();
|
||||
let sql = sql.trim().trim_end_matches(';');
|
||||
|
|
|
|||
|
|
@ -330,6 +330,15 @@ pub async fn list_triggers(conn: &OracleClient, schema: &str, table: &str) -> Re
|
|||
.collect())
|
||||
}
|
||||
|
||||
pub async fn execute_query_with_schema(conn: &OracleClient, schema: &str, sql: &str) -> Result<QueryResult, String> {
|
||||
let set_schema = format!("ALTER SESSION SET CURRENT_SCHEMA = \"{}\"", schema);
|
||||
conn.execute(&set_schema, &[]).await.map_err(|e| {
|
||||
log::error!("[oracle] set current_schema failed: {e}");
|
||||
e.to_string()
|
||||
})?;
|
||||
execute_query(conn, sql).await
|
||||
}
|
||||
|
||||
pub async fn execute_query(conn: &OracleClient, sql: &str) -> Result<QueryResult, String> {
|
||||
let start = Instant::now();
|
||||
let sql = sql.trim().trim_end_matches(';');
|
||||
|
|
|
|||
|
|
@ -191,6 +191,7 @@ pub async fn do_execute(
|
|||
}
|
||||
PoolKind::Oracle(pool) => {
|
||||
let client = pool.client();
|
||||
let schema = schema.map(|s| s.to_string());
|
||||
drop(connections);
|
||||
let client = match cancel_token.as_ref() {
|
||||
Some(token) => tokio::select! {
|
||||
|
|
@ -200,7 +201,13 @@ pub async fn do_execute(
|
|||
},
|
||||
None => client.lock().await,
|
||||
};
|
||||
wait_for_query(cancel_token, db::oracle_driver::execute_query(&*client, sql)).await.map(truncate_result)
|
||||
if let Some(schema) = schema {
|
||||
wait_for_query(cancel_token, db::oracle_driver::execute_query_with_schema(&*client, &schema, sql))
|
||||
.await
|
||||
.map(truncate_result)
|
||||
} else {
|
||||
wait_for_query(cancel_token, db::oracle_driver::execute_query(&*client, sql)).await.map(truncate_result)
|
||||
}
|
||||
}
|
||||
PoolKind::Elasticsearch(client) => {
|
||||
let client = client.clone();
|
||||
|
|
@ -215,11 +222,16 @@ pub async fn do_execute(
|
|||
PoolKind::Dameng(client) => {
|
||||
let client = client.clone();
|
||||
let sql = sql.to_string();
|
||||
let schema = schema.map(|s| s.to_string());
|
||||
drop(connections);
|
||||
wait_for_query(cancel_token, async move {
|
||||
let task = tokio::task::spawn_blocking(move || {
|
||||
let client = client.lock().map_err(|e| e.to_string())?;
|
||||
db::dm_driver::execute_query_sync(&client, &sql)
|
||||
if let Some(schema) = schema {
|
||||
db::dm_driver::execute_query_with_schema_sync(&client, &schema, &sql)
|
||||
} else {
|
||||
db::dm_driver::execute_query_sync(&client, &sql)
|
||||
}
|
||||
});
|
||||
task.await.map_err(|e| e.to_string())?
|
||||
})
|
||||
|
|
|
|||
|
|
@ -623,6 +623,10 @@ function onWhereFilterKeydown(e: KeyboardEvent) {
|
|||
}
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (whereSuggestions.value.length > 0) {
|
||||
acceptWhereSuggestion();
|
||||
return;
|
||||
}
|
||||
applyWhereFilter();
|
||||
}
|
||||
}
|
||||
|
|
@ -709,6 +713,10 @@ function onOrderByKeydown(e: KeyboardEvent) {
|
|||
}
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (orderBySuggestions.value.length > 0) {
|
||||
acceptOrderBySuggestion();
|
||||
return;
|
||||
}
|
||||
applyOrderBySearch();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue