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

Method get_or_load

src/cache/schema.rs:249–278  ·  view source on GitHub ↗

Get table schema with automatic preloading on first access

(&self, conn: &Connection, table_name: &str)

Source from the content-addressed store, hash-verified

247
248 /// Get table schema with automatic preloading on first access
249 pub fn get_or_load(&self, conn: &Connection, table_name: &str) -> Result<TableSchema, rusqlite::Error> {
250 // Try cache first
251 if let Some(schema) = self.get(table_name) {
252 return Ok(schema);
253 }
254
255 // If all tables haven't been loaded yet, do bulk preload
256 if !*self.all_tables_loaded.read().unwrap() {
257 self.preload_all_schemas(conn)?;
258
259 // Try cache again after preload
260 if let Some(schema) = self.get(table_name) {
261 return Ok(schema);
262 }
263 }
264
265 // If still not found, load this specific table
266 let schema = self.load_table_schema_direct(conn, table_name)?;
267 self.insert(table_name.to_string(), schema.clone());
268
269 // Check for decimal columns and update bloom filter
270 let has_decimal = schema.columns.iter().any(|col| {
271 col.pg_type == "numeric" || col.pg_oid == PgType::Numeric.to_oid()
272 });
273 if has_decimal {
274 self.decimal_tables.write().unwrap().insert(table_name.to_string());
275 }
276
277 Ok(schema)
278 }
279
280 /// Ensure schema is loaded for tables referenced in a query
281 pub fn ensure_schema_loaded(&self, conn: &Connection, query: &str) {

Callers 5

get_table_schemaMethod · 0.80
query_fast_pathFunction · 0.80
execute_fast_selectFunction · 0.80

Calls 7

readMethod · 0.80
preload_all_schemasMethod · 0.80
to_oidMethod · 0.80
getMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected