feat(query): display total row count in result status bar
Execute COUNT query asynchronously after main query to show total matching rows. Strip user-supplied LIMIT/OFFSET from count SQL so the total reflects all rows, not just the limited page.
This commit is contained in:
1 parent
e15e99aeb5
commit
539faef23d
8 files changed
+43
-1
No files matched your search
@@ -1,9 +1,15 @@
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use crate::models::connection::DatabaseType;
|
||||
use crate::sql::find_statement_at_cursor;
|
||||
use crate::sql_dialect::{quote_table_identifier, uses_fetch_first};
|
||||
|
||||
static LIMIT_OFFSET_STRIP_RE: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"(?i)(\s+LIMIT\s+\d+(\s+OFFSET\s+\d+)?|\s+OFFSET\s+\d+(\s+LIMIT\s+\d+)?|\s+OFFSET\s+\d+\s+ROWS?\s+FETCH\s+(?:FIRST|NEXT)\s+\d+\s+ROWS?\s+ONLY|\s+FETCH\s+(?:FIRST|NEXT)\s+\d+\s+ROWS?\s+ONLY)\s*$").unwrap()
|
||||
});
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct QuerySqlBuildResult {
|
||||
@@ -183,6 +189,8 @@ pub fn build_count_query_sql(options: CountQuerySqlOptions) -> QuerySqlBuildResu
|
||||
return err("unsupported");
|
||||
}
|
||||
|
||||
let statement = LIMIT_OFFSET_STRIP_RE.replace(&statement, "").to_string();
|
||||
|
||||
let alias = quote_table_identifier(options.database_type, "dbx_count");
|
||||
let wrapped_sql = if options.database_type == Some(DatabaseType::SqlServer) {
|
||||
sql_server_statement_for_derived_table(&statement)
|
||||
|
||||
Reference in new issue
Block a user