Skip to main content

helios_persistence/backends/sqlite/
mod.rs

1//! SQLite backend implementation.
2//!
3//! This module provides a complete SQLite implementation of all storage traits.
4//! It supports both in-memory databases (great for testing) and file-based
5//! databases (for development and small deployments).
6//!
7//! # Features
8//!
9//! - In-memory and file-based modes
10//! - Full CRUD operations with tenant isolation
11//! - Version history tracking
12//! - Basic search support (string, token, date, reference)
13//! - Transaction support with ACID guarantees
14//!
15//! # Example
16//!
17//! ```no_run
18//! use helios_persistence::backends::sqlite::SqliteBackend;
19//! use helios_persistence::tenant::{TenantContext, TenantId, TenantPermissions};
20//!
21//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
22//! // Create an in-memory database
23//! let backend = SqliteBackend::in_memory()?;
24//!
25//! // Initialize the schema
26//! backend.init_schema()?;
27//!
28//! // Create a tenant context
29//! let tenant = TenantContext::new(
30//!     TenantId::new("acme"),
31//!     TenantPermissions::full_access(),
32//! );
33//!
34//! // Now you can use the backend for CRUD operations
35//! # Ok(())
36//! # }
37//! ```
38//!
39//! # Schema
40//!
41//! The SQLite backend uses the following schema:
42//!
43//! ```sql
44//! -- Main resource table
45//! CREATE TABLE resources (
46//!     tenant_id TEXT NOT NULL,
47//!     resource_type TEXT NOT NULL,
48//!     id TEXT NOT NULL,
49//!     version_id TEXT NOT NULL,
50//!     data BLOB NOT NULL,  -- JSON data
51//!     last_updated TEXT NOT NULL,
52//!     is_deleted INTEGER NOT NULL DEFAULT 0,
53//!     deleted_at TEXT,
54//!     PRIMARY KEY (tenant_id, resource_type, id)
55//! );
56//!
57//! -- Version history table
58//! CREATE TABLE resource_history (
59//!     tenant_id TEXT NOT NULL,
60//!     resource_type TEXT NOT NULL,
61//!     id TEXT NOT NULL,
62//!     version_id TEXT NOT NULL,
63//!     data BLOB NOT NULL,
64//!     last_updated TEXT NOT NULL,
65//!     is_deleted INTEGER NOT NULL DEFAULT 0,
66//!     PRIMARY KEY (tenant_id, resource_type, id, version_id)
67//! );
68//! ```
69
70mod backend;
71mod bulk_export;
72mod bulk_submit;
73mod schema;
74pub mod search;
75mod search_impl;
76mod storage;
77mod transaction;
78
79pub use backend::{SqliteBackend, SqliteBackendConfig};