Skip to main content

forge_runtime/kv/
mod.rs

1//! PostgreSQL-backed key-value store for framework internals.
2
3mod store;
4
5pub use store::KvStore;
6
7use std::future::Future;
8use std::pin::Pin;
9use std::time::Duration;
10
11use forge_core::error::Result;
12use forge_core::function::KvHandle;
13
14impl KvHandle for KvStore {
15    fn get<'a>(
16        &'a self,
17        key: &'a str,
18    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>>> + Send + 'a>> {
19        Box::pin(self.get(key))
20    }
21
22    fn set<'a>(
23        &'a self,
24        key: &'a str,
25        value: &'a [u8],
26        ttl: Option<Duration>,
27    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> {
28        Box::pin(self.set(key, value, ttl))
29    }
30
31    fn set_if_absent<'a>(
32        &'a self,
33        key: &'a str,
34        value: &'a [u8],
35        ttl: Option<Duration>,
36    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'a>> {
37        Box::pin(self.set_if_absent(key, value, ttl))
38    }
39
40    fn delete<'a>(
41        &'a self,
42        key: &'a str,
43    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'a>> {
44        Box::pin(self.delete(key))
45    }
46
47    fn increment<'a>(
48        &'a self,
49        key: &'a str,
50        delta: i64,
51        ttl: Option<Duration>,
52    ) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'a>> {
53        Box::pin(self.increment(key, delta, ttl))
54    }
55}