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
82
83
84
85
86
87
88
89
90
91
92
93
//! SQLx-facing integration crate for HydraCache database result caching.
//!
//! The database-neutral query cache API lives in `hydracache-db`. This crate
//! keeps SQLx users on a convenient import path while avoiding a hard conceptual
//! dependency between the generic adapter and SQLx itself.
//!
//! # Example
//!
//! ```rust
//! use hydracache::HydraCache;
//! use hydracache_sqlx::DbCache;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
//! struct User {
//! id: i64,
//! name: String,
//! }
//!
//! # #[tokio::main]
//! # async fn main() -> hydracache_sqlx::Result<()> {
//! let local = HydraCache::local().build();
//!
//! // SQLx users may import DbCache from this crate, but the type itself is
//! // database-neutral and comes from hydracache-db.
//! let queries = DbCache::new(local, "db");
//!
//! let user = queries
//! .cached::<User>()
//! .key("user:42")
//! .tag("user:42")
//! .fetch_with(|| async {
//! // This loader runs only on a cache miss. On a cache hit, HydraCache
//! // returns the cached User and this SQLx code is not executed.
//! Ok::<_, std::io::Error>(User {
//! id: 42,
//! name: "Ada".to_owned(),
//! })
//! })
//! .await?;
//!
//! assert_eq!(user.id, 42);
//! # Ok(())
//! # }
//! ```
pub use ;
/// SQLx-specific compatibility name for [`DbCache`].
pub type SqlxCache<C = PostcardCodec> = ;
/// SQLx-specific compatibility name for [`DbQuery`].
pub type SqlxQuery<T, C = PostcardCodec> = ;
/// SQLx-specific compatibility name for [`DbCacheError`].
pub type SqlxCacheError = DbCacheError;
/// Re-export the SQLx crate used by this adapter.
///
/// This lets downstream users keep one adapter-aligned SQLx version in examples
/// and integration code without hiding SQLx behind HydraCache abstractions.
pub use sqlx;