Java DSL for SQL
JavaQ takes care of building the sql query for you, rescuing you from the pain of remembering syntax for different dialects. With Java's static typing, JavaQ reduces the chances of making structural mistakes in the query.
Repository
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
Dependency
<dependency>
<groupId>com.github.vivekmittal</groupId>
<artifactId>javaq</artifactId>
<version>v1.0.0</version>
</dependency>
import static com.javaq.JavaQ.select;
Select All
select().from("EMPLOYEE").sql()
Where Clause
select("ID", "NAME").from("EMPLOYEE").where("ID = 1").sql()
Operators (AND/OR/LIKE/IN)
- AND/OR
select("ID", "NAME").from("EMPLOYEE") .where("ID = 1").and("NAME = 'BATMAN'") .sql()
select("ID", "NAME").from("EMPLOYEE") .where("ID = 1").or("NAME = 'BATMAN'") .sql()
- IN
select("ID", "NAME").from("EMPLOYEE") .where("ID") .in(select("ID").from("AWARD_WINNERS")) .or("NAME = 'BATMAN'") .sql()
select("ID", "NAME").from("EMPLOYEE") .where("ID").in("1", "2") .sql()
- LIKE
select("ID", "NAME").from("EMPLOYEE") .where("NAME").like("%BATMAN%") .sql()
Joins
- INNER JOIN
select("ID", "NAME").from("EMPLOYEE") .join("ADDRESS").on("ADDRESS.ID = EMPLOYEE.ADDRESS_ID") .where("ID = 1").or("NAME = 'BATMAN'") .sql()
- LEFT JOIN
select("ID", "NAME").from("EMPLOYEE") .leftJoin("ADDRESS").on("ADDRESS.ID = EMPLOYEE.ADDRESS_ID") .where("ID = 1").or("NAME = 'BATMAN'") .sql()
Order By
select("ID", "NAME").from("EMPLOYEE") .orderBy("ID", Order.OrderType.ASC) .sql()
Group By
select("NAME", "COUNT(*)").from("EMPLOYEE") .groupBy("NAME") .orderBy("COUNT(*)", ASC) .sql()
Limit
select("NAME", "COUNT(*)").from("EMPLOYEE") .groupBy("NAME") .orderBy("COUNT(*)", ASC) .limit(10) .sql()
- Generate queries for different SQL Dialects
- Integrate with JDBC APIs
- Generate update queries
Interested in contributing to JavaQ ? Here are some ways you can do that
- Raise issues/bugs
- Update documentation
- Contribute in open issues/improvements/features
- Any new ideas
Feel free to raise pull requests :)
MIT