Skip to content

jianshangquan/SQLQueryBuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLQueryBuilder

Is a simple SQL query builder in Java\

Note: Currently it support only MySQL query

HOW TO USE?

scenario 1
SQLBuilder.getMySQLBuilder().select("*").from("table").build()

// RESULT : 
//        SELECT * FROM `table`;
scenario 2
SQLBuilder.getMySQLBuilder().select("fields").from("table").build()

// RESULT : 
//        SELECT fields FROM `table`;
scenario 3
SQLBuilder.getMySQLBuilder().select("field1, field2")
        .from("table")
        .where().field("field1").isGraterThan("20")
        .nextPipe().build();

// RESULT : 
//        SELECT field1, field2 FROM `table`
//        WHERE field1 < 20;
scenario 4
SQLBuilder.getMySQLBuilder()
        .select(
                SQLFun.sum("field").as("sum").transpile()
        ).from("table1")
        .join("table2").leftOuterJoin()
        .on("file2").isEqualTo("table1.field").nextPipe()
        .where().field("field1").isEqualTo("value").nextPipe()
        .orderBy("table1.field").ascending().nextPipe()
        .build();

// RESULT: 
//        SELECT SUM(field) as 'sum' FROM `table1`
//        LEFT OUTER JOIN `table2` ON table2.file2 = table1.field
//        WHERE field1 = value
//        ORDER BY table1.field ASC;