TeilQuery

Struct TeilQuery 

Source
pub struct TeilQuery<T: Teil> { /* private fields */ }
Expand description

Simple wrapper around the query_vec function

Implementations§

Source§

impl<T: Teil> TeilQuery<T>

Source

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)]);
Source

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]);
Source

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);
Source

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);
Source

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>
where <T as Teil>::Filter: RefUnwindSafe, <T as Teil>::Sort: RefUnwindSafe,

§

impl<T> Send for TeilQuery<T>
where <T as Teil>::Filter: Send, <T as Teil>::Sort: Send,

§

impl<T> Sync for TeilQuery<T>
where <T as Teil>::Filter: Sync, <T as Teil>::Sort: Sync,

§

impl<T> Unpin for TeilQuery<T>
where <T as Teil>::Filter: Unpin, <T as Teil>::Sort: Unpin,

§

impl<T> UnwindSafe for TeilQuery<T>
where <T as Teil>::Filter: UnwindSafe, <T as Teil>::Sort: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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.

Source§

impl<T, U> Into<U> for T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V