pub trait StorageAdaptor:
Send
+ Sync
+ 'static {
// Required methods
fn put<'life0, 'async_trait>(
&'life0 mut self,
record: Record,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
partition: u8,
pk: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<Record>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete<'life0, 'life1, 'async_trait>(
&'life0 mut self,
partition: u8,
pk: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<Record>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn query<'life0, 'async_trait>(
&'life0 self,
query: Query,
) -> Pin<Box<dyn Future<Output = Result<Vec<Record>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn incremental_id<'life0, 'async_trait>(
&'life0 mut self,
partition: u8,
) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Storage adaptor trait for persistence backends.
This trait provides a minimal interface (4 methods) that can be efficiently implemented on various storage backends while enabling query optimization.
§Implementor’s Guide
§Simple backends (memory, file-based)
Store records in a map/list and implement query by filtering in memory.
§Database backends (Postgres, MongoDB, Firebase, IndexedDB, etc.)
Create a single table with indexes:
CREATE TABLE storage (
pk TEXT PRIMARY KEY,
partition TEXT NOT NULL,
sort_key BLOB,
data BLOB NOT NULL
);
CREATE INDEX idx_partition_sort ON storage(partition, sort_key);Translate Query to SQL:
SELECT * FROM storage
WHERE partition = :partition
ORDER BY :sort_key DESCRequired Methods§
Sourcefn put<'life0, 'async_trait>(
&'life0 mut self,
record: Record,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn put<'life0, 'async_trait>(
&'life0 mut self,
record: Record,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stores a record, inserting or updating by primary key.
Sourcefn get<'life0, 'life1, 'async_trait>(
&'life0 self,
partition: u8,
pk: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<Record>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
partition: u8,
pk: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<Record>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieves a record by primary key.
Returns None if the record doesn’t exist.
Sourcefn delete<'life0, 'life1, 'async_trait>(
&'life0 mut self,
partition: u8,
pk: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<Record>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 mut self,
partition: u8,
pk: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<Record>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Deletes a record by primary key.
Returns the deleted record if it existed, None otherwise.