Skip to main content

Crate product_os_store

Crate product_os_store 

Source
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 functionality
  • redis_key_value_store: Redis backend support
  • memory_key_value_store: In-memory backend
  • file_key_value_store: File-based backend

§Queue Store Features

  • queue_store: Core queue functionality
  • redis_queue_store: Redis queue backend
  • memory_queue_store: In-memory queue backend
  • file_queue_store: File-based queue backend

§Relational Store Features

  • relational_store: Core relational database functionality
  • postgres_relational_store: PostgreSQL backend
  • sqlite_relational_store: SQLite backend
  • sql_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.

Modules§

binary_keys
Composite binary key helpers for graph / co-occurrence workloads.

Structs§

KeyValueStore
Key-value store configuration
KeywordStore
Keyword store configuration.
MemoryMappedStore
Memory-mapped store configuration.
QueueStore
Queue store configuration
RelationalStore
Relational database configuration
Stores
Container for all store configurations
VectorStore
Vector store configuration.

Enums§

KeyValueKind
Type of key-value store
KeywordKind
Type of keyword (BM25) store backend.
MemoryMappedKind
Type of memory-mapped store backend.
ProductOSStoreError
Errors that can occur when working with Product OS stores.
QueueKind
Type of queue store
RelationalKind
Type of relational database
VectorKind
Type of vector (dense ANN) store backend.