Struct teil::TeilQuery

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

Simple wrapper around the query_vec function

Implementations§

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

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

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

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

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§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more