Get table schema with automatic preloading on first access
(&self, conn: &Connection, table_name: &str)
| 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) { |
no test coverage detected