sqry_cli/persistence/mod.rs
1// Allow unused items in this module - these are public API methods that may be
2// used by external consumers or in future features (shell integration, LSP, etc.)
3#![allow(dead_code)]
4
5//! Query persistence subsystem.
6//!
7//! This module provides persistence for user aliases and query history,
8//! enabling users to save and reuse frequently used queries.
9//!
10//! # Architecture
11//!
12//! The persistence subsystem uses a binary index format (`postcard`) for
13//! efficient storage and fast access. Data is stored in two locations:
14//!
15//! - **Global**: `~/.config/sqry/global.index.user` - cross-project aliases
16//! - **Local**: `.sqry-index.user` in project root - project-specific aliases
17//!
18//! All file operations are atomic (using temp file + rename) to prevent
19//! corruption from crashes or concurrent access.
20//!
21//! # Components
22//!
23//! - [`UserMetadataIndex`]: Main interface for loading/saving user metadata
24//! - [`AliasManager`]: High-level API for managing saved query aliases
25//! - [`HistoryManager`]: High-level API for managing query history
26//! - [`PersistenceConfig`]: Configuration for paths and limits
27//!
28//! # Example
29//!
30//! ```ignore
31//! use std::sync::Arc;
32//! use sqry_cli::persistence::{
33//! UserMetadataIndex, PersistenceConfig, StorageScope, AliasManager
34//! };
35//!
36//! // Open the index
37//! let config = PersistenceConfig::default();
38//! let index = Arc::new(UserMetadataIndex::open(Some("."), config)?);
39//!
40//! // Create an alias manager
41//! let aliases = AliasManager::new(index.clone());
42//! aliases.save("my-query", "search", &["main".into()], None, StorageScope::Global)?;
43//!
44//! // Retrieve the alias
45//! let alias = aliases.get("my-query")?;
46//! println!("Command: {} {:?}", alias.alias.command, alias.alias.args);
47//! ```
48
49mod alias;
50mod config;
51mod history;
52mod index;
53mod types;
54mod validation;
55
56// Re-export public API
57// Allow unused_imports: These are exported for external consumers
58// (shell integration, LSP, external tools)
59#[allow(unused_imports)]
60pub use alias::{AliasError, AliasManager};
61#[allow(unused_imports)]
62pub use config::{
63 DEFAULT_MAX_HISTORY_ENTRIES, DEFAULT_MAX_INDEX_BYTES, ENV_CONFIG_DIR, ENV_NO_HISTORY,
64 ENV_NO_REDACT, PersistenceConfig, global_config_dir,
65};
66#[allow(unused_imports)]
67pub use history::{
68 HistoryError, HistoryManager, HistoryStats, REDACTED_PLACEHOLDER, contains_secrets,
69 parse_duration, redact_secrets,
70};
71#[allow(unused_imports)]
72pub use index::{GLOBAL_INDEX_FILE, LOCAL_INDEX_FILE, UserMetadataIndex, open_shared_index};
73#[allow(unused_imports)]
74pub use types::{
75 AliasExportFile, AliasWithScope, HistoryEntry, HistoryState, ImportConflictStrategy,
76 ImportResult, SavedAlias, StorageScope, USER_METADATA_VERSION, UserMetadata,
77};
78#[allow(unused_imports)]
79pub use validation::{
80 AliasNameError, MAX_ALIAS_LENGTH, MIN_ALIAS_LENGTH, suggest_alias_name, validate_alias_name,
81};