Struct aragog::DatabaseRecord [−][src]
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
impl<T: Record> DatabaseRecord<T>
[src]
pub async fn create<D>(record: T, db_accessor: &D) -> Result<Self, ServiceError> where
D: DatabaseAccess,
[src]
D: DatabaseAccess,
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
.
Arguments
record
- The document to create, it will be returned exactly as theDatabaseRecord<T>
recorddb_accessor
- 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:
UnprocessableEntity
on data corruption- Any error returned by hooks
pub async fn force_create<D>(
record: T,
db_accessor: &D
) -> Result<Self, ServiceError> where
D: DatabaseAccess,
[src]
record: T,
db_accessor: &D
) -> Result<Self, ServiceError> where
D: DatabaseAccess,
Creates a document in database skipping hooks. The function will write a new document and return a database record containing the newly created key.
Hooks
This function will skip all hooks.
Arguments
record
- The document to create, it will be returned exactly as theDatabaseRecord<T>
recorddb_accessor
- 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:
UnprocessableEntity
on data corruption
pub async fn save<D>(&mut self, db_accessor: &D) -> Result<(), ServiceError> where
D: DatabaseAccess,
[src]
D: DatabaseAccess,
Writes in the database the new state of the record, "saving it".
Hooks
This function will launch T
hooks before_save
and after_save
.
Arguments:
db_accessor
- 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:
Conflict
on index uniqueness conflictUnprocessableEntity
on data corruption- Any error returned by hooks
pub async fn force_save<D>(
&mut self,
db_accessor: &D
) -> Result<(), ServiceError> where
D: DatabaseAccess,
[src]
&mut self,
db_accessor: &D
) -> Result<(), ServiceError> where
D: DatabaseAccess,
Writes in the database the new state of the record, skipping hooks.
Hooks
This function will skip all hooks.
Arguments:
db_accessor
- 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:
Conflict
on index uniqueness conflictUnprocessableEntity
on data corruption
pub async fn delete<D>(&mut self, db_accessor: &D) -> Result<(), ServiceError> where
D: DatabaseAccess,
[src]
D: DatabaseAccess,
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
.
Arguments:
db_accessor
- 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:
NotFound
on invalid document keyUnprocessableEntity
on data corruption- Any error returned by hooks
pub async fn force_delete<D>(&self, db_accessor: &D) -> Result<(), ServiceError> where
D: DatabaseAccess,
[src]
D: DatabaseAccess,
Removes the record from the database, skipping hooks. The structure won't be freed or emptied but the document won't exist in the global state
Hooks
This function will skip all hooks.
Arguments:
db_accessor
- 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:
NotFound
on invalid document keyUnprocessableEntity
on data corruption
pub async fn link<A, B, D, E>(
from_record: &DatabaseRecord<A>,
to_record: &DatabaseRecord<B>,
db_accessor: &D,
edge_record: E
) -> Result<DatabaseRecord<T>, ServiceError> where
A: Serialize + DeserializeOwned + Clone + Record,
B: Serialize + DeserializeOwned + Clone + Record,
D: DatabaseAccess,
E: FnOnce(String, String) -> T,
T: EdgeRecord,
[src]
from_record: &DatabaseRecord<A>,
to_record: &DatabaseRecord<B>,
db_accessor: &D,
edge_record: E
) -> Result<DatabaseRecord<T>, ServiceError> where
A: Serialize + DeserializeOwned + Clone + Record,
B: Serialize + DeserializeOwned + Clone + Record,
D: DatabaseAccess,
E: FnOnce(String, String) -> T,
T: EdgeRecord,
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, EdgeRecord, Record, Serialize, Deserialize)] struct Edge { _from: String, _to: String, description: String, } let record_a = User::find("123", &db_accessor).await.unwrap(); let record_b = User::find("234", &db_accessor).await.unwrap(); let edge = DatabaseRecord::link(&record_a, &record_b, &db_accessor, |_from, _to| { Edge { _from, _to, description: "description".to_string() } }).await.unwrap();
pub async fn find<D>(key: &str, db_accessor: &D) -> Result<Self, ServiceError> where
D: DatabaseAccess,
[src]
D: DatabaseAccess,
Retrieves a record from the database with the associated unique key
Arguments:
key
- the unique record key as a string slicedb_accessor
- database connection pool reference
Returns
On success Self
is returned,
On failure a ServiceError
is returned:
NotFound
on invalid document keyUnprocessableEntity
on data corruption
pub async fn reload<D>(self, db_accessor: &D) -> Result<Self, ServiceError> where
D: DatabaseAccess,
T: Send,
[src]
D: DatabaseAccess,
T: Send,
Reloads a record from the database, returning the new record.
Arguments
db_accessor
- database connection pool reference
Returns
On success Self
is returned,
On failure a ServiceError
is returned:
NotFound
on invalid document keyUnprocessableEntity
on data corruption
pub async fn reload_mut<D>(
&mut self,
db_accessor: &D
) -> Result<(), ServiceError> where
D: DatabaseAccess,
T: Send,
[src]
&mut self,
db_accessor: &D
) -> Result<(), ServiceError> where
D: DatabaseAccess,
T: Send,
Reloads a record from the database.
Returns
On success ()
is returned and self
is updated,
On failure a ServiceError
is returned:
NotFound
on invalid document keyUnprocessableEntity
on data corruption
pub async fn get<D>(
query: Query,
db_accessor: &D
) -> Result<RecordQueryResult<T>, ServiceError> where
D: DatabaseAccess,
[src]
query: Query,
db_accessor: &D
) -> Result<RecordQueryResult<T>, ServiceError> where
D: DatabaseAccess,
Retrieves all records from the database matching the associated conditions.
Arguments:
query
- TheQuery
to matchdb_accessor
- 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:
NotFound
if no document matches the conditionUnprocessableEntity
on data corruption
Example
let query = User::query().filter(Filter::new(Comparison::field("username").equals_str("MichelDu93")) .and(Comparison::field("age").greater_than(10))); // Both lines are equivalent: DatabaseRecord::<User>::get(query.clone(), &db_accessor).await.unwrap(); User::get(query.clone(), &db_accessor).await.unwrap();
pub async fn aql_get<D>(
query: &str,
db_accessor: &D
) -> Result<RecordQueryResult<T>, ServiceError> where
D: DatabaseAccess,
[src]
query: &str,
db_accessor: &D
) -> Result<RecordQueryResult<T>, ServiceError> where
D: DatabaseAccess,
Retrieves all records from the database matching the associated conditions.
Arguments:
query
- The AQL request stringdb_accessor
- 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:
NotFound
if no document matches the conditionUnprocessableEntity
on 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
let query = r#"FOR i in User FILTER i.username == "MichelDu93" && i.age > 10 return i"#; DatabaseRecord::<User>::aql_get(query, &db_accessor).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", &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());
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", &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());
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", &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());
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", &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());
pub async fn exists<D>(query: Query, db_accessor: &D) -> bool where
D: DatabaseAccess,
[src]
D: DatabaseAccess,
Checks if any document matching the associated conditions exist
Arguments:
query
- TheQuery
to matchdb_accessor
- database connection pool 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;
pub fn id(&self) -> &String
[src]
Getter for the Document _id
built as `$collection_name/$_key
pub fn key(&self) -> &String
[src]
Getter for the Document _key
pub fn rev(&self) -> &String
[src]
Getter for the Document _rev
Trait Implementations
impl<T: Clone + Record> Clone for DatabaseRecord<T>
[src]
fn clone(&self) -> DatabaseRecord<T>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug + Record> Debug for DatabaseRecord<T>
[src]
impl<T: Record> Deref for DatabaseRecord<T>
[src]
impl<T: Record> DerefMut for DatabaseRecord<T>
[src]
impl<T: Record> Display for DatabaseRecord<T>
[src]
impl<T: 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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,