pub struct TeilQuery<T: Teil> { /* private fields */ }Expand description
Simple wrapper around the query_vec function
Implementations§
Source§impl<T: Teil> TeilQuery<T>
impl<T: Teil> TeilQuery<T>
Sourcepub fn filters(self, filters: Vec<T::Filter>) -> Self
pub fn filters(self, filters: Vec<T::Filter>) -> Self
Specifies a vector of filters to be applied to the query
This function can be called multiple times, and the resulting filter will be a chain of all provided filters before calling execute.
use teil::{Teil, Filter};
#[derive(Filter)]
enum AccountFilter {
#[teil(target = "balance", less_or_equal_than)]
MaxBalance(f64)
}
#[derive(Teil)]
#[teil(filter_type = "AccountFilter")]
struct Account {
#[teil(primary_key)]
owner: String,
balance: f64
}
// Prepare the db and so on...
// Query that does not return registers with a balance higher than 1,000
let query = Account::query().filters(vec![AccountFilter::MaxBalance(1_000.0)]);Sourcepub fn sort(self, sort: Vec<T::Sort>) -> Self
pub fn sort(self, sort: Vec<T::Sort>) -> Self
Specifies a vector of sort instructions to be applied to the query
This function can be called multiple times, and the resulting sort instruction will be a chain of all provided sort instructions before calling execute.
use teil::{Teil, Sort};
#[derive(Sort)]
enum AccountSort {
#[teil(target = "balance", desc)]
Richest
}
#[derive(Teil)]
#[teil(sort_type = "AccountSort")]
struct Account {
#[teil(primary_key)]
owner: String,
balance: f64
}
// Prepare the db and so on...
// Query that returns everything in the DB sorted from highest balance to lowest
let query = Account::query().sort(vec![AccountSort::Richest]);Sourcepub fn skip(self, num_elements: usize) -> Self
pub fn skip(self, num_elements: usize) -> Self
Indicates that a certain amount of registers shall be skipped when running the query
use teil::{Teil};
#[derive(Teil)]
struct Account {
#[teil(primary_key)]
owner: String,
balance: f64
}
// Prepare the db and so on...
// Query that skips the first 2 satisfactory registers from the result
let query = Account::query().skip(2);Sourcepub fn limit(self, limit: usize) -> Self
pub fn limit(self, limit: usize) -> Self
Indicates a limit for the number of elements that the query should return
use teil::{Teil};
#[derive(Teil)]
struct Account {
#[teil(primary_key)]
owner: String,
balance: f64
}
// Prepare the db and so on...
// Query that returns maximum 10 elements
let query = Account::query().limit(10);Sourcepub async fn execute(self) -> Result<Vec<T>, Error>
pub async fn execute(self) -> Result<Vec<T>, Error>
Executes the query
use teil::{Teil};
#[derive(Teil)]
struct Account {
#[teil(primary_key)]
owner: String,
balance: f64
}
// Prepare the db and so on...
// Query that skips the first 2 satisfactory registers from the result
let res = match Account::query().execute().await {
Ok(res) => res,
Err(e) => panic!("Could not execute query! {}", e)
};
// Do something with the vector of elements...Auto Trait Implementations§
impl<T> Freeze for TeilQuery<T>
impl<T> RefUnwindSafe for TeilQuery<T>
impl<T> Send for TeilQuery<T>
impl<T> Sync for TeilQuery<T>
impl<T> Unpin for TeilQuery<T>
impl<T> UnwindSafe for TeilQuery<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more