llm_registry_db/
lib.rs

1//! Database layer for LLM Registry
2//!
3//! This crate provides database persistence for the LLM Registry system, including:
4//! - Connection pool management with deadpool
5//! - Repository trait abstractions for assets
6//! - PostgreSQL implementation with SQLx
7//! - Event store for audit trails and event sourcing
8//! - Database migrations
9//! - Comprehensive error handling
10//!
11//! # Features
12//!
13//! - **Compile-time verified queries**: Using SQLx macros for type-safe SQL
14//! - **Connection pooling**: Efficient connection management with configurable pools
15//! - **Transaction support**: ACID guarantees for multi-step operations
16//! - **Event sourcing**: Complete audit trail of all registry operations
17//! - **Flexible search**: Full-text search and filtering capabilities
18//! - **Dependency tracking**: Graph-based dependency management with cycle detection
19//!
20//! # Example
21//!
22//! ```rust,no_run
23//! use llm_registry_db::{PoolConfig, create_pool, PostgresAssetRepository};
24//! use llm_registry_core::Asset;
25//!
26//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
27//! // Create a connection pool
28//! let config = PoolConfig::new("postgres://localhost/llm_registry")
29//!     .max_connections(10);
30//! let pool = create_pool(&config).await?;
31//!
32//! // Create repository
33//! let repo = PostgresAssetRepository::new(pool);
34//!
35//! // Use the repository
36//! // let asset = repo.create(my_asset).await?;
37//! # Ok(())
38//! # }
39//! ```
40
41// Re-export core domain types for convenience
42pub use llm_registry_core;
43
44// Public modules
45pub mod cache;
46pub mod error;
47pub mod event_store;
48pub mod nats_publisher;
49pub mod pool;
50pub mod postgres;
51pub mod repository;
52
53// Re-exports for convenience
54pub use cache::{CacheConfig, CacheStats, RedisCache};
55pub use error::{DbError, DbResult};
56pub use event_store::{EventQuery, EventQueryResults, EventStore, PostgresEventStore};
57pub use nats_publisher::{
58    EventMessage, NatsEventPublisher, NatsPublisherConfig, NatsSubscriberConfig,
59};
60pub use pool::{
61    close_pool, create_pool, get_pool_stats, run_migrations, verify_pool_health, PoolConfig,
62    PoolStats,
63};
64pub use postgres::PostgresAssetRepository;
65pub use repository::{AssetRepository, SearchQuery, SearchResults, SortField, SortOrder};
66
67// Re-export sqlx types that users may need
68pub use sqlx::postgres::PgPool;
69
70/// Database layer version
71pub const VERSION: &str = env!("CARGO_PKG_VERSION");
72
73/// Default database URL environment variable name
74pub const DEFAULT_DATABASE_URL_ENV: &str = "DATABASE_URL";
75
76#[cfg(test)]
77mod tests {
78    use super::*;
79
80    #[test]
81    fn test_version() {
82        assert!(!VERSION.is_empty());
83    }
84
85    #[test]
86    fn test_default_env_var() {
87        assert_eq!(DEFAULT_DATABASE_URL_ENV, "DATABASE_URL");
88    }
89}