Expand description
Query persistence subsystem.
This module provides persistence for user aliases and query history, enabling users to save and reuse frequently used queries.
§Architecture
The persistence subsystem uses a binary index format (postcard) for
efficient storage and fast access. Data is stored in two locations:
- Global:
~/.config/sqry/global.index.user- cross-project aliases - Local:
.sqry-index.userin project root - project-specific aliases
All file operations are atomic (using temp file + rename) to prevent corruption from crashes or concurrent access.
§Components
UserMetadataIndex: Main interface for loading/saving user metadataAliasManager: High-level API for managing saved query aliasesHistoryManager: High-level API for managing query historyPersistenceConfig: Configuration for paths and limits
§Example
ⓘ
use std::sync::Arc;
use sqry_cli::persistence::{
UserMetadataIndex, PersistenceConfig, StorageScope, AliasManager
};
// Open the index
let config = PersistenceConfig::default();
let index = Arc::new(UserMetadataIndex::open(Some("."), config)?);
// Create an alias manager
let aliases = AliasManager::new(index.clone());
aliases.save("my-query", "search", &["main".into()], None, StorageScope::Global)?;
// Retrieve the alias
let alias = aliases.get("my-query")?;
println!("Command: {} {:?}", alias.alias.command, alias.alias.args);Structs§
- Alias
Export File - JSON export format for aliases (for backup/restore via ).
- Alias
Manager - Manager for saved query aliases.
- Alias
With Scope - Alias with its storage scope for listing.
- History
Entry - A single entry in the query history.
- History
Manager - Manager for query history.
- History
State - History state stored in the user metadata index.
- History
Stats - Statistics about the command history.
- Import
Result - Result of an import operation.
- Persistence
Config - Configuration for the persistence subsystem.
- Saved
Alias - A saved query alias.
- User
Metadata - Root structure for user metadata stored in the index.
- User
Metadata Index - User metadata index providing atomic access to alias and history storage.
Enums§
- Alias
Error - Error type for alias operations.
- Alias
Name Error - Error type for alias name validation.
- History
Error - Error type for history operations.
- Import
Conflict Strategy - Import conflict resolution strategies.
- Storage
Scope - Storage scope for aliases.
Constants§
- DEFAULT_
MAX_ HISTORY_ ENTRIES - Default maximum number of history entries to retain.
- DEFAULT_
MAX_ INDEX_ BYTES - Default maximum size of the user metadata index in bytes (10 MB).
- ENV_
CONFIG_ DIR - Environment variable for overriding the global config directory.
- ENV_
NO_ HISTORY - Environment variable to disable history recording.
- ENV_
NO_ REDACT - Environment variable to disable secret redaction (default: enabled).
- GLOBAL_
INDEX_ FILE - Global index file name.
- LOCAL_
INDEX_ FILE - Local index file name.
- MAX_
ALIAS_ LENGTH - Maximum alias name length.
- MIN_
ALIAS_ LENGTH - Minimum alias name length.
- REDACTED_
PLACEHOLDER - Placeholder for redacted secrets.
- USER_
METADATA_ VERSION - Current version of the user metadata format. Increment when making breaking changes to the schema.
Functions§
- contains_
secrets - Check if a string contains potential secrets.
- global_
config_ dir - Get the default global config directory.
- open_
shared_ index - Create a shared user metadata index.
- parse_
duration - Parse a duration string like “30d”, “1w”, “24h”.
- redact_
secrets - Redact potential secrets from command arguments.
- suggest_
alias_ name - Suggest a valid alias name based on an invalid input.
- validate_
alias_ name - Validate an alias name according to the specification.