actix_diesel_cache

Actix actor for caching diesel database

Latest version: 0.1.0 registry icon
Maintenance score
0
Safety score
0
Popularity score
70
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
0.1.0 0 0 0 0 0

Stability
Latest release:

0.1.0 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

Apache-2.0   -   Apache License 2.0

Not a wildcard

Not proprietary

OSI Compliant


MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



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