pub struct PluginStorage { /* private fields */ }Expand description
SQLite-backed per-plugin KV store. Cheap to clone (wraps an Arc).
Implementations§
Source§impl PluginStorage
impl PluginStorage
Sourcepub fn open(path: PathBuf) -> Result<Self>
pub fn open(path: PathBuf) -> Result<Self>
Open (or create) the store at a specific path and run migrations.
Sourcepub async fn get(
&self,
plugin_id: &str,
namespace: &str,
key: &str,
) -> Result<Option<String>>
pub async fn get( &self, plugin_id: &str, namespace: &str, key: &str, ) -> Result<Option<String>>
Read a value. Ok(None) when the key is unset.
Sourcepub async fn set(
&self,
plugin_id: &str,
namespace: &str,
key: &str,
value: &str,
) -> Result<()>
pub async fn set( &self, plugin_id: &str, namespace: &str, key: &str, value: &str, ) -> Result<()>
Upsert a value.
Sourcepub async fn delete(
&self,
plugin_id: &str,
namespace: &str,
key: &str,
) -> Result<()>
pub async fn delete( &self, plugin_id: &str, namespace: &str, key: &str, ) -> Result<()>
Delete a value (no-op if absent).
Sourcepub async fn rekey_plugin(&self, from: &str, to: &str) -> Result<usize>
pub async fn rekey_plugin(&self, from: &str, to: &str) -> Result<usize>
List the keys a plugin has set within a namespace (newest first).
Move every row owned by from to to — the plugin-id rename migration.
The KV is keyed (plugin_id, namespace, key), so a plugin whose id changes
would otherwise silently lose all of its state: a goal plugin’s active
conditions, the learning log, anything a hook stashed. The rows are still
there, just unreachable under the new id, which reads to a user as data loss
with no error anywhere.
INSERT OR IGNORE + DELETE rather than UPDATE: if the new id already has
a row at the same (namespace, key) — a re-run, or a fresh install that
already wrote state — the NEW value wins and the stale legacy row is dropped.
A bare UPDATE would fail the primary-key constraint and abort the whole
migration on the one plugin that needed it least.
Returns the number of legacy rows removed.
§Errors
Returns Err if the SQLite transaction fails.
pub async fn keys( &self, plugin_id: &str, namespace: &str, ) -> Result<Vec<String>>
Trait Implementations§
Source§impl Clone for PluginStorage
impl Clone for PluginStorage
Source§fn clone(&self) -> PluginStorage
fn clone(&self) -> PluginStorage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more