Expand description
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
use hydracache::HydraCache;
use hydracache_sqlx::{DbCache, SqlxQueryExt};
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 (id, name): (i64, String) = queries
.cached::<(i64, String)>()
.key("user:42")
.tag("user:42")
.fetch_one(
pool.clone(),
sqlx::query_as("select id, name from users where id = $1").bind(42_i64),
)
.await?;
assert_eq!(id, 42);
assert!(!name.is_empty());Use DbQuery::fetch_with when you need SQLx macros, transactions, or a
repository function instead of a pool-like executor.
Re-exports§
pub use sqlx;
Structs§
- DbCache
- A database-oriented view over a
HydraCacheinstance. - DbQuery
- A cacheable database query descriptor.
Enums§
- DbCache
Error - Error type returned by database cache adapter helpers.
- Sqlx
Cache Error - Error type returned by SQLx-facing cache helpers.
Traits§
- Sqlx
Query Ext - Convenience SQLx execution methods for
DbQuery.