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

Method prepare_and_cache

src/cache/statement_pool.rs:73–100  ·  view source on GitHub ↗

Prepare a statement and cache its metadata for future use

(
        &self,
        conn: &'conn Connection,
        query: &str,
    )

Source from the content-addressed store, hash-verified

71
72 /// Prepare a statement and cache its metadata for future use
73 pub fn prepare_and_cache<'conn>(
74 &self,
75 conn: &'conn Connection,
76 query: &str,
77 ) -> Result<(Statement<'conn>, StatementMetadata), rusqlite::Error> {
78 // For batch INSERTs, use a normalized fingerprint for caching
79 let cache_key = if let Some(fingerprint) = Self::batch_insert_fingerprint(query) {
80 fingerprint
81 } else {
82 query.to_string()
83 };
84
85 // Check if we have cached metadata for this query
86 if let Some(metadata) = self.get_metadata(&cache_key) {
87 // We have metadata, prepare the statement with that info
88 let stmt = conn.prepare(query)?;
89 return Ok((stmt, metadata));
90 }
91
92 // First time seeing this query, prepare it and extract metadata
93 let stmt = conn.prepare(query)?;
94 let metadata = self.extract_metadata(&stmt, query)?;
95
96 // Cache the metadata
97 self.cache_metadata(cache_key, metadata.clone());
98
99 Ok((stmt, metadata))
100 }
101
102 /// Execute a cached statement with parameters
103 pub fn execute_cached<P: Params>(

Callers 3

execute_cachedMethod · 0.80
query_cachedMethod · 0.80

Calls 4

get_metadataMethod · 0.80
extract_metadataMethod · 0.80
cache_metadataMethod · 0.80
cloneMethod · 0.45

Tested by 1