#[derive(AcidRepository)]
{
// Attributes available to this derive:
#[mongo]
#[postgres]
}
Expand description
Provides an implementation of AcidRepositoryAccess<C>
and Atomic
depending on the
provided attributes.
Accepted attributes and fields are:
#[postgres(Connection)]
-> postgres
, tx_pg
,
#[mongo(Connection)]
-> mongo
, tx_mg
,
Useful for deriving on repository structs with generic connections that only use postgres.
The connection
attribute must be specified and equal to the generic connection parameter
of the repository, e.g. if the generic connection is specified as C
then the attribute must
be #[connection = "C"]
.
Deriving structs MUST have a postgres
, mongo
or both fields and they must be a generic client
Client<A, C>
provided in hextacy::clients::db
.
The structs, depending on which client they are using, must also contain the tx_pg
or tx_mg
fields which will be used to keep track of transactions for the respective client. Transaction fields
must be a RefCell<Option<C>>
(hextacy::db
provides a Transaction
type for convenience).
§Example
#[derive(Debug, AcidRepository)]
#[postgres(Pg)]
#[mongo(Mg)]
pub(super) struct Repository<A, B, Pg, Mg, User>
where
A: DBConnect<Connection = Pg>,
B: DBConnect<Connection = Mg>,
User: UserRepository<Pg>,
Session: SessionRepository<Mg>,
{
postgres: Client<A, Pg>,
mongo: Client<B, Mg>,
tx_pg: Transaction<Pg>,
tx_mg: Transaction<Mg>,
user: PhantomData<User>,
session: PhantomData<Session>,
}