Expand description
SQLite-based storage implementation for SCIM resources.
This module provides persistent storage using SQLite database with the same interface as in-memory storage. Resources are stored as key-value pairs where the key represents the hierarchical tenant/resource_type/resource_id structure and the value contains the JSON resource data.
§Database Schema
The storage uses a simple table structure:
tenant_id
: Text field for tenant isolationresource_type
: Text field for resource type (User, Group, etc.)resource_id
: Text field for the resource identifierdata
: Text field containing JSON resource data- Primary key: (tenant_id, resource_type, resource_id)
§Usage
use scim_server::storage::{SqliteStorage, StorageProvider, StorageKey};
use serde_json::json;
// Default database at scim_data/scim_server.db (creates directory if needed)
let storage = SqliteStorage::new().await?;
// Or custom path
let storage = SqliteStorage::new_with_path("custom/path/data.db").await?;
// Or in-memory for testing
let storage = SqliteStorage::new_in_memory().await?;
let key = StorageKey::new("tenant1", "User", "123");
let user_data = json!({
"id": "123",
"userName": "john.doe"
});
let stored = storage.put(key.clone(), user_data).await?;
let retrieved = storage.get(key).await?;
// Check statistics
let stats = storage.stats().await?;
println!("Total resources: {}", stats.total_resources);
§Database Creation Behavior
SQLiteStorage provides explicit control over database file creation:
new()
: Creates database atscim_data/scim_server.db
new_with_path(path)
: Creates database at custom pathnew_in_memory()
: Creates temporary in-memory database
If the database file doesn’t exist, it will be created along with any necessary parent directories. If it exists, it will be opened for read-write access.
§Examples
use scim_server::storage::{SqliteStorage, StorageProvider, StorageKey};
use serde_json::json;
// Production usage - creates scim_data/scim_server.db
let storage = SqliteStorage::new().await?;
// Store a user
let key = StorageKey::new("company1", "User", "user123");
let user = json!({
"id": "user123",
"userName": "john.doe",
"displayName": "John Doe",
"emails": [{"value": "john@company1.com", "primary": true}]
});
storage.put(key.clone(), user.clone()).await?;
// Retrieve the user
let retrieved = storage.get(key).await?;
assert_eq!(retrieved, Some(user));
// Get statistics
let stats = storage.stats().await?;
println!("Storage contains {} resources across {} tenants",
stats.total_resources, stats.tenant_count);
// Search for users
let found = storage.find_by_attribute(
StorageKey::prefix("company1", "User"),
"userName",
"john.doe"
).await?;
println!("Found {} users matching criteria", found.len());
Structs§
- Sqlite
Storage - SQLite-based storage provider for SCIM resources.