Skip to content

Comments

Add a way to combine where with OR / AND. #158#163

Merged
lex148 merged 7 commits intoweldsorm:and_orfrom
polo-asm:or_and
Dec 13, 2025
Merged

Add a way to combine where with OR / AND. #158#163
lex148 merged 7 commits intoweldsorm:and_orfrom
polo-asm:or_and

Conversation

@polo-asm
Copy link
Contributor

Implementation for #158

Or / And condition can be written using 2 syntax :

User::where_col(|u| or( u.first_name.equal("John") , and( u.last_name.equal("Doe") , u.is_active.equal(true) ) ) )
User::where_col(|u| 
    u.first_name.equal("John")
    .or(  
        u.last_name.equal("Doe")
        .and(u.is_active.equal(true) ) 
    )
)

It's a proposal which can be enhanced. Maybe some documentation may be needed.

use super::Relation;
use super::{read_as_ident, read_as_path, read_as_string};
use crate::errors::Result;
use syn::{Expr, Ident, Token};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this using was not removed in my previous PR.

use std::marker::PhantomData;
use welds_connections::Param;

#[derive(Clone)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to implement Clone & Copy in Schema structure

pub struct Basic<T> {
col: String,
field: String,
col: &'static str,
Copy link
Contributor Author

@polo-asm polo-asm Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String prevent from implementing Copy. Because column and field are const it can be replaced by a static str


quote! {

#[derive(Copy,Clone)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in closure |a| a.id.equal(0).or( a.name.equal("yyyy") ) the compiler must be able to copy a to use it twice. So I implemented Copy & Clone on the schema structure. I was also obliged to implement Copy on all query/clause structures.

@lex148 lex148 changed the base branch from main to and_or December 13, 2025 17:14
@lex148 lex148 merged commit 7a267a1 into weldsorm:and_or Dec 13, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants