jkrasnay / sqlbuilder

SQL Builder Library for Java
Apache License 2.0
249 stars 73 forks source link

Missing OR in WHERE #17

Open Oifan opened 6 years ago

Oifan commented 6 years ago

Your library is small and effective, but it only allows logical AND in the WHERE clause. Imagine you need to build a more complex query with several ANDs and ORs -- see these examples: https://www.techonthenet.com/sql/and_or.php . I took a look at your SelectBuilder class and I see for WHERE clause there is only method and(String) -- how can anyone do more complex queries, like this one?:

SELECT * FROM suppliers
WHERE (state = 'California' AND supplier_id <> 900)
OR (supplier_id = 100);
s4ibot commented 6 years ago

OR is not missing!

Example: new SelectCreator().column("*").from("suppliers").where(Predicates.or(Predicates.and(Predicates.eq("state", "California"), Predicates.neq("supplier_id", 900)), Predicates.eq("supplier_id", 100)));