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

Method execute_with_session_cached

src/session/db_handler.rs:1935–1985  ·  view source on GitHub ↗

Execute with session-specific connection (with optional cached connection)

(
        &self,
        query: &str,
        session_id: &Uuid,
        cached_conn: Option<&Arc<parking_lot::Mutex<rusqlite::Connection>>>
    )

Source from the content-addressed store, hash-verified

1933
1934 /// Execute with session-specific connection (with optional cached connection)
1935 pub async fn execute_with_session_cached(
1936 &self,
1937 query: &str,
1938 session_id: &Uuid,
1939 cached_conn: Option<&Arc<parking_lot::Mutex<rusqlite::Connection>>>
1940 ) -> Result<DbResponse, PgSqliteError> {
1941 eprintln!("🗂️ execute_with_session_cached called, cached_conn: {}", cached_conn.is_some());
1942 match cached_conn {
1943 Some(conn) => {
1944 self.connection_manager.execute_with_cached_connection(conn, |conn| {
1945 // Process query with fast path optimization
1946 let processed_query = process_query(query, conn, &self.schema_cache)?;
1947
1948 let rows_affected = conn.execute(&processed_query, [])?;
1949
1950 // Handle CREATE TABLE metadata storage
1951 if query.trim_start().to_uppercase().starts_with("CREATE TABLE")
1952 && let Some(table_name) = extract_table_name_from_create(query) {
1953 // Get type mappings from CREATE TABLE translator
1954 use crate::translator::CreateTableTranslator;
1955 if let Ok(result) = CreateTableTranslator::translate_with_connection_full(query, Some(conn)) {
1956 if !result.type_mappings.is_empty() {
1957 // Store type mappings and numeric constraints
1958 if let Err(e) = self.store_create_table_metadata(conn, &table_name, &result.type_mappings) {
1959 debug!("Failed to store CREATE TABLE metadata: {}", e);
1960 }
1961 }
1962
1963 // Populate constraints for CREATE TABLE statements
1964 if let Err(e) = crate::catalog::constraint_populator::populate_constraints_for_table(conn, &table_name) {
1965 // Log the error but don't fail the CREATE TABLE operation
1966 debug!("Failed to populate constraints for table {}: {}", table_name, e);
1967 } else {
1968 debug!("Successfully populated constraint catalog tables for table: {}", table_name);
1969 }
1970 }
1971 }
1972
1973 Ok(DbResponse {
1974 columns: vec![],
1975 rows: vec![],
1976 rows_affected,
1977 })
1978 })
1979 }
1980 None => {
1981 // Fall back to regular lookup
1982 self.execute_with_session(query, session_id).await
1983 }
1984 }
1985 }
1986
1987 /// Execute with session-specific connection
1988 pub async fn execute_with_session(&self, query: &str, session_id: &Uuid) -> Result<DbResponse, PgSqliteError> {

Callers 8

execute_dmlMethod · 0.80
execute_ddlMethod · 0.80
execute_genericMethod · 0.80
execute_dmlMethod · 0.80
execute_ddlMethod · 0.80
execute_genericMethod · 0.80

Calls 8

process_queryFunction · 0.50
executeMethod · 0.45
is_emptyMethod · 0.45
execute_with_sessionMethod · 0.45

Tested by

no test coverage detected