feat(expr): add range comparison ops

This commit is contained in:
2025-08-11 14:23:27 +02:00
parent 5f8dbdc764
commit d608b808af
2 changed files with 45 additions and 5 deletions

View File

@@ -260,7 +260,7 @@ where
#[allow(clippy::print_stdout)]
mod test {
use super::PushToBuilder;
use super::expr::{Equals, NotEquals};
use super::expr::{Equals, Geq, Leq};
use sqlx::{Any, QueryBuilder};
use sqlx_utils_macros::WhereClause;
@@ -271,15 +271,18 @@ mod test {
struct WhereTest {
#[sqlxu(op = "Equals")]
name: String,
#[sqlxu(op = "NotEquals")]
id: i64,
#[sqlxu(rename = "id", op = "Geq")]
id_at_least: i64,
#[sqlxu(rename = "id", op = "Leq")]
id_at_most: i64,
}
let mut builder: QueryBuilder<'_, Any> = QueryBuilder::new("");
let s = WhereTest {
name: "Flip".to_string(),
id: 69,
id_at_least: 69,
id_at_most: 420,
};
s.push_to(&mut builder);

View File

@@ -116,6 +116,30 @@ impl SqlOperand for NotIn {
const EXPR: &str = " NOT IN ";
}
pub struct Gt;
impl SqlOperand for Gt {
const EXPR: &str = " > ";
}
pub struct Lt;
impl SqlOperand for Lt {
const EXPR: &str = " < ";
}
pub struct Geq;
impl SqlOperand for Geq {
const EXPR: &str = " >= ";
}
pub struct Leq;
impl SqlOperand for Leq {
const EXPR: &str = " <= ";
}
impl_push!(
And, Or, Comma, Equals, Is, NotEquals, IsNot, Like, NotLike, Ilike, NotIlike, In, NotIn
);
@@ -141,7 +165,8 @@ pub const fn ensure_where<T: WhereOp>(t: T) -> T {
mod sealed {
use crate::builder::expr::{
And, Comma, Equals, Ilike, In, Is, IsNot, Like, NotEquals, NotIlike, NotIn, NotLike, Or,
And, Comma, Equals, Geq, Gt, Ilike, In, Is, IsNot, Leq, Like, Lt, NotEquals, NotIlike,
NotIn, NotLike, Or,
};
pub trait Sealed {}
@@ -159,11 +184,15 @@ mod sealed {
impl Sealed for And {}
impl Sealed for Comma {}
impl Sealed for Equals {}
impl Sealed for Geq {}
impl Sealed for Gt {}
impl Sealed for Ilike {}
impl Sealed for In {}
impl Sealed for Is {}
impl Sealed for IsNot {}
impl Sealed for Leq {}
impl Sealed for Like {}
impl Sealed for Lt {}
impl Sealed for NotEquals {}
impl Sealed for NotIlike {}
impl Sealed for NotIn {}
@@ -173,11 +202,15 @@ mod sealed {
impl SealedBinary for And {}
impl SealedBinary for Comma {}
impl SealedBinary for Equals {}
impl SealedBinary for Geq {}
impl SealedBinary for Gt {}
impl SealedBinary for Ilike {}
impl SealedBinary for In {}
impl SealedBinary for Is {}
impl SealedBinary for IsNot {}
impl SealedBinary for Leq {}
impl SealedBinary for Like {}
impl SealedBinary for Lt {}
impl SealedBinary for NotEquals {}
impl SealedBinary for NotIlike {}
impl SealedBinary for NotIn {}
@@ -185,11 +218,15 @@ mod sealed {
impl SealedBinary for Or {}
impl SealedWhere for Equals {}
impl SealedWhere for Geq {}
impl SealedWhere for Gt {}
impl SealedWhere for Ilike {}
impl SealedWhere for In {}
impl SealedWhere for Is {}
impl SealedWhere for IsNot {}
impl SealedWhere for Leq {}
impl SealedWhere for Like {}
impl SealedWhere for Lt {}
impl SealedWhere for NotEquals {}
impl SealedWhere for NotIlike {}
impl SealedWhere for NotIn {}