1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Allow unused items in this module - these are public API methods that may be
// used by external consumers or in future features (shell integration, LSP, etc.)
//! 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.user` in 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 metadata
//! - [`AliasManager`]: High-level API for managing saved query aliases
//! - [`HistoryManager`]: High-level API for managing query history
//! - [`PersistenceConfig`]: Configuration for paths and limits
//!
//! # Example
//!
//! ```ignore
//! 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);
//! ```
// Re-export public API
// Allow unused_imports: These are exported for external consumers
// (shell integration, LSP, external tools)
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;