Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

All notable changes to this project will be documented in this file.

## [0.11.5] - 2025-04-03

### 🐛 Bug Fixes

- Mapping store name with db url

## [0.11.4] - 2025-04-02

### 🚜 Refactor

- Updating wasmtime to 31.0.0

### ⚙️ Miscellaneous Tasks

- Release

## [0.11.3] - 2025-04-02

### 🐛 Bug Fixes
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.11.4"
version = "0.11.5"
edition = "2021"
publish = false
authors = ["FastEdge Development Team"]
Expand Down
13 changes: 7 additions & 6 deletions crates/key-value-store/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use reactor::gcore::fastedge::key_value;
use slab::Slab;
use smol_str::SmolStr;
use std::collections::HashSet;
use std::collections::HashMap;
use std::sync::Arc;
use wasmtime::component::Resource;

Expand All @@ -18,12 +18,13 @@ pub trait Store: Sync + Send {

#[async_trait::async_trait]
pub trait StoreManager: Sync + Send {
async fn get_store(&self, name: &str) -> Result<Arc<dyn Store>, Error>;
/// Get a store by db url.
async fn get_store(&self, param: &str) -> Result<Arc<dyn Store>, Error>;
}

#[derive(Clone)]
pub struct KeyValueStore {
allowed_stores: HashSet<SmolStr>,
allowed_stores: HashMap<SmolStr, SmolStr>,
manager: Arc<dyn StoreManager>,
stores: Slab<Arc<dyn Store>>,
}
Expand Down Expand Up @@ -73,7 +74,7 @@ impl key_value::HostStore for KeyValueStore {
impl key_value::Host for KeyValueStore {}

impl KeyValueStore {
pub fn new(allowed_stores: Vec<SmolStr>, manager: Arc<dyn StoreManager>) -> Self {
pub fn new(allowed_stores: Vec<(SmolStr, SmolStr)>, manager: Arc<dyn StoreManager>) -> Self {
Self {
allowed_stores: allowed_stores.into_iter().collect(),
manager,
Expand All @@ -83,8 +84,8 @@ impl KeyValueStore {

/// Open a store by name. Return the store ID.
pub async fn open(&mut self, name: &str) -> Result<u32, Error> {
if self.allowed_stores.contains(name) {
let store = self.manager.get_store(name).await?;
if let Some(param) = self.allowed_stores.get(name) {
let store = self.manager.get_store(&param).await?;
Ok(self.stores.insert(store) as u32)
} else {
Err(Error::AccessDenied)
Expand Down
2 changes: 1 addition & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ContextT for Context {
}

fn make_key_value_store(&self, stores: &Vec<KvStoreOption>) -> KeyValueStore {
let stores = stores.iter().map(|s| s.name.clone()).collect();
let stores = stores.iter().map(|s| (s.name.clone(), s.param.clone())).collect();
KeyValueStore::new(stores, Arc::new(CliStoreManager))
}
}
Expand Down