Expand description

typesafe_repository is designed to abstract data persistence, so its implementations can be easily swapped for testing or migration purposes

You can create your own repository by implementing traits like Add, List, Get, and plenty of others (see async_ops for complete list)

Typical way to define abstract repository for some type is:

use typesafe_repository::{Identity, Repository, Add, List, Remove};
use typesafe_repository::inmemory::InMemoryRepository;
use typesafe_repository::macros::Id;
use std::sync::Arc;

#[derive(Clone, Id)]
pub struct Foo {
  id: usize,
}

trait FooRepository:
  Repository<Foo, Error = Box<dyn std::error::Error + Send + Sync>>
  + Add<Foo>
  + List<Foo>
  + Remove<Foo>
{}

impl<T> FooRepository for T
where T: Repository<Foo, Error = Box<dyn std::error::Error + Send + Sync>>
    + Add<Foo>
    + List<Foo>
    + Remove<Foo> {}

struct FooService {
  repo: Arc<dyn FooRepository>,
}

// You can mock any repository with InMemoryRepository since it implements all operations on
// all types
let repo = Arc::new(InMemoryRepository::new());
FooService { repo };

Re-exports

pub use async_ops::*;

Modules

async operations for Repository
Transactional traits and wrapper for Repository

Structs

Identity which can be obtained only from impl Identity or ValidIdentityProvider

Traits

Partially initialized entity
Defines type’s primary key
Defines additional type’s keys
Marker trait with Error definition for operations
Mark that Selector can be used with type
Marker identity for advanced operations and parameters

Type Definitions

Identity::Id shorthand that helps abstract from Id type