Registers an object in the catalog. Specifying `transient` as true allows the object to be deleted by [Self::remove_transient_objects]. Returns the GlobalId assigned by the catalog to the object. Errors if an object of the same name is already in the catalog.
(
&mut self,
name: &str,
cols: Vec<String>,
typ: SqlRelationType,
transient: bool,
)
| 33 | /// |
| 34 | /// Errors if an object of the same name is already in the catalog. |
| 35 | pub fn insert( |
| 36 | &mut self, |
| 37 | name: &str, |
| 38 | cols: Vec<String>, |
| 39 | typ: SqlRelationType, |
| 40 | transient: bool, |
| 41 | ) -> Result<GlobalId, String> { |
| 42 | if self.objects.contains_key(name) { |
| 43 | return Err(format!("Object {name} already exists in catalog")); |
| 44 | } |
| 45 | let id = if transient { |
| 46 | GlobalId::Transient(u64::cast_from(self.objects.len())) |
| 47 | } else { |
| 48 | GlobalId::User(u64::cast_from(self.objects.len())) |
| 49 | }; |
| 50 | self.objects.insert(name.to_string(), (id, cols, typ)); |
| 51 | self.names.insert(id, name.to_string()); |
| 52 | Ok(id) |
| 53 | } |
| 54 | |
| 55 | pub fn get(&'a self, name: &str) -> Option<&'a (GlobalId, Vec<String>, SqlRelationType)> { |
| 56 | self.objects.get(name) |
no test coverage detected