Expand description
§Product OS Store
A flexible, high-level framework for working with various storage backends including key-value stores, queues, and relational databases in a unified way.
§Overview
Product OS Store provides a consistent interface across different storage paradigms:
- Key-Value Stores: Redis, in-memory, and file-based storage
- Queue Stores: Redis queues, in-memory queues, and file-based queues
- Relational Stores: PostgreSQL and SQLite with a query builder
§Features
The crate uses feature flags to enable different storage backends:
§Key-Value Store Features
key_value_store: Core key-value store functionalityredis_key_value_store: Redis backend supportmemory_key_value_store: In-memory backendfile_key_value_store: File-based backend
§Queue Store Features
queue_store: Core queue functionalityredis_queue_store: Redis queue backendmemory_queue_store: In-memory queue backendfile_queue_store: File-based queue backend
§Relational Store Features
relational_store: Core relational database functionalitypostgres_relational_store: PostgreSQL backendsqlite_relational_store: SQLite backendsql_relational_store: SQL query building and processing
§Example Usage
§Key-Value Store
use product_os_store::{ProductOSKeyValueStore, ProductOSStoreError};
use product_os_store::{KeyValueStore, KeyValueKind};
// Create a sink store (for testing/examples)
let config = KeyValueStore {
enabled: true,
kind: KeyValueKind::Sink,
host: "localhost".to_string(),
port: 6379,
secure: false,
db_number: 0,
db_name: None,
username: None,
password: None,
pool_size: 1,
default_limit: 100,
default_offset: 0,
prefix: None,
};
let mut store = ProductOSKeyValueStore::new(&config);
store.connect()?;
store.set_group("users");
// Store and retrieve values
store.group_set("user:1", "{\"name\":\"John\"}")?;
let value = store.group_get("user:1")?;§Relational Store with Query Builder
use product_os_store::{
ProductOSRelationalStore, Query, Fields, Table, Expression
};
use product_os_store::{RelationalStore, RelationalKind};
let config = RelationalStore {
enabled: true,
kind: RelationalKind::Sink,
host: "localhost".to_string(),
port: 5432,
secure: false,
db_name: "test".to_string(),
username: None,
password: None,
pool_size: 1,
default_limit: 100,
default_offset: 0,
prefix: None,
};
let mut store = ProductOSRelationalStore::new(&config);
store.connect().await?;
// Build and execute a query using the high-level API
let query = Query::QueryComplete(
Table::Table("users".to_string()),
None, // join
Some(Fields::All),
None, // distinct
Some(Expression::EqualTo("status".to_string(), "active".to_string())),
None, // group_by
None, // having
None, // sort_by
None, // fetch
None, // into
);
// Use the query directly with the store methods
let rows = store.get_all_specific(&query).await?;§No-Std Support
This crate supports no_std environments with the alloc feature.
Enable the std feature (part of default) for full functionality.
§Safety and Error Handling
All I/O operations return Result<T, ProductOSStoreError> for proper error handling.
SQL injection protection is built into the query builder through input validation.
Structs§
- KeyValue
Store - Key-value store configuration
- Queue
Store - Queue store configuration
- Relational
Store - Relational database configuration
- Stores
- Container for all store configurations
Enums§
- KeyValue
Kind - Type of key-value store
- ProductOS
Store Error - Errors that can occur when working with Product OS stores.
- Queue
Kind - Type of queue store
- Relational
Kind - Type of relational database