Technical notes

DatabaseAccess trait

The object DatabaseConnection is the default handler for every database operations but you can create your own.

Every operation taking the connection as an argument is taking a Generic type implementing DatabaseAccess, so you can implement it on your own struct.

Note: This is not recommended, modification to DatabaseAccess can happen without considering them as breaking.

Trait object

All aragog API using a DatabaseAccess type also use ?Sized (Sized restriction relaxation)

This means you can use dynamically typed trait objects.

Example extract from boxed example:


#![allow(unused_variables)]
fn main() {
pub struct BoxedConnection {
    pub connection: Box<dyn DatabaseAccess>,
}

impl BoxedConnection {
    pub fn connection(&self) -> &dyn DatabaseAccess {
        self.connection.deref()
    }
}
}

Database truncation

The DatabaseConnection provides a truncate_database method but you should use it only for testing purposes, it is highly destructive as it will drop every collections known to the connection.