pub struct Condition {
pub sql: String,
pub values: Vec<Box<dyn AnyValue>>,
}
Expand description
Represents a SQL condition fragment with its associated bound values.
A Condition
is essentially a piece of SQL (e.g. "id = $1"
)
along with one or more values that should be bound into the query.
It is designed to be used with sqlx::QueryBuilder
for dynamic
query construction.
Fields§
§sql: String
The raw SQL fragment (e.g. "id = $1"
, "name IN (...)"
).
values: Vec<Box<dyn AnyValue>>
The values to be bound into the SQL fragment.
Each value is stored as a boxed AnyValue
trait object,
which allows heterogeneous types to be stored in the same vector.
Implementations§
Source§impl Condition
impl Condition
Sourcepub fn multi<T: BindValue + Clone + 'static>(sql: String, vals: Vec<T>) -> Self
pub fn multi<T: BindValue + Clone + 'static>(sql: String, vals: Vec<T>) -> Self
Create a new Condition
with multiple bound values.
Useful for IN
clauses or other multi-value conditions.
§Example
ⓘ
use sqlorm_core::qb::condition::Condition;
use sqlorm_core::qb::BindValue;
let cond = Condition::multi("id IN (?, ?, ?)".to_string(), vec![1, 2, 3]);
assert_eq!(cond.sql, "id IN (?, ?, ?)");
assert_eq!(cond.values.len(), 3);
Sourcepub fn none(sql: String) -> Self
pub fn none(sql: String) -> Self
Create a new Condition
with no bound values.
Useful for static SQL fragments that don’t require parameters.
§Example
use sqlorm_core::qb::condition::Condition;
let cond = Condition::none("deleted_at IS NULL".to_string());
assert_eq!(cond.sql, "deleted_at IS NULL");
assert!(cond.values.is_empty());
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Condition
impl !RefUnwindSafe for Condition
impl Send for Condition
impl Sync for Condition
impl Unpin for Condition
impl !UnwindSafe for Condition
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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