pub struct SQLQuery { /* private fields */ }Expand description
SQL-like query for Redis Search.
Holds a SQL SELECT statement and optional named parameters. Parameter
placeholders use the :name syntax (e.g. :id, :product_id).
When used with SearchIndex::query(), the SQL is parsed and translated
into a Redis Search FT.SEARCH filter string. Non-aggregate queries with
WHERE, ORDER BY, LIMIT, and OFFSET clauses are supported.
§Example
use redis_vl::{SQLQuery, SqlParam};
let query = SQLQuery::new("SELECT * FROM idx WHERE price > :min_price")
.with_param("min_price", SqlParam::Float(99.99));
assert!(!query.substituted_sql().contains(":min_price"));
assert!(query.substituted_sql().contains("99.99"));Implementations§
Source§impl SQLQuery
impl SQLQuery
Sourcepub fn with_params(
sql: impl Into<String>,
params: HashMap<String, SqlParam>,
) -> Self
pub fn with_params( sql: impl Into<String>, params: HashMap<String, SqlParam>, ) -> Self
Creates an SQL query with pre-populated parameters.
Sourcepub fn with_param(self, name: impl Into<String>, value: SqlParam) -> Self
pub fn with_param(self, name: impl Into<String>, value: SqlParam) -> Self
Adds a single named parameter.
Sourcepub fn params_map(&self) -> &HashMap<String, SqlParam>
pub fn params_map(&self) -> &HashMap<String, SqlParam>
Returns the parameter map.
Sourcepub fn substituted_sql(&self) -> String
pub fn substituted_sql(&self) -> String
Returns the SQL string with non-binary parameters substituted.
Uses a token-based approach: splits the SQL on :param boundaries to
prevent partial matching (:id inside :product_id stays intact).
Single quotes in string values are SQL-escaped (' → '').
Sourcepub fn is_aggregate(&self) -> bool
pub fn is_aggregate(&self) -> bool
Returns true if this SQL query is an aggregate query (contains
aggregate functions like COUNT, SUM, AVG, etc., or GROUP BY).
Aggregate queries are translated to FT.AGGREGATE rather than
FT.SEARCH.
Sourcepub fn build_aggregate_cmd(&self, index_name: &str) -> Option<Cmd>
pub fn build_aggregate_cmd(&self, index_name: &str) -> Option<Cmd>
Builds an FT.AGGREGATE command for aggregate SQL queries.
Returns None if the SQL is not an aggregate query.
The index_name parameter is the Redis Search index to query.
Sourcepub fn is_vector_query(&self) -> bool
pub fn is_vector_query(&self) -> bool
Returns true if this SQL query contains vector search functions
(vector_distance() or cosine_distance()).
Sourcepub fn is_geo_aggregate(&self) -> bool
pub fn is_geo_aggregate(&self) -> bool
Returns true if this SQL query contains geo_distance() in the
SELECT clause (which generates FT.AGGREGATE with APPLY geodistance).
Sourcepub fn build_geo_aggregate_cmd(&self, index_name: &str) -> Option<Cmd>
pub fn build_geo_aggregate_cmd(&self, index_name: &str) -> Option<Cmd>
Builds an FT.AGGREGATE command for geo_distance in SELECT.
Returns None if the SQL doesn’t have geo_distance() in SELECT.
Trait Implementations§
Source§impl QueryString for SQLQuery
impl QueryString for SQLQuery
Source§fn to_redis_query(&self) -> String
fn to_redis_query(&self) -> String
Source§fn params(&self) -> Vec<QueryParam>
fn params(&self) -> Vec<QueryParam>
PARAMS.Source§fn return_fields(&self) -> Vec<String>
fn return_fields(&self) -> Vec<String>
Source§fn limit(&self) -> Option<QueryLimit>
fn limit(&self) -> Option<QueryLimit>
Source§fn should_unpack_json(&self) -> bool
fn should_unpack_json(&self) -> bool
Source§fn geofilter(&self) -> Option<GeoFilter>
fn geofilter(&self) -> Option<GeoFilter>
FT.SEARCH GEOFILTER clause.Source§fn render(&self) -> QueryRender
fn render(&self) -> QueryRender
Source§fn no_content(&self) -> bool
fn no_content(&self) -> bool
NOCONTENT.Auto Trait Implementations§
impl Freeze for SQLQuery
impl RefUnwindSafe for SQLQuery
impl Send for SQLQuery
impl Sync for SQLQuery
impl Unpin for SQLQuery
impl UnsafeUnpin for SQLQuery
impl UnwindSafe for SQLQuery
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more