Skip to main content

SqlQuery

Struct SqlQuery 

Source
pub struct SqlQuery<'a, T: SqlEntity> { /* private fields */ }
Expand description

A query builder. This is the main structure to build the SQL queries using a templating system. It is designed to be a composable structure to build the SQL queries alongside the according parameters. The query is built using the set_variable method to set the variables and the add_parameter method to add the parameters. The query is expanded using the expand method to get the SQL query and the parameters.

Implementations§

Source§

impl<'a, T: SqlEntity> SqlQuery<'a, T>

Source

pub fn new(query: &str) -> Self

Create a new query using the given string as a SQL template. The template is a string with the variables enclosed in {:variable:} placeholders. The default variable is the projection of the entity.

Source

pub fn set_variable(&mut self, name: &'a str, value: &str) -> &mut Self

Set a variable in the query. This variable will be replaced by its value in the query.

Source

pub fn add_parameter(&mut self, parameter: &'a dyn ToSqlAny) -> &mut Self

Add a parameter to the query. This parameter will be replaced by its value in the query. The parameter will be expanded in the $? placeholder.

Source

pub fn append_parameters( &mut self, parameters: Vec<&'a dyn ToSqlAny>, ) -> &mut Self

Append a vec of parameters to the query.

Source

pub fn set_parameters(&mut self, parameters: Vec<&'a dyn ToSqlAny>) -> &mut Self

Set the parameters of the query.

Source

pub fn get_variables(&self) -> &HashMap<&'a str, String>

Return the variables of the query.

Source

pub fn get_parameters(&self) -> Vec<&'a dyn ToSqlAny>

Return the parameters of the query. This method is mostly intended for testing purposes since the parameters are cloned.

Source

pub fn expand(self) -> (String, Vec<&'a dyn ToSqlAny>)

Return the query and the parameters to be sent to the server. This consumes the query instance.

Trait Implementations§

Source§

impl<'a, T: SqlEntity> Display for SqlQuery<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for SqlQuery<'a, T>

§

impl<'a, T> !RefUnwindSafe for SqlQuery<'a, T>

§

impl<'a, T> Send for SqlQuery<'a, T>
where T: Send,

§

impl<'a, T> Sync for SqlQuery<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for SqlQuery<'a, T>
where T: Unpin,

§

impl<'a, T> UnsafeUnpin for SqlQuery<'a, T>

§

impl<'a, T> !UnwindSafe for SqlQuery<'a, T>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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