()
| 50 | |
| 51 | #[tokio::test] |
| 52 | async fn test_insert_performance_improvement() { |
| 53 | use pgsqlite::session::DbHandler; |
| 54 | use std::time::Instant; |
| 55 | |
| 56 | // Create in-memory database |
| 57 | let db = DbHandler::new(":memory:").expect("Failed to create database"); |
| 58 | |
| 59 | // Create a session |
| 60 | let session_id = Uuid::new_v4(); |
| 61 | db.create_session_connection(session_id).await.expect("Failed to create session connection"); |
| 62 | |
| 63 | // Create test table without decimal columns (should use fast path) |
| 64 | db.execute_with_session("CREATE TABLE test_table (id INTEGER, name TEXT)", &session_id).await.expect("Failed to create table"); |
| 65 | |
| 66 | // Test fast path INSERT performance |
| 67 | let start = Instant::now(); |
| 68 | for i in 0..100 { |
| 69 | let query = format!("INSERT INTO test_table (id, name) VALUES ({i}, 'test{i}')"); |
| 70 | db.execute_with_session(&query, &session_id).await.expect("Failed to execute INSERT"); |
| 71 | } |
| 72 | let duration = start.elapsed(); |
| 73 | |
| 74 | println!("100 INSERT operations (fast path) took: {duration:?}"); |
| 75 | println!("Average per INSERT: {:?}", duration / 100); |
| 76 | |
| 77 | // Verify data was inserted |
| 78 | let result = db.query_with_session("SELECT COUNT(*) FROM test_table", &session_id).await.expect("Failed to count rows"); |
| 79 | assert_eq!(result.rows.len(), 1); |
| 80 | |
| 81 | // The actual count should be 100 |
| 82 | if let Some(Some(count_bytes)) = result.rows[0].first() { |
| 83 | let count_str = String::from_utf8_lossy(count_bytes); |
| 84 | assert_eq!(count_str, "100"); |
| 85 | } |
| 86 | |
| 87 | // Clean up |
| 88 | db.remove_session_connection(&session_id); |
| 89 | } |
| 90 | |
| 91 | #[tokio::test] |
| 92 | async fn test_insert_with_decimal_columns_fallback() { |
nothing calls this directly
no test coverage detected