Add function to fetch Grid Schema by name
Adds a function to fetch a single grid schema by name from the
database.
@@ -24,6 +24,7 @@ use diesel::{
dsl::{insert_into, update},
pg::PgConnection,
prelude::*,
+ result::Error::NotFound,
QueryResult,
};
@@ -99,3 +100,16 @@ pub fn list_grid_property_definitions(
.filter(grid_property_definition::end_block_num.eq(MAX_BLOCK_NUM))
.load::<GridPropertyDefinition>(conn)
}
+
+pub fn fetch_grid_schema(conn: &PgConnection, name: &str) -> QueryResult<Option<GridSchema>> {
+ grid_schema::table
+ .select(grid_schema::all_columns)
+ .filter(
+ grid_schema::name
+ .eq(name)
+ .and(grid_schema::end_block_num.eq(MAX_BLOCK_NUM)),
+ )
+ .first(conn)
+ .map(Some)
+ .or_else(|err| if err == NotFound { Ok(None) } else { Err(err) })
+}
