actix_diesel_cache 0.1.0

actix_diesel_cache is crate which provides the actix actor for caching all database entries on local machine.
Documentation
  • Coverage
  • 100%
    14 out of 14 items documented0 out of 9 items with examples
  • Size
  • Source code size: 43.05 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 6.9 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 4s Average build duration of successful builds.
  • all releases: 1m 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • i1i1/actix_diesel_cache
    1 2 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • i1i1

actix_diesel_cache

Docs Crates.io

A library with actor which provides caching for small and rarely changing tables in databases.

Usage

Add to Cargo.toml:

actix_diesel_cache = "0.1.0"

Example

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]);
}