pub trait PersistentDataStore: Send + Sync {
// Required methods
fn init(
&mut self,
all_data: AllData<SerializedItem, SerializedItem>,
) -> Result<(), PersistentStoreError>;
fn flag(
&self,
key: &str,
) -> Result<Option<SerializedItem>, PersistentStoreError>;
fn segment(
&self,
key: &str,
) -> Result<Option<SerializedItem>, PersistentStoreError>;
fn all_flags(
&self,
) -> Result<HashMap<String, SerializedItem>, PersistentStoreError>;
fn upsert(
&mut self,
kind: DataKind,
key: &str,
serialized_item: SerializedItem,
) -> Result<bool, PersistentStoreError>;
fn is_initialized(&self) -> bool;
}
Expand description
PersistentDataStore is an interface for a data store that holds feature flags and related data in a serialized form.
This interface should be used for database integrations, or any other data store implementation that stores data in some external service. The SDK will provide its own caching layer on top of the persistent data store; the data store implementation should not provide caching, but simply do every query or update that the SDK tells it to do.
Required Methods§
sourcefn init(
&mut self,
all_data: AllData<SerializedItem, SerializedItem>,
) -> Result<(), PersistentStoreError>
fn init( &mut self, all_data: AllData<SerializedItem, SerializedItem>, ) -> Result<(), PersistentStoreError>
Overwrites the store’s contents with a set of items for each collection.
All previous data should be discarded, regardless of versioning.
The update should be done atomically. If it cannot be done atomically, then the store must first add or update each item in the same order that they are given in the input data, and then delete any previously stored items that were not in the input data.
sourcefn flag(
&self,
key: &str,
) -> Result<Option<SerializedItem>, PersistentStoreError>
fn flag( &self, key: &str, ) -> Result<Option<SerializedItem>, PersistentStoreError>
Retrieves a flag item from the specified collection, if available.
If the specified key does not exist in the collection, it should result Ok(None).
If the item has been deleted and the store contains a placeholder, it should return that placeholder rather than filtering it out.
sourcefn segment(
&self,
key: &str,
) -> Result<Option<SerializedItem>, PersistentStoreError>
fn segment( &self, key: &str, ) -> Result<Option<SerializedItem>, PersistentStoreError>
Retrieves a segment item from the specified collection, if available.
If the specified key does not exist in the collection, it should result Ok(None).
If the item has been deleted and the store contains a placeholder, it should return that placeholder rather than filtering it out.
sourcefn all_flags(
&self,
) -> Result<HashMap<String, SerializedItem>, PersistentStoreError>
fn all_flags( &self, ) -> Result<HashMap<String, SerializedItem>, PersistentStoreError>
Retrieves all flag items from the specified collection.
If the store contains placeholders for deleted items, it should include them in the results, not filter them out.
sourcefn upsert(
&mut self,
kind: DataKind,
key: &str,
serialized_item: SerializedItem,
) -> Result<bool, PersistentStoreError>
fn upsert( &mut self, kind: DataKind, key: &str, serialized_item: SerializedItem, ) -> Result<bool, PersistentStoreError>
Updates or inserts an item in the specified collection. For updates, the object will only be updated if the existing version is less than the new version.
The SDK may pass a SerializedItem that represents a placeholder for a deleted item. In that case, assuming the version is greater than any existing version of that item, the store should retain that placeholder rather than simply not storing anything.
sourcefn is_initialized(&self) -> bool
fn is_initialized(&self) -> bool
Returns true if the data store contains a data set, meaning that PersistentDataStore::init has been called at least once.
In a shared data store, it should be able to detect this even if PersistentDataStore::init was called in a different process: that is, the test should be based on looking at what is in the data store.