MCPcopy Create free account
hub / github.com/erans/pgsqlite / try_execute_fast_path_with_params

Method try_execute_fast_path_with_params

src/session/db_handler.rs:2307–2549  ·  view source on GitHub ↗

Try fast path execution with parameters

(
        &self,
        query: &str,
        params: &[rusqlite::types::Value],
        session_id: &Uuid,
    )

Source from the content-addressed store, hash-verified

2305
2306 /// Try fast path execution with parameters
2307 pub async fn try_execute_fast_path_with_params(
2308 &self,
2309 query: &str,
2310 params: &[rusqlite::types::Value],
2311 session_id: &Uuid,
2312 ) -> Result<Option<DbResponse>, PgSqliteError> {
2313
2314 // Detect query type before the closure
2315 let query_type = QueryTypeDetector::detect_query_type(query);
2316
2317 // Use the connection manager to get the session connection
2318 let result = self.connection_manager.execute_with_session(session_id, |conn| {
2319 // Execute the query directly with rusqlite parameters
2320 let mut stmt = conn.prepare(query)?;
2321
2322 let response: Result<DbResponse, rusqlite::Error> = match query_type {
2323 QueryType::Select => {
2324 let column_count = stmt.column_count();
2325 let mut column_names = Vec::with_capacity(column_count);
2326 for i in 0..column_count {
2327 column_names.push(sanitize_column_name(stmt.column_name(i).unwrap_or("")).to_string());
2328 }
2329
2330 // Build datetime column info for conversion
2331 let mut datetime_columns = std::collections::HashMap::new();
2332
2333 // Try to extract table name from query for schema lookup
2334 let table_name = FROM_TABLE_REGEX.as_ref()
2335 .ok()
2336 .and_then(|regex| regex.captures(query))
2337 .map(|captures| captures[1].to_string());
2338
2339
2340 // Look up column types for datetime conversion
2341 if let Some(ref table) = table_name {
2342 for (i, column_name) in column_names.iter().enumerate() {
2343 // Handle aliased columns by extracting the base column name
2344 let base_column_name = if column_name.contains("_") {
2345 // For aliased columns like "users_created_at", try to extract "created_at"
2346 if let Some(underscore_pos) = column_name.rfind('_') {
2347 &column_name[underscore_pos + 1..]
2348 } else {
2349 column_name
2350 }
2351 } else {
2352 column_name
2353 };
2354
2355 // Look up schema type
2356 let mut schema_stmt = conn.prepare(
2357 "SELECT pg_type FROM __pgsqlite_schema WHERE table_name = ?1 AND column_name = ?2"
2358 )?;
2359
2360 if let Ok(Some(pg_type)) = schema_stmt.query_row([table, base_column_name], |row| {
2361 row.get::<_, String>(0)
2362 }).optional() {
2363 if pg_type == "TIMESTAMP" || pg_type == "TIMESTAMP WITHOUT TIME ZONE" {
2364 datetime_columns.insert(i, "timestamp");

Callers

nothing calls this directly

Calls 10

sanitize_column_nameFunction · 0.85
format_days_to_dateFunction · 0.85
execute_with_sessionMethod · 0.45
insertMethod · 0.45
queryMethod · 0.45
getMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected