[][src]Struct aragog::DatabaseRecord

pub struct DatabaseRecord<T: Serialize + DeserializeOwned + Clone + Record> {
    pub key: String,
    pub record: T,
}

Struct representing database stored documents

The document of type T mut implement Serialize, DeserializeOwned, Clone and Record

Fields

key: String

The Document unique and indexed key

record: T

The deserialized stored document

Implementations

impl<T: Serialize + DeserializeOwned + Clone + Record> DatabaseRecord<T>[src]

pub async fn save<'_, '_>(
    &'_ mut self,
    db_pool: &'_ DatabaseConnectionPool
) -> Result<(), ServiceError> where
    T: Validate
[src]

Writes in the database the new state of the record, "saving it". The record will first be validates as it should implement the Validate trait.

Arguments:

  • db_pool - database connection pool reference

Returns

On success () is returned, meaning that the current instance is up to date with the database state. On failure a ServiceError is returned:

pub async fn delete<'_, '_>(
    &'_ self,
    db_pool: &'_ DatabaseConnectionPool
) -> Result<(), ServiceError>
[src]

Removes the record from the database. The structure won't be freed or emptied but the document won't exist in the global state

Arguments:

  • db_pool - database connection pool reference

Returns

On success () is returned, meaning that the record is now deleted, the structure should not be used afterwards. On failure a ServiceError is returned:

pub async fn find<'_, '_>(
    key: &'_ str,
    db_pool: &'_ DatabaseConnectionPool
) -> Result<Self, ServiceError>
[src]

Retrieves a record from the database with the associated unique key

Arguments:

  • key - the unique record key as a string slice
  • db_pool - database connection pool reference

Returns

On success Self is returned, On failure a ServiceError is returned:

pub async fn find_where<'_>(
    query: Query,
    db_pool: &'_ DatabaseConnectionPool
) -> Result<Self, ServiceError>
[src]

Retrieves a record from the database with the associated conditions. The function wraps a simple get_where for a single record instance to find.

Since the function attempts to retrieve one unique record, if the condition is matched by multiple documents the function will return an error. Use this function for conditions that are supposed to match only one document, the condition should probably be on a unique indexed field.

Arguments:

  • query - The Query to match
  • db_pool - database connection pool reference

Note

This is simply an AQL request wrapper.

Returns

On success Self is returned, On failure a ServiceError is returned:

Example

This example is not tested
use aragog::query::{Query, QueryItem};

let mut query = Query::new(QueryItem::field("username").equals_str("MichelDu93"))
    .and(QueryItem::field("age").greater_than(10));

User::find_where(query, &db_pool).await.unwrap();

pub async fn get_where<'_>(
    query: Query,
    db_pool: &'_ DatabaseConnectionPool
) -> Result<Vec<Self>, ServiceError>
[src]

Retrieves all records from the database matching the associated conditions.

Arguments:

  • query - The Query to match
  • db_pool - database connection pool reference

Note

This is simply an AQL request wrapper.

Returns

On success a vector of Self is returned. It is never empty. On failure a ServiceError is returned:

Example

This example is not tested
use aragog::query::{Query, QueryItem};

let mut query = Query::new(QueryItem::field("username").equals_str("MichelDu93"))
    .and(QueryItem::field("age").greater_than(10));

User::get_where(query, &db_pool).await.unwrap();

pub async fn exists_where<'_>(
    query: Query,
    db_pool: &'_ DatabaseConnectionPool
) -> bool
[src]

Checks if any document matching the associated conditions exist

Arguments:

  • query - The Query to match
  • db_pool - database connection pool reference

Note

This is simply an AQL request wrapper.

Returns

On success true is returned, false if nothing exists.

Example

This example is not tested
use aragog::query::{Query, QueryItem};

let mut query = Query::new(QueryItem::field("username").equals_str("MichelDu93"))
    .and(QueryItem::field("age").greater_than(10));

User::exists_where(query, &db_pool).await;

pub async fn create<'_>(
    record: T,
    db_pool: &'_ DatabaseConnectionPool
) -> Result<Self, ServiceError> where
    T: Validate
[src]

Creates a document in database The function will write a new document and return a database record containing the newly created key

Arguments

  • record - The document to create, it will be returned exactly as the DatabaseRecord<T> record
  • db_pool - database connection pool reference

Returns

On success a new instance of Self is returned, with the key value filled and record filled with the argument value On failure a ServiceError is returned:

pub fn from(doc_response: DocumentResponse<T>) -> Result<Self, ServiceError>[src]

Builds a DatabaseRecord from a arangors crate DocumentResponse<T> It will return the filled DatabaseRecord on success or will return a ServiceError::UnprocessableEntity on failure

pub fn authenticate(&self, password: &str) -> Result<(), ServiceError> where
    T: Authenticate
[src]

Authenticates the instance. The method is available if T implements Authenticate and will simply call the authenticate method on the record

Arguments

  • password - the value supposed to validate authentication, password or secret

Returns

On success () is returned, on failure it will return a ServiceError according to the Authenticate implementation

Trait Implementations

impl<T: Debug + Serialize + DeserializeOwned + Clone + Record> Debug for DatabaseRecord<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for DatabaseRecord<T> where
    T: RefUnwindSafe

impl<T> Send for DatabaseRecord<T> where
    T: Send

impl<T> Sync for DatabaseRecord<T> where
    T: Sync

impl<T> Unpin for DatabaseRecord<T> where
    T: Unpin

impl<T> UnwindSafe for DatabaseRecord<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.