#[cfg(feature = "diesel")]
pub(in crate) mod diesel;
mod error;
use crate::paging::Paging;
#[cfg(feature = "diesel")]
pub use self::diesel::{DieselConnectionSchemaStore, DieselSchemaStore};
pub use error::SchemaStoreError;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Schema {
pub name: String,
pub description: String,
pub owner: String,
pub properties: Vec<PropertyDefinition>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub service_id: Option<String>,
pub start_commit_num: i64,
pub end_commit_num: i64,
pub last_updated: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PropertyDefinition {
pub start_commit_num: i64,
pub end_commit_num: i64,
pub name: String,
pub schema_name: String,
pub data_type: String,
pub required: bool,
pub description: String,
pub number_exponent: i64,
pub enum_options: Vec<String>,
pub struct_properties: Vec<PropertyDefinition>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub service_id: Option<String>,
}
#[derive(Clone, Debug)]
pub struct SchemaList {
pub data: Vec<Schema>,
pub paging: Paging,
}
impl SchemaList {
pub fn new(data: Vec<Schema>, paging: Paging) -> Self {
Self { data, paging }
}
}
pub trait SchemaStore {
fn add_schema(&self, schema: Schema) -> Result<(), SchemaStoreError>;
fn get_schema(
&self,
name: &str,
service_id: Option<&str>,
) -> Result<Option<Schema>, SchemaStoreError>;
fn list_schemas(
&self,
service_id: Option<&str>,
offset: i64,
limit: i64,
) -> Result<SchemaList, SchemaStoreError>;
fn list_property_definitions(
&self,
service_id: Option<&str>,
) -> Result<Vec<PropertyDefinition>, SchemaStoreError>;
fn list_property_definitions_with_schema_name(
&self,
schema_name: &str,
service_id: Option<&str>,
) -> Result<Vec<PropertyDefinition>, SchemaStoreError>;
fn get_property_definition_by_name(
&self,
schema_name: &str,
definition_name: &str,
service_id: Option<&str>,
) -> Result<Option<PropertyDefinition>, SchemaStoreError>;
}
impl<SS> SchemaStore for Box<SS>
where
SS: SchemaStore + ?Sized,
{
fn add_schema(&self, schema: Schema) -> Result<(), SchemaStoreError> {
(**self).add_schema(schema)
}
fn get_schema(
&self,
name: &str,
service_id: Option<&str>,
) -> Result<Option<Schema>, SchemaStoreError> {
(**self).get_schema(name, service_id)
}
fn list_schemas(
&self,
service_id: Option<&str>,
offset: i64,
limit: i64,
) -> Result<SchemaList, SchemaStoreError> {
(**self).list_schemas(service_id, offset, limit)
}
fn list_property_definitions(
&self,
service_id: Option<&str>,
) -> Result<Vec<PropertyDefinition>, SchemaStoreError> {
(**self).list_property_definitions(service_id)
}
fn list_property_definitions_with_schema_name(
&self,
schema_name: &str,
service_id: Option<&str>,
) -> Result<Vec<PropertyDefinition>, SchemaStoreError> {
(**self).list_property_definitions_with_schema_name(schema_name, service_id)
}
fn get_property_definition_by_name(
&self,
schema_name: &str,
definition_name: &str,
service_id: Option<&str>,
) -> Result<Option<PropertyDefinition>, SchemaStoreError> {
(**self).get_property_definition_by_name(schema_name, definition_name, service_id)
}
}