[−][src]Struct aragog::DatabaseRecord
Struct representing database stored documents
The document of type T mut implement Serialize, DeserializeOwned, Clone and Record
Fields
key: StringThe Document unique and indexed _key
id: StringThe Document unique and indexed _id
rev: StringThe Document revision _rev
record: TThe 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]
&'_ mut self,
db_pool: &'_ DatabaseConnectionPool
) -> Result<(), ServiceError> where
T: Validate,
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:
Conflicton index uniqueness conflictUnprocessableEntityon data corruptionValidationErroron failed field validations
pub async fn delete<'_, '_>(
&'_ self,
db_pool: &'_ DatabaseConnectionPool
) -> Result<(), ServiceError>[src]
&'_ self,
db_pool: &'_ DatabaseConnectionPool
) -> Result<(), ServiceError>
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:
NotFoundon invalid document keyUnprocessableEntityon data corruption
pub async fn find<'_, '_>(
key: &'_ str,
db_pool: &'_ DatabaseConnectionPool
) -> Result<Self, ServiceError>[src]
key: &'_ str,
db_pool: &'_ DatabaseConnectionPool
) -> Result<Self, ServiceError>
Retrieves a record from the database with the associated unique key
Arguments:
key- the unique record key as a string slicedb_pool- database connection pool reference
Returns
On success Self is returned,
On failure a ServiceError is returned:
NotFoundon invalid document keyUnprocessableEntityon data corruption
pub async fn get<'_>(
query: Query,
db_pool: &'_ DatabaseConnectionPool
) -> Result<RecordQueryResult<T>, ServiceError>[src]
query: Query,
db_pool: &'_ DatabaseConnectionPool
) -> Result<RecordQueryResult<T>, ServiceError>
Retrieves all records from the database matching the associated conditions.
Arguments:
query- TheQueryto matchdb_pool- database connection pool reference
Note
This is simply an AQL request wrapper.
Returns
On success a QueryResult with a vector of Self is returned. It is can be empty.
On failure a ServiceError is returned:
NotFoundif no document matches the conditionUnprocessableEntityon data corruption
Example
use aragog::query::{Query, Comparison}; let mut query = Query::new().filter(Filter::new(Comparison::field("username").equals_str("MichelDu93")) .and(Comparison::field("age").greater_than(10)); User::get(query, &db_pool).await.unwrap();
pub async fn aql_get<'_, '_>(
query: &'_ str,
db_pool: &'_ DatabaseConnectionPool
) -> Result<RecordQueryResult<T>, ServiceError>[src]
query: &'_ str,
db_pool: &'_ DatabaseConnectionPool
) -> Result<RecordQueryResult<T>, ServiceError>
Retrieves all records from the database matching the associated conditions.
Arguments:
query- The AQL request stringdb_pool- database connection pool reference
Returns
On success a QueryResult with a vector of Self is returned. It is can be empty.
On failure a ServiceError is returned:
NotFoundif no document matches the conditionUnprocessableEntityon data corruption
Warning
If you call this method on a graph query only the documents that can be serialized into T will be returned.
Example
use aragog::query::{Query, Comparison}; let mut query = r#"FOR i in User FILTER i.username == "MichelDu93" && i.age > 10 return i"#; User::aql_get(query, &db_pool).await.unwrap();
pub fn outbound_query(&self, min: u16, max: u16, edge_collection: &str) -> Query[src]
Creates a new outbound graph Query with self as a start vertex
Arguments
edge_collection- The name of the queried edge collectionmin- The minimum depth of the graph requestmax- The maximum depth of the graph request
Example
let record = User::find("123", &database_pool).await.unwrap(); // Both statements are equivalent let q = record.outbound_query(1, 2, "ChildOf"); let q = Query::outbound(1, 2, "ChildOf", record.id);
pub fn inbound_query(&self, min: u16, max: u16, edge_collection: &str) -> Query[src]
Creates a new inbound graph Query with self as a start vertex
Arguments
edge_collection- The name of the queried edge collectionmin- The minimum depth of the graph requestmax- The maximum depth of the graph request
Example
let record = User::find("123", &database_pool).await.unwrap(); // Both statements are equivalent let q = record.inbound_query(1, 2, "ChildOf"); let q = Query::inbound(1, 2, "ChildOf", record.id);
pub fn outbound_graph(&self, min: u16, max: u16, named_graph: &str) -> Query[src]
Creates a new outbound graph Query with self as a start vertex
Arguments
min- The minimum depth of the graph requestmax- The maximum depth of the graph requestnamed_graph- The named graph to traverse
Example
let record = User::find("123", &database_pool).await.unwrap(); // Both statements are equivalent let q = record.outbound_graph(1, 2, "SomeGraph"); let q = Query::outbound_graph(1, 2, "SomeGraph", record.id);
pub fn inbound_graph(&self, min: u16, max: u16, named_graph: &str) -> Query[src]
Creates a new inbound graph Query with self as a start vertex
Arguments
min- The minimum depth of the graph requestmax- The maximum depth of the graph requestnamed_graph- The named graph to traverse
Example
let record = User::find("123", &database_pool).await.unwrap(); // Both statements are equivalent let q = record.inbound_graph(1, 2, "SomeGraph"); let q = Query::inbound_graph(1, 2, "SomeGraph", record.id);
pub async fn link<U, V, W, '_, '_, '_>(
from_record: &'_ DatabaseRecord<U>,
to_record: &'_ DatabaseRecord<V>,
db_pool: &'_ DatabaseConnectionPool,
document: W
) -> Result<DatabaseRecord<T>, ServiceError> where
U: Serialize + DeserializeOwned + Clone + Record,
V: Serialize + DeserializeOwned + Clone + Record,
T: EdgeRecord,
W: FnOnce(String, String) -> T, [src]
from_record: &'_ DatabaseRecord<U>,
to_record: &'_ DatabaseRecord<V>,
db_pool: &'_ DatabaseConnectionPool,
document: W
) -> Result<DatabaseRecord<T>, ServiceError> where
U: Serialize + DeserializeOwned + Clone + Record,
V: Serialize + DeserializeOwned + Clone + Record,
T: EdgeRecord,
W: FnOnce(String, String) -> T,
Creates and returns edge between from_record and target_record
Example
#[derive(Clone, EdgeRecord, Validate, Serialize, Deserialize)] struct Edge { _from: String, _to: String, description: String, } let record_a = Character::find("123", &database_connection_pool).await.unwrap(); let record_b = Character::find("234", &database_connection_pool).await.unwrap(); let edge = DatabaseRecord::link(&record_a, &record_b, &database_connection_pool, |_from, _to| { Edge { _from, _to, description: "description".to_string() } }).await.unwrap();
pub async fn exists<'_>(
query: Query,
db_pool: &'_ DatabaseConnectionPool
) -> bool[src]
query: Query,
db_pool: &'_ DatabaseConnectionPool
) -> bool
Checks if any document matching the associated conditions exist
Arguments:
query- TheQueryto matchdb_pool- database connection pool reference
Note
This is simply an AQL request wrapper.
Returns
On success true is returned, false if nothing exists.
Example
use aragog::query::{Query, Comparison}; let mut query = Query::new().filter(Filter::new(Comparison::field("username").equals_str("MichelDu93")) .and(Comparison::field("age").greater_than(10)); User::exists(query, &db_pool).await;
pub async fn create<'_>(
record: T,
db_pool: &'_ DatabaseConnectionPool
) -> Result<Self, ServiceError> where
T: Validate, [src]
record: T,
db_pool: &'_ DatabaseConnectionPool
) -> Result<Self, ServiceError> where
T: Validate,
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 theDatabaseRecord<T>recorddb_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:
UnprocessableEntityon data corruption
pub fn from_response(
doc_response: DocumentResponse<T>
) -> Result<Self, ServiceError>[src]
doc_response: DocumentResponse<T>
) -> Result<Self, ServiceError>
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]
T: Authenticate,
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
pub fn get_id(&self) -> String[src]
Retrieves the ArangoDB _id built as `$collection_name/$_key
Trait Implementations
impl<T: Debug + Serialize + DeserializeOwned + Clone + Record> Debug for DatabaseRecord<T>[src]
impl<T: Serialize + DeserializeOwned + Clone + Record> From<Document<T>> for DatabaseRecord<T>[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for DatabaseRecord<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for DatabaseRecord<T> where
T: Send,
T: Send,
impl<T> Sync for DatabaseRecord<T> where
T: Sync,
T: Sync,
impl<T> Unpin for DatabaseRecord<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for DatabaseRecord<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T> Instrument for T[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>[src]
pub fn in_current_span(self) -> Instrumented<Self>[src]
impl<T> Instrument for T[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>[src]
pub fn in_current_span(self) -> Instrumented<Self>[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,