Skip to content

Commit 877d25b

Browse files
committed
refactor(frontend,backend): enforce type over interface, async ConnectionManager, clippy fixes
Frontend: - Update ESLint config to enforce `type` over `interface` declarations - Auto-convert 40 `interface` usages to `type` across stores, components, types - Fix DataTableView.vue invoke call to use nested `query` object matching TableDataQuery struct Backend: - Migrate ConnectionManager from std::sync::RwLock to tokio::sync::RwLock for async compatibility - Make get_stats(), get_all_metadata(), get_connection_metadata() async - Rename update_stats_locked → update_stats_from_metadata - Refactor get_table_data command: 8 flat params → TableDataQuery struct (fixes clippy too_many_arguments) - Derive Default for SslMode with #[default] attribute - Remove unnecessary `as usize` casts in postgres.rs - Replace format!() with string literals for static SQL in mysql.rs - Auto-fix clippy: needless_borrows_for_generic_args, manual_map, new_without_default, redundant_closure Tests: - Update connection_manager_tests.rs to async API - Restore concurrent connection tests (test_concurrent_connections, test_concurrent_isolation_no_interference) - Fix integration tests: unused imports, missing ConnectionPool import, field name corrections
1 parent f74828e commit 877d25b

55 files changed

Lines changed: 1001 additions & 1177 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ export default antfu({
2525
'**/.tauri/**',
2626
'AGENTS.md',
2727
'docs/**',
28+
'src-tauri/gen/**',
2829
],
2930
rules: {
3031
'no-console': 'warn',
3132
'unused-imports/no-unused-vars': 'warn',
3233
'style/eol-last': ['error', 'always'],
34+
'ts/consistent-type-definitions': ['error', 'type'],
3335
},
3436
})

src-tauri/examples/mysql_usage.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
//! ```
1414
1515
use sqlkit_lib::database::{
16-
ConnectionConfig, DatabaseAdapter, DatabaseType, MySQLAdapter, PoolConfig, SslMode,
16+
ConnectionConfig, ConnectionPool, DatabaseAdapter, DatabaseType, MySQLAdapter, PoolConfig,
17+
SslMode,
1718
};
1819
use std::env;
1920
use std::time::Duration;
@@ -40,7 +41,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4041
max_connections: 10,
4142
connection_timeout: Duration::from_secs(30),
4243
max_lifetime: Duration::from_secs(1800), // 30 minutes
43-
idle_timeout: Duration::from_secs(600), // 10 minutes
44+
idle_timeout: Duration::from_secs(600), // 10 minutes
4445
};
4546

4647
// Create connection configuration
@@ -66,7 +67,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6667
println!("Server Version: {}", status.server_version.unwrap());
6768
println!(
6869
"Current Database: {}",
69-
status.current_database.unwrap_or_else(|| "None".to_string())
70+
status
71+
.current_database
72+
.unwrap_or_else(|| "None".to_string())
7073
);
7174
println!("Current User: {}\n", status.current_user.unwrap());
7275

src-tauri/examples/postgres_usage.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
//! - POSTGRES_DB (default: postgres)
1717
1818
use sqlkit_lib::database::{
19-
ConnectionConfig, DatabaseAdapter, DatabaseType, PoolConfig, PostgresAdapter, SslMode,
19+
ConnectionConfig, ConnectionPool, DatabaseAdapter, DatabaseType, PoolConfig, PostgresAdapter,
20+
SslMode,
2021
};
2122
use std::env;
2223
use std::time::Duration;
@@ -42,7 +43,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4243
max_connections: 10,
4344
connection_timeout: Duration::from_secs(30),
4445
max_lifetime: Duration::from_secs(1800), // 30 minutes
45-
idle_timeout: Duration::from_secs(600), // 10 minutes
46+
idle_timeout: Duration::from_secs(600), // 10 minutes
4647
};
4748

4849
// Build connection configuration
@@ -67,9 +68,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6768
println!("Testing connection...");
6869
let status = adapter.test_connection().await?;
6970
println!("✓ Connection Status:");
70-
println!(" - Server Version: {}", status.server_version.unwrap_or_default());
71-
println!(" - Current Database: {}", status.current_database.unwrap_or_default());
72-
println!(" - Current User: {}\n", status.current_user.unwrap_or_default());
71+
println!(
72+
" - Server Version: {}",
73+
status.server_version.unwrap_or_default()
74+
);
75+
println!(
76+
" - Current Database: {}",
77+
status.current_database.unwrap_or_default()
78+
);
79+
println!(
80+
" - Current User: {}\n",
81+
status.current_user.unwrap_or_default()
82+
);
7383

7484
// List databases
7585
println!("Listing databases...");
@@ -112,7 +122,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
112122
// Execute a simple query
113123
println!("Executing query: SELECT version()");
114124
let result = adapter.execute_query("SELECT version() as version").await?;
115-
println!("✓ Query executed in {}ms", result.execution_time_ms.unwrap_or(0));
125+
println!(
126+
"✓ Query executed in {}ms",
127+
result.execution_time_ms.unwrap_or(0)
128+
);
116129
if let Some(row) = result.rows.first() {
117130
if let Some(version) = row.get("version") {
118131
println!(" PostgreSQL Version: {:?}\n", version);
@@ -124,7 +137,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
124137
let result = adapter
125138
.execute_query("SELECT current_timestamp, current_user")
126139
.await?;
127-
println!("✓ Query executed in {}ms", result.execution_time_ms.unwrap_or(0));
140+
println!(
141+
"✓ Query executed in {}ms",
142+
result.execution_time_ms.unwrap_or(0)
143+
);
128144
println!(" Columns: {:?}", result.columns);
129145
println!(" Rows: {}\n", result.rows.len());
130146

@@ -138,7 +154,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
138154
'{"role": "admin", "active": true}'::jsonb as metadata
139155
"#;
140156
let result = adapter.execute_query(query).await?;
141-
println!("✓ Complex types query executed in {}ms", result.execution_time_ms.unwrap_or(0));
157+
println!(
158+
"✓ Complex types query executed in {}ms",
159+
result.execution_time_ms.unwrap_or(0)
160+
);
142161
if let Some(row) = result.rows.first() {
143162
println!(" Result contains: {:?}", row.keys().collect::<Vec<_>>());
144163
}

src-tauri/examples/sqlite_usage.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async fn file_based_example() -> Result<(), Box<dyn std::error::Error>> {
3535
let temp_dir = std::env::temp_dir();
3636
let db_path = temp_dir.join("example.db");
3737
let db_path_str = db_path.to_string_lossy().to_string();
38-
38+
3939
// Clean up any existing database
4040
let _ = fs::remove_file(&db_path);
4141
let _ = fs::remove_file(db_path.with_extension("db-wal"));
@@ -178,7 +178,7 @@ async fn metadata_example() -> Result<(), Box<dyn std::error::Error>> {
178178
let temp_dir = std::env::temp_dir();
179179
let db_path = temp_dir.join("metadata_example.db");
180180
let db_path_str = db_path.to_string_lossy().to_string();
181-
181+
182182
// Clean up
183183
let _ = fs::remove_file(&db_path);
184184
let _ = fs::remove_file(db_path.with_extension("db-wal"));
@@ -248,7 +248,11 @@ async fn metadata_example() -> Result<(), Box<dyn std::error::Error>> {
248248
" - {} ({}) {}{}",
249249
col.name,
250250
col.data_type,
251-
if col.is_primary_key { "PRIMARY KEY " } else { "" },
251+
if col.is_primary_key {
252+
"PRIMARY KEY "
253+
} else {
254+
""
255+
},
252256
if col.nullable { "NULL" } else { "NOT NULL" }
253257
);
254258
}
@@ -258,9 +262,7 @@ async fn metadata_example() -> Result<(), Box<dyn std::error::Error>> {
258262
.execute_query("INSERT INTO customers (name) VALUES ('John Doe'), ('Jane Smith')")
259263
.await?;
260264

261-
let table_info = adapter
262-
.get_table_info(None, None, "customers")
263-
.await?;
265+
let table_info = adapter.get_table_info(None, None, "customers").await?;
264266
println!("\n✓ Table info for 'customers':");
265267
println!(" - Name: {}", table_info.name);
266268
println!(" - Type: {}", table_info.table_type);

src-tauri/examples/sqlserver_usage.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! ```
1515
1616
use sqlkit_lib::database::{
17-
ConnectionConfig, DatabaseAdapter, DatabaseType, SqlServerAdapter, PoolConfig, SslMode,
17+
ConnectionConfig, DatabaseAdapter, DatabaseType, PoolConfig, SqlServerAdapter, SslMode,
1818
};
1919
use std::env;
2020
use std::time::Duration;
@@ -61,11 +61,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6161
let status = adapter.test_connection().await?;
6262
println!(
6363
"Server version: {}",
64-
status.server_version.unwrap_or_else(|| "Unknown".to_string())
64+
status
65+
.server_version
66+
.unwrap_or_else(|| "Unknown".to_string())
6567
);
6668
println!(
6769
"Current database: {}",
68-
status.current_database.unwrap_or_else(|| "Unknown".to_string())
70+
status
71+
.current_database
72+
.unwrap_or_else(|| "Unknown".to_string())
6973
);
7074
println!(
7175
"Current user: {}",
@@ -109,7 +113,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
109113

110114
// Example: Create a temporary table and query it
111115
println!("\n=== Example: Working with temporary tables ===");
112-
116+
113117
// Create table
114118
adapter
115119
.execute_query(
@@ -132,17 +136,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
132136
('charlie', 'charlie@example.com')",
133137
)
134138
.await?;
135-
println!(
136-
"Inserted {} rows",
137-
insert_result.rows_affected.unwrap_or(0)
138-
);
139+
println!("Inserted {} rows", insert_result.rows_affected.unwrap_or(0));
139140

140141
// Query data
141142
let result = adapter
142143
.execute_query("SELECT * FROM #demo_users ORDER BY id")
143144
.await?;
144145
println!("Query returned {} rows:", result.rows.len());
145-
println!("Execution time: {}ms", result.execution_time.unwrap_or(0));
146+
println!(
147+
"Execution time: {}ms",
148+
result.execution_time_ms.unwrap_or(0)
149+
);
146150

147151
// Display results
148152
for row in result.rows {
@@ -151,7 +155,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
151155

152156
// Example: Complex types
153157
println!("\n=== Example: Working with complex types ===");
154-
158+
155159
adapter
156160
.execute_query(
157161
"CREATE TABLE #demo_complex (
@@ -162,18 +166,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
162166
)",
163167
)
164168
.await?;
165-
169+
166170
adapter
167171
.execute_query(
168172
r#"INSERT INTO #demo_complex (xml_data, json_data) VALUES
169173
('<root><name>Test</name></root>', '{"type": "example", "status": "active"}')"#,
170174
)
171175
.await?;
172-
173-
let complex_result = adapter
174-
.execute_query("SELECT * FROM #demo_complex")
175-
.await?;
176-
176+
177+
let complex_result = adapter.execute_query("SELECT * FROM #demo_complex").await?;
178+
177179
println!("Complex types data:");
178180
for row in complex_result.rows {
179181
println!(" - XML: {:?}", row.get("xml_data"));

0 commit comments

Comments
 (0)