Skip to main content

QueryBuilder

Struct QueryBuilder 

Source
pub struct QueryBuilder<'a> { /* private fields */ }
Expand description

Query builder for PostgREST database operations.

Provides a fluent API for constructing and executing database queries.

Use execute() to get the raw response, or execute_and_parse() to deserialize the JSON body.

Implementations§

Source§

impl<'a> QueryBuilder<'a>

Source

pub fn select(self, columns: impl Into<String>) -> Self

Specifies which columns to select.

Pass "*" to select all columns, or a comma-separated list of column names.

Source

pub fn insert<T: Serialize>(self, data: &T) -> Result<Self, Error>

Prepares an insert operation with the provided data.

Data will be serialized to JSON. Call execute() to run the query.

Source

pub fn update<T: Serialize>(self, data: &T) -> Result<Self, Error>

Prepares an update operation with the provided data.

Should be combined with filter methods to target specific rows.

Source

pub fn delete(self) -> Self

Prepares a delete operation.

Should be combined with filter methods to target specific rows.

Source

pub fn eq(self, column: impl Into<String>, value: impl Into<String>) -> Self

Filter: column equals value (col=eq.val).

Source

pub fn neq(self, column: impl Into<String>, value: impl Into<String>) -> Self

Filter: column not equals value (col=neq.val).

Source

pub fn gt(self, column: impl Into<String>, value: impl Into<String>) -> Self

Filter: column greater than value (col=gt.val).

Source

pub fn gte(self, column: impl Into<String>, value: impl Into<String>) -> Self

Filter: column greater than or equal to value (col=gte.val).

Source

pub fn lt(self, column: impl Into<String>, value: impl Into<String>) -> Self

Filter: column less than value (col=lt.val).

Source

pub fn lte(self, column: impl Into<String>, value: impl Into<String>) -> Self

Filter: column less than or equal to value (col=lte.val).

Source

pub fn like(self, column: impl Into<String>, pattern: impl Into<String>) -> Self

Filter: column matches pattern (col=like.pattern).

Use * as wildcard character.

Source

pub fn ilike( self, column: impl Into<String>, pattern: impl Into<String>, ) -> Self

Filter: column matches pattern case-insensitively (col=ilike.pattern).

Use * as wildcard character.

Source

pub fn in_<I, S>(self, column: impl Into<String>, values: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Filter: column value is in the provided list (col=in.(v1,v2,...)).

Source

pub fn is_null(self, column: impl Into<String>) -> Self

Filter: column is null (col=is.null).

Source

pub fn not_null(self, column: impl Into<String>) -> Self

Filter: column is not null (col=not.is.null).

Source

pub fn order(self, column: impl Into<String>) -> Self

Orders results by the specified column.

Use "column" for ascending or "column.desc" for descending.

Source

pub fn limit(self, count: usize) -> Self

Limits the number of rows returned.

Source

pub fn offset(self, count: usize) -> Self

Offsets the results by the specified number of rows.

Source

pub async fn execute(self) -> Result<Response, Error>

Executes the query and returns the raw response.

Returns Error::Api if the server responds with a non-2xx status code.

Source

pub async fn execute_and_parse<T: DeserializeOwned>(self) -> Result<T, Error>

Executes the query and deserializes the JSON response body into T.

This is a convenience wrapper around execute() that also parses the response body.

Auto Trait Implementations§

§

impl<'a> Freeze for QueryBuilder<'a>

§

impl<'a> !RefUnwindSafe for QueryBuilder<'a>

§

impl<'a> Send for QueryBuilder<'a>

§

impl<'a> Sync for QueryBuilder<'a>

§

impl<'a> Unpin for QueryBuilder<'a>

§

impl<'a> !UnwindSafe for QueryBuilder<'a>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more