pub struct Store { /* private fields */ }Expand description
The top-level manager for document collections in Cyberpath Sentinel.
Store manages the root directory where all collections are stored. It handles
directory creation, collection access, and serves as the entry point for all
document storage operations. Each Store instance corresponds to a single
filesystem-backed database.
§Architecture
The Store creates a hierarchical structure:
- Root directory (specified at creation)
data/subdirectory (contains all collections)- Collection directories (e.g.,
users/,audit_logs/)
- Collection directories (e.g.,
§Examples
use sentinel_dbms::Store;
// Create a new store at the specified path
let store =
Store::new("/var/lib/sentinel/db", Some("my_passphrase")).await?;
// Access a collection
let users = store.collection("users").await?;§Thread Safety
Store is safe to share across threads. Multiple collections can be accessed
concurrently, with each collection managing its own locking internally.
Implementations§
Source§impl Store
impl Store
Sourcepub async fn new<P>(root_path: P, passphrase: Option<&str>) -> Result<Self>
pub async fn new<P>(root_path: P, passphrase: Option<&str>) -> Result<Self>
Creates a new Store instance at the specified root path.
This method initializes the store by creating the root directory if it doesn’t
exist. It does not create the data/ subdirectory until collections are accessed.
§Parameters
root_path- The filesystem path where the store will be created. This can be any type that implementsAsRef<Path>, including&str,String,Path, andPathBuf.
§Returns
Result<Self>- Returns a newStoreinstance on success, or aSentinelErrorif:- The directory cannot be created due to permission issues
- The path is invalid or cannot be accessed
- I/O errors occur during directory creation
§Examples
use sentinel_dbms::Store;
// Create a store with a string path
let store = Store::new("/var/lib/sentinel", None).await?;
// Create a store with a PathBuf
use std::path::PathBuf;
let path = PathBuf::from("/tmp/my-store");
let store = Store::new(path, None).await?;
// Create a store in a temporary directory
let temp_dir = std::env::temp_dir().join("sentinel-test");
let store = Store::new(&temp_dir, None).await?;§Notes
- If the directory already exists, this method succeeds without modification
- Parent directories are created automatically if they don’t exist
- The created directory will have default permissions set by the operating system
Sourcepub async fn collection(&self, name: &str) -> Result<Collection>
pub async fn collection(&self, name: &str) -> Result<Collection>
Retrieves or creates a collection with the specified name.
This method provides access to a named collection within the store. If the
collection directory doesn’t exist, it will be created automatically under
the data/ subdirectory of the store’s root path.
§Parameters
name- The name of the collection. This will be used as the directory name underdata/. The name should be filesystem-safe (avoid special characters that are invalid in directory names on your target platform).
§Returns
Result<Collection>- Returns aCollectioninstance on success, or aSentinelErrorif:- The collection directory cannot be created due to permission issues
- The name contains invalid characters for the filesystem
- I/O errors occur during directory creation
§Examples
use sentinel_dbms::Store;
use serde_json::json;
let store = Store::new("/var/lib/sentinel", None).await?;
// Access a users collection
let users = store.collection("users").await?;
// Insert a document into the collection
users.insert("user-123", json!({
"name": "Alice",
"email": "alice@example.com"
})).await?;
// Access multiple collections
let audit_logs = store.collection("audit_logs").await?;
let certificates = store.collection("certificates").await?;§Collection Naming
Collection names should follow these guidelines:
- Use lowercase letters, numbers, underscores, and hyphens
- Avoid spaces and special characters
- Keep names descriptive but concise (e.g.,
users,audit_logs,api_keys)
§Notes
- Calling this method multiple times with the same name returns separate
Collectioninstances pointing to the same directory - The
data/subdirectory is created automatically on first collection access - Collections are not cached; each call creates a new
Collectioninstance - No validation is performed on the collection name beyond filesystem constraints