rajat-g / SelectQueryBuilder

A Utility to generate Select Query

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SelectQueryBuilder

Codacy Badge Quality Gate Status Coverage

Examples

Some usage examples:

Example 1:

List<String> names = Arrays.asList("Larry", "Curly", "Moe");
SelectBuilder selectBuilder = new SelectBuilder()
                                    .column("*")
                                    .from("Emp")
                                    .where(Predicates.in("name", names));

The output is:

SELECT * FROM Emp WHERE name in (?, ?, ?)

Example 2:

SelectBuilder sb = new SelectBuilder("suppliers");
Predicate condition1 = Predicates.and(Predicates.eq("state", "California"),
                                      Predicates.neq("supplier_id", 900));
Predicate condition2 = Predicates.eq("supplier_id", 100);
sb.where(condition1).orWhere(condition2);

The output is:

SELECT * FROM suppliers WHERE (state = ? AND supplier_id <> ?) OR supplier_id = ?

Example 3:

SelectBuilder sb = new SelectBuilder().column("Customers.CustomerName", "Orders.OrderID")
                .from("Customers").fullOuterJoin("Orders ON Customers.CustomerID=Orders.CustomerID");

The output is:

SELECT Customers.CustomerName, Orders.OrderID FROM Customers FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID

About

A Utility to generate Select Query


Languages

Language:Java 100.0%