Trait pastebin::DbInterface [] [src]

pub trait DbInterface: Send + Sync {
    fn store_data(&self, id: ObjectId, data: &[u8]) -> Result<(), DbError>;
fn load_data(&self, id: ObjectId) -> Result<Option<Vec<u8>>, DbError>;
fn remove_data(&self, id: ObjectId) -> Result<(), DbError>;
fn max_data_size(&self) -> usize; }

Interface to a database.

To store and retrieve pastes from a database we only need several functions. And we can describe them to be abstract enough to be easily used with just any kind of database, be it SQL, NoSQL or just a hash table or whatever.

Required Methods

Stores the data into the database under a given ID.

Unique ID has to be generated before calling this method. It might be found to be an extra burden since usually a database will generate an ID for you, but generating it in advance actually makes you not to rely on a database to return the generated ID. As of MongoDB, the identifier is generated on the client side anyhow.

Loads data from the database.

Returns a corresponding data if found, None otherwise.

Removes data from the database.

Normally we don't care whether an object exists in the database or not, so an implementation doesn't have to check that fact, and usually databases are okay with attempts to remove something that doesn't exist.

Tells the maximum data size that could be handled.

This is useful, for example, for MongoDB which has a limit on a BSON document size.

Implementors