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>
impl<'a> QueryBuilder<'a>
Sourcepub fn select(self, columns: impl Into<String>) -> Self
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.
Sourcepub fn insert<T: Serialize>(self, data: &T) -> Result<Self, Error>
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.
Sourcepub fn update<T: Serialize>(self, data: &T) -> Result<Self, Error>
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.
Sourcepub fn delete(self) -> Self
pub fn delete(self) -> Self
Prepares a delete operation.
Should be combined with filter methods to target specific rows.
Sourcepub fn eq(self, column: impl Into<String>, value: impl Into<String>) -> Self
pub fn eq(self, column: impl Into<String>, value: impl Into<String>) -> Self
Filter: column equals value (col=eq.val).
Sourcepub fn neq(self, column: impl Into<String>, value: impl Into<String>) -> Self
pub fn neq(self, column: impl Into<String>, value: impl Into<String>) -> Self
Filter: column not equals value (col=neq.val).
Sourcepub fn gt(self, column: impl Into<String>, value: impl Into<String>) -> Self
pub fn gt(self, column: impl Into<String>, value: impl Into<String>) -> Self
Filter: column greater than value (col=gt.val).
Sourcepub fn gte(self, column: impl Into<String>, value: impl Into<String>) -> Self
pub fn gte(self, column: impl Into<String>, value: impl Into<String>) -> Self
Filter: column greater than or equal to value (col=gte.val).
Sourcepub fn lt(self, column: impl Into<String>, value: impl Into<String>) -> Self
pub fn lt(self, column: impl Into<String>, value: impl Into<String>) -> Self
Filter: column less than value (col=lt.val).
Sourcepub fn lte(self, column: impl Into<String>, value: impl Into<String>) -> Self
pub fn lte(self, column: impl Into<String>, value: impl Into<String>) -> Self
Filter: column less than or equal to value (col=lte.val).
Sourcepub fn like(self, column: impl Into<String>, pattern: impl Into<String>) -> Self
pub fn like(self, column: impl Into<String>, pattern: impl Into<String>) -> Self
Filter: column matches pattern (col=like.pattern).
Use * as wildcard character.
Sourcepub fn ilike(
self,
column: impl Into<String>,
pattern: impl Into<String>,
) -> Self
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.
Sourcepub fn in_<I, S>(self, column: impl Into<String>, values: I) -> Self
pub fn in_<I, S>(self, column: impl Into<String>, values: I) -> Self
Filter: column value is in the provided list (col=in.(v1,v2,...)).
Sourcepub fn not_null(self, column: impl Into<String>) -> Self
pub fn not_null(self, column: impl Into<String>) -> Self
Filter: column is not null (col=not.is.null).
Sourcepub fn order(self, column: impl Into<String>) -> Self
pub fn order(self, column: impl Into<String>) -> Self
Orders results by the specified column.
Use "column" for ascending or "column.desc" for descending.
Sourcepub async fn execute(self) -> Result<Response, Error>
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.
Sourcepub async fn execute_and_parse<T: DeserializeOwned>(self) -> Result<T, Error>
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.