Crates.io | actix_diesel_cache |
lib.rs | actix_diesel_cache |
version | 0.1.0 |
source | src |
created_at | 2020-12-23 13:59:33.254103 |
updated_at | 2020-12-23 13:59:33.254103 |
description | actix_diesel_cache is crate which provides the actix actor for caching all database entries on local machine. |
homepage | |
repository | https://github.com/i1i1/actix_diesel_cache |
max_upload_size | |
id | 326507 |
size | 12,124 |
actix_diesel_cache
A library with actor which provides caching for small and rarely changing tables in databases.
Add to Cargo.toml
:
actix_diesel_cache = "0.1.0"
use diesel::prelude::*;
table! {
shop (id) {
id -> Int4,
name -> Text,
address -> Text,
}
}
#[derive(Queryable, Insertable, Clone, Debug, Eq, PartialEq)]
#[table_name = "shop"]
struct Shop {
id: i32,
name: String,
address: String,
}
impl actix_diesel_cache::Cache<SqliteConnection, shop::table> for Shop {
type Id = i32;
fn get_id(&self) -> Self::Id {
s.id
}
}
async fn example(conn: SqliteConnection) -> actix_diesel_cache::Result<()> {
let addr = actix_diesel_cache::CacheDbActor::new(conn)?.start();
let shop = Shop {
id: 1,
name: "Adidas",
address: "Central street",
};
addr.send(actix_diesel_cache::Save(shop)).await.unwrap()?;
let shop1 = addr.send(actix_diesel_cache::Get(shop.id)).await.unwrap()?;;
assert_eq!(shop, shop1);
let shops = addr.send(actix_diesel_cache::GetAll::default()).await.unwrap()?;;
assert_eq!(shops, vec![shop]);
}