Struct aragog::DatabaseRecord

source ·
pub struct DatabaseRecord<T> {
    pub record: T,
    /* private fields */
}
Expand description

Struct representing database stored documents.

The document of type T mut implement Record

Note

DatabaseRecord implements Deref and DerefMut into T

Fields§

§record: T

The deserialized stored document

Implementations§

source§

impl<T: Record> DatabaseRecord<T>

source

pub async fn create_with_options<D>( record: T, db_accessor: &D, options: OperationOptions ) -> Result<Self, Error>where D: DatabaseAccess + ?Sized,

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

Note

This method should be used for very specific cases, prefer using create instead. If you want global operation options (always wait for sync, always ignore hooks, etc) configure your DatabaseConnection with with_operation_options to have a customs set of default options.

Hooks

This function will launch T hooks before_create and after_create unless the options argument disables hooks.

Arguments
  • record - The document to create, it will be returned exactly as the DatabaseRecord<T> record
  • db_accessor - database connection reference
  • options - Operation options to apply
Returns

On success a new instance of Self is returned, with the key value filled and record filled with the argument value. An Error is returned if the operation or the hooks failed.

source

pub async fn create_with_key_and_options<D>( record: T, key: String, db_accessor: &D, options: OperationOptions ) -> Result<Self, Error>where D: DatabaseAccess + ?Sized,

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

Note

This method should be used for very specific cases, prefer using create_with_key instead. If you want global operation options (always wait for sync, always ignore hooks, etc) configure your DatabaseConnection with with_operation_options to have a customs set of default options.

Hooks

This function will launch T hooks before_create and after_create unless the options argument disables hooks.

Arguments
  • record - The document to create, it will be returned exactly as the DatabaseRecord<T> record
  • key - The custom key to apply
  • db_accessor - database connection reference
  • options - Operation options to apply
Returns

On success a new instance of Self is returned, with the key value filled and record filled with the argument value. An Error is returned if the operation or the hooks failed.

source

pub async fn create<D>(record: T, db_accessor: &D) -> Result<Self, Error>where D: DatabaseAccess + ?Sized,

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

Hooks

This function will launch T hooks before_create and after_create unless the db_accessor operations options specifically disable hooks.

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

On success a new instance of Self is returned, with the key value filled and record filled with the argument value. An Error is returned if the operation or the hooks failed.

source

pub async fn create_with_key<D>( record: T, key: String, db_accessor: &D ) -> Result<Self, Error>where D: DatabaseAccess + ?Sized,

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

Hooks

This function will launch T hooks before_create and after_create unless the db_accessor operations options specifically disable hooks.

Arguments
  • record - The document to create, it will be returned exactly as the DatabaseRecord<T> record
  • key - the custom document key
  • db_accessor - database connection reference
Returns

On success a new instance of Self is returned, with the key value filled and record filled with the argument value. An Error is returned if the operation or the hooks failed.

source

pub async fn force_create<D>(record: T, db_accessor: &D) -> Result<Self, Error>where D: DatabaseAccess + ?Sized,

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

Note

This function will override the default operations options:

  • Revision will be ignored
  • Hooks will be skipped and should be used sparingly.
Hooks

This function will skip all hooks.

Arguments
  • record - The document to create, it will be returned exactly as the DatabaseRecord<T> record
  • db_accessor - database connection 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 an Error is returned.

source

pub async fn save_with_options<D>( &mut self, db_accessor: &D, options: OperationOptions ) -> Result<(), Error>where D: DatabaseAccess + ?Sized,

Writes in the database the new state of the record, “saving it”.

Note

This method should be used for very specific cases, prefer using save instead. If you want global operation options (always wait for sync, always ignore hooks, etc) configure your DatabaseConnection with with_operation_options to have a customs set of default options.

Hooks

This function will launch T hooks before_save and after_save unless the options argument disables hooks.

Arguments:
  • db_accessor - database connection reference
  • options - Operation options to apply
Returns

On success () is returned, meaning that the current instance is up to date with the database state. An Error is returned if the operation or the hooks failed.

source

pub async fn save<D>(&mut self, db_accessor: &D) -> Result<(), Error>where D: DatabaseAccess + ?Sized,

Writes in the database the new state of the record, “saving it”.

Hooks

This function will launch T hooks before_save and after_save unless the db_accessor operations options specifically disable hooks.

Arguments:
  • db_accessor - database connection reference
Returns

On success () is returned, meaning that the current instance is up to date with the database state. An Error is returned if the operation or the hooks failed.

source

pub async fn force_save<D>(&mut self, db_accessor: &D) -> Result<(), Error>where D: DatabaseAccess + ?Sized,

Writes in the database the new state of the record.

Note

This function will override the default operations options:

  • Revision will be ignored
  • Hooks will be skipped and should be used sparingly.
Hooks

This function will skip all hooks.

Arguments:
  • db_accessor - database connection reference
Returns

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

source

pub async fn delete_with_options<D>( &mut self, db_accessor: &D, options: OperationOptions ) -> Result<(), Error>where D: DatabaseAccess + ?Sized,

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

Note

This method should be used for very specific cases, prefer using delete instead. If you want global operation options (always wait for sync, always ignore hooks, etc) configure your DatabaseConnection with with_operation_options to have a customs set of default options

Hooks

This function will launch T hooks before_delete and after_delete unless the options argument disables hooks.

Arguments:
  • db_accessor - database connection reference
Returns

On success () is returned, meaning that the record is now deleted, the structure should not be used afterwards. An Error is returned if the operation or the hooks failed.

source

pub async fn delete<D>(&mut self, db_accessor: &D) -> Result<(), Error>where D: DatabaseAccess + ?Sized,

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

Hooks

This function will launch T hooks before_delete and after_delete unless the db_accessor operations options specifically disable hooks.

Arguments:
  • db_accessor - database connection reference
Returns

On success () is returned, meaning that the record is now deleted, the structure should not be used afterwards. An Error is returned if the operation or the hooks failed.

source

pub async fn force_delete<D>(&mut self, db_accessor: &D) -> Result<(), Error>where D: DatabaseAccess + ?Sized,

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

Note

This function will override the default operations options:

  • Revision will be ignored
  • Hooks will be skipped and should be used sparingly.
Hooks

This function will skip all hooks.

Arguments:
  • db_accessor - database connection reference
Returns

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

Creates and returns edge between from_record and target_record.

Hooks

This function will launch T hooks before_create and after_create.

Example
#[derive(Clone, Record, Serialize, Deserialize)]
struct Edge {
    description: String,
}

let user_a = DatabaseRecord::create(User { }, &db_accessor).await.unwrap();
let user_b = DatabaseRecord::create(User { }, &db_accessor).await.unwrap();

let edge = DatabaseRecord::link(&user_a, &user_b, &db_accessor,
    Edge { description: "description".to_string() }
).await.unwrap();
assert_eq!(edge.id_from(), user_a.id());
assert_eq!(edge.id_to(), user_b.id());
assert_eq!(&edge.description, "description");
source

pub async fn find<D>(key: &str, db_accessor: &D) -> Result<Self, Error>where D: DatabaseAccess + ?Sized,

Retrieves a record from the database with the associated unique key

Arguments:
  • key - the unique record key as a string slice
  • db_accessor - database connection reference
Returns

On success Self is returned, On failure an Error is returned:

source

pub async fn reload<D>(self, db_accessor: &D) -> Result<Self, Error>where D: DatabaseAccess + ?Sized, T: Send,

Reloads a record from the database, returning the new record.

Arguments
  • db_accessor - database connection reference
Returns

On success Self is returned, On failure an Error is returned:

source

pub async fn reload_mut<D>(&mut self, db_accessor: &D) -> Result<(), Error>where D: DatabaseAccess + ?Sized, T: Send,

Reloads a record from the database.

Returns

On success () is returned and self is updated, On failure an Error is returned:

source

pub async fn get<D>( query: &Query, db_accessor: &D ) -> Result<QueryResult<T>, Error>where D: DatabaseAccess + ?Sized,

Retrieves all records from the database matching the associated conditions.

Arguments:
  • query - The Query to match
  • db_accessor - database connection reference
Note

This is simply an AQL request wrapper.

Returns

On success a QueryResult with a vector of Self is returned. It can be empty. On failure an Error is returned:

Example
let query = User::query().filter(Filter::new(Comparison::field("username").equals_str("RobertSurcouf"))
    .and(Comparison::field("age").greater_than(10)));

// Both lines are equivalent:
DatabaseRecord::<User>::get(&query, &db_accessor).await.unwrap();
User::get(&query, &db_accessor).await.unwrap();
source

pub async fn get_in_batches<D>( query: &Query, db_accessor: &D, batch_size: u32 ) -> Result<QueryCursor<T>, Error>where D: DatabaseAccess + ?Sized,

Retrieves all records from the database matching the associated conditions in batches.

Arguments:
  • query - The Query to match
  • db_accessor - database connection reference
  • batch_size- The maximum number of documents in a batch
Returns

On success a QueryCursor is returned. It can be empty. On failure an Error is returned:

Example
let query = User::query().filter(Filter::new(Comparison::field("age").greater_than(10)));

// Both lines are equivalent:
DatabaseRecord::<User>::get_in_batches(&query, &db_accessor, 100).await.unwrap();
User::get_in_batches(&query, &db_accessor, 100).await.unwrap();
source

pub async fn aql_get<D>( query: &str, db_accessor: &D ) -> Result<QueryResult<T>, Error>where D: DatabaseAccess + ?Sized,

Retrieves all records from the database matching the associated conditions.

Arguments:
  • query - The AQL request string
  • db_accessor - database connection reference
Returns

On success a QueryResult with a vector of Self is returned. It is can be empty. On failure an Error is returned:

Warning

If you call this method on a graph query only the documents that can be serialized into T will be returned.

Example
let query = r#"FOR i in User FILTER i.username == "RoertSurcouf" && i.age > 10 return i"#;

DatabaseRecord::<User>::aql_get(query, &db_accessor).await.unwrap();
source

pub fn outbound_query(&self, min: u16, max: u16, edge_collection: &str) -> Query

Creates a new outbound graph Query with self as a start vertex

Arguments
  • edge_collection- The name of the queried edge collection
  • min - The minimum depth of the graph request
  • max - The maximum depth of the graph request
Example
let record = User::find("123", &db_accessor).await.unwrap();
// Both statements are equivalent
let q = record.outbound_query(1, 2, "ChildOf");
let q = Query::outbound(1, 2, "ChildOf", record.id());
source

pub fn inbound_query(&self, min: u16, max: u16, edge_collection: &str) -> Query

Creates a new inbound graph Query with self as a start vertex

Arguments
  • edge_collection- The name of the queried edge collection
  • min - The minimum depth of the graph request
  • max - The maximum depth of the graph request
Example
let record = User::find("123", &db_accessor).await.unwrap();
// Both statements are equivalent
let q = record.inbound_query(1, 2, "ChildOf");
let q = Query::inbound(1, 2, "ChildOf", record.id());
source

pub fn outbound_graph(&self, min: u16, max: u16, named_graph: &str) -> Query

Creates a new outbound graph Query with self as a start vertex

Arguments
  • min - The minimum depth of the graph request
  • max - The maximum depth of the graph request
  • named_graph- The named graph to traverse
Example
let record = User::find("123", &db_accessor).await.unwrap();
// Both statements are equivalent
let q = record.outbound_graph(1, 2, "SomeGraph");
let q = Query::outbound_graph(1, 2, "SomeGraph", record.id());
source

pub fn inbound_graph(&self, min: u16, max: u16, named_graph: &str) -> Query

Creates a new inbound graph Query with self as a start vertex

Arguments
  • min - The minimum depth of the graph request
  • max - The maximum depth of the graph request
  • named_graph- The named graph to traverse
Example
let record = User::find("123", &db_accessor).await.unwrap();
// Both statements are equivalent
let q = record.inbound_graph(1, 2, "SomeGraph");
let q = Query::inbound_graph(1, 2, "SomeGraph", record.id());
source

pub async fn exists<D>(query: &Query, db_accessor: &D) -> boolwhere D: DatabaseAccess + ?Sized,

Checks if any document matching the associated conditions exist

Arguments:
  • query - The Query to match
  • db_accessor - database connection reference
Note

This is simply an AQL request wrapper.

Returns

On success true is returned, false if nothing exists.

Example
let query = User::query().filter(
    Filter::new(Comparison::field("username").equals_str("MichelDu93"))
        .and(Comparison::field("age").greater_than(10)));
User::exists(&query, &db_accessor).await;
source

pub fn id(&self) -> &String

Getter for the Document _id built as $collection_name/$_key

source

pub fn key(&self) -> &String

Getter for the Document _key

source

pub fn rev(&self) -> &String

Getter for the Document _rev

Trait Implementations§

source§

impl<T: Clone> Clone for DatabaseRecord<T>

source§

fn clone(&self) -> DatabaseRecord<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for DatabaseRecord<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Record> Deref for DatabaseRecord<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T: Record> DerefMut for DatabaseRecord<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'de, T> Deserialize<'de> for DatabaseRecord<T>where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: Record> Display for DatabaseRecord<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Record> From<Document<T>> for DatabaseRecord<T>

source§

fn from(doc: Document<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Record> FromIterator<DatabaseRecord<T>> for QueryResult<T>

source§

fn from_iter<I: IntoIterator<Item = DatabaseRecord<T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T> Serialize for DatabaseRecord<T>where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Record> TryInto<DatabaseRecord<T>> for DocumentResponse<DatabaseRecord<T>>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<DatabaseRecord<T>, Self::Error>

Performs the conversion.
source§

impl<T: Record> TryInto<DatabaseRecord<T>> for DocumentResponse<DatabaseRecordDto<T>>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<DatabaseRecord<T>, Self::Error>

Performs the conversion.

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,