FaaPz / PDO

Just another PDO database library
MIT License
316 stars 103 forks source link

add parenthesis in query #168

Open kernel64 opened 2 years ago

kernel64 commented 2 years ago

Sametimes we need to write a query with parenthesis like this exemple :

WHERE ( categorie = 'informatique' AND stock < 20 )
OR ( categorie = 'fourniture' AND stock < 200 )

So with this merge we will be able to write it like this :

$subject1 = new Parenthesis(new Conditional('categorie', '=', 'informatique'), 'AND', new Conditional('stock', '<', 20));
$subject2 = new Parenthesis(new Conditional('categorie', '=', 'fourniture'), 'AND', new Conditional('stock', '<', 200));
$subject  = new Conditional($subject1, 'OR', $subject2);
kwhat commented 2 years ago

This should already be covered by the Grouping clause.

$subject  = new Grouping(
    'OR',
    new Grouping(
        'AND', 
        new Conditional('categorie', '=', 'informatique'), 
        new Conditional('stock', '<', 20)
    ),
    new Grouping(
        'AND', 
        new Conditional('categorie', '=', 'fourniture'), 
        new Conditional('stock', '<', 200)
    ),
);
kernel64 commented 2 years ago

You are right. Thank you @kwhat for the clarification.