pub trait Record: DeserializeOwned + Serialize + Clone {
const COLLECTION_NAME: &'static str;
Show 14 methods
// Required methods
fn before_create_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn before_save_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn before_delete_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn after_create_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn after_save_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn after_delete_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn find<'life0, 'life1, 'async_trait, D>(
key: &'life0 str,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<DatabaseRecord<Self>, Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn get<'life0, 'life1, 'async_trait, D>(
query: &'life0 Query,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<QueryResult<Self>, Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn get_in_batches<'life0, 'life1, 'async_trait, D>(
query: &'life0 Query,
db_accessor: &'life1 D,
batch_size: u32
) -> Pin<Box<dyn Future<Output = Result<QueryCursor<Self>, Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn exists<'life0, 'life1, 'async_trait, D>(
query: &'life0 Query,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn create<'life0, 'async_trait, D>(
record: Self,
db_accessor: &'life0 D
) -> Pin<Box<dyn Future<Output = Result<DatabaseRecord<Self>, Error>> + Send + 'async_trait>>
where D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn query() -> Query { ... }
fn transaction_builder() -> TransactionBuilder { ... }
fn transaction<'life0, 'async_trait>(
db_connection: &'life0 DatabaseConnection
) -> Pin<Box<dyn Future<Output = Result<Transaction, Error>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait { ... }
}
Expand description
The main trait of the Aragog library.
Trait for structures that can be stored in Database.
The trait must be implemented to be used as a record in DatabaseRecord
Required Associated Constants§
sourceconst COLLECTION_NAME: &'static str
const COLLECTION_NAME: &'static str
returns the associated Collection for read and write operations.
Required Methods§
sourcefn before_create_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn before_create_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
method called by DatabaseRecord
::create
before the database operation.
Define hooks manually or with macros (see the book)
sourcefn before_save_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn before_save_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
method called by DatabaseRecord
::save
before the database operation.
Define hooks manually or with macros (see the book)
sourcefn before_delete_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn before_delete_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
method called by DatabaseRecord
::delete
before the database operation.
Define hooks manually or with macros (see the book)
sourcefn after_create_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn after_create_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
method called automatically by DatabaseRecord
::create
after the database operation.
Define hooks manually or with macros (see the book)
sourcefn after_save_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn after_save_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
method called automatically by DatabaseRecord
::save
after the database operation.
Define hooks manually or with macros (see the book)
sourcefn after_delete_hook<'life0, 'life1, 'async_trait, D>(
&'life0 mut self,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn after_delete_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
method called automatically by DatabaseRecord
::delete
after the database operation.
Define hooks manually or with macros (see the book)
Provided Methods§
sourcefn find<'life0, 'life1, 'async_trait, D>(
key: &'life0 str,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<DatabaseRecord<Self>, Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn find<'life0, 'life1, 'async_trait, D>( key: &'life0 str, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<DatabaseRecord<Self>, Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Finds a document in database from its unique key.
Simple wrapper for DatabaseRecord
<T
>::find
sourcefn get<'life0, 'life1, 'async_trait, D>(
query: &'life0 Query,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = Result<QueryResult<Self>, Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait, D>( query: &'life0 Query, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<QueryResult<Self>, Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Finds all documents in database matching a Query
.
Simple wrapper for DatabaseRecord
<T
>::get
sourcefn get_in_batches<'life0, 'life1, 'async_trait, D>(
query: &'life0 Query,
db_accessor: &'life1 D,
batch_size: u32
) -> Pin<Box<dyn Future<Output = Result<QueryCursor<Self>, Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_in_batches<'life0, 'life1, 'async_trait, D>( query: &'life0 Query, db_accessor: &'life1 D, batch_size: u32 ) -> Pin<Box<dyn Future<Output = Result<QueryCursor<Self>, Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Finds all documents in database matching a Query
in batches.
Simple wrapper for DatabaseRecord
<T
>::get_in_batches
sourcefn exists<'life0, 'life1, 'async_trait, D>(
query: &'life0 Query,
db_accessor: &'life1 D
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn exists<'life0, 'life1, 'async_trait, D>( query: &'life0 Query, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Returns true if there are any document in database matching a Query
.
Simple wrapper for DatabaseRecord
<T
>::exists
sourcefn create<'life0, 'async_trait, D>(
record: Self,
db_accessor: &'life0 D
) -> Pin<Box<dyn Future<Output = Result<DatabaseRecord<Self>, Error>> + Send + 'async_trait>>where
D: DatabaseAccess + ?Sized + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
fn create<'life0, 'async_trait, D>( record: Self, db_accessor: &'life0 D ) -> Pin<Box<dyn Future<Output = Result<DatabaseRecord<Self>, Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait,
Creates a new document in database.
Simple wrapper for DatabaseRecord
<T
>::create
Example
#[derive(Clone, Serialize, Deserialize, Record)]
pub struct User {
pub name: String,
}
let user = User { name: "Patrick".to_owned() };
let created_user = User::create(user, &db_connection).await.unwrap();
assert_eq!(created_user.name, "Patrick".to_owned());
sourcefn query() -> Query
fn query() -> Query
Creates a new Query
instance for Self
.
Example
#[derive(Record, Clone, Serialize, Deserialize)]
pub struct User { }
// All three statements are equivalent:
let q = User::query();
let q = Query::new(User::COLLECTION_NAME);
let q = Query::new("User");
sourcefn transaction_builder() -> TransactionBuilder
fn transaction_builder() -> TransactionBuilder
Returns a transaction builder on this collection only.
sourcefn transaction<'life0, 'async_trait>(
db_connection: &'life0 DatabaseConnection
) -> Pin<Box<dyn Future<Output = Result<Transaction, Error>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
fn transaction<'life0, 'async_trait>( db_connection: &'life0 DatabaseConnection ) -> Pin<Box<dyn Future<Output = Result<Transaction, Error>> + Send + 'async_trait>>where Self: Send + 'async_trait, 'life0: 'async_trait,
Builds a transaction for this collection only.
Arguments
db_connection
- The current database connection