diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 9870979..4ae5e70 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -6,7 +6,7 @@ - + diff --git a/README.md b/README.md index 634d0d7..e152db5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,57 @@ # SQLQueryBuilder -Is a simple SQL query builder in Java +Is a simple SQL query builder in Java\ +Currently it support only MySQL query + + +### HOW TO USE? + +##### scenario 1 +```java +SQLBuilder.getMySQLBuilder().select("fields").from("table").build() + +// RESULT : +// SELECT fields FROM `table`; +``` + +##### scenario 2 +```java +SQLBuilder.getMySQLBuilder().select("fields").from("table").build() + +// RESULT : +// SELECT fields FROM `table`; +``` + +##### scenario 3 +```java +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 +```java + +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; + +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index f4d5779..8fb5268 100644 --- a/pom.xml +++ b/pom.xml @@ -4,8 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.example - SQLBuilder + com.bytete.com + MySQLBuilder 1.0-SNAPSHOT diff --git a/src/main/java/Builder/ConditionBuilder.java b/src/main/java/Builder/ConditionBuilder.java index bb3613a..458118f 100644 --- a/src/main/java/Builder/ConditionBuilder.java +++ b/src/main/java/Builder/ConditionBuilder.java @@ -1,9 +1,9 @@ package Builder; -import com.jiantech.SearchQueryForSQL.Builder.Model.VerificationErrorMsg; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.BuildPipeable; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.SQLWhereConditions; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Verifiable; +import Builder.Model.VerificationErrorMsg; +import Builder.interfaces.BuildPipeable; +import Builder.interfaces.SQLWhereConditions; +import Builder.interfaces.Verifiable; public class ConditionBuilder implements BuildPipeable, SQLWhereConditions, Verifiable { SQLBuilder builder; diff --git a/src/main/java/Builder/MySqlQueryBuilder.java b/src/main/java/Builder/MySqlQueryBuilder.java index b1fd91a..41ef5a7 100644 --- a/src/main/java/Builder/MySqlQueryBuilder.java +++ b/src/main/java/Builder/MySqlQueryBuilder.java @@ -1,10 +1,10 @@ package Builder; -import com.jiantech.SearchQueryForSQL.Builder.Model.VerificationErrorMsg; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Buildable; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Joinable; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.SQLConfiguration; +import Builder.Model.VerificationErrorMsg; +import Builder.interfaces.Buildable; +import Builder.interfaces.Joinable; +import Builder.interfaces.SQLConfiguration; public class MySqlQueryBuilder extends SQLBuilder implements Buildable, SQLConfiguration { diff --git a/src/main/java/Builder/OrderBuilder.java b/src/main/java/Builder/OrderBuilder.java index df5e930..150c5ce 100644 --- a/src/main/java/Builder/OrderBuilder.java +++ b/src/main/java/Builder/OrderBuilder.java @@ -1,8 +1,8 @@ package Builder; -import com.jiantech.SearchQueryForSQL.Builder.Model.VerificationErrorMsg; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.BuildPipeable; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Verifiable; +import Builder.Model.VerificationErrorMsg; +import Builder.interfaces.BuildPipeable; +import Builder.interfaces.Verifiable; public class OrderBuilder implements BuildPipeable, Verifiable { SQLBuilder sqlBuilder; diff --git a/src/main/java/Builder/SQLBuilder.java b/src/main/java/Builder/SQLBuilder.java index acf6057..1fc991c 100644 --- a/src/main/java/Builder/SQLBuilder.java +++ b/src/main/java/Builder/SQLBuilder.java @@ -1,8 +1,9 @@ package Builder; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Buildable; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Joinable; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Verifiable; + +import Builder.interfaces.Buildable; +import Builder.interfaces.Joinable; +import Builder.interfaces.Verifiable; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/Builder/SQLJoinBuilder.java b/src/main/java/Builder/SQLJoinBuilder.java index 8790daa..f26443a 100644 --- a/src/main/java/Builder/SQLJoinBuilder.java +++ b/src/main/java/Builder/SQLJoinBuilder.java @@ -1,7 +1,8 @@ package Builder; -import com.jiantech.SearchQueryForSQL.Builder.Model.VerificationErrorMsg; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.*; + +import Builder.Model.VerificationErrorMsg; +import Builder.interfaces.*; public class SQLJoinBuilder implements BuildPipeable, SQLJoinCondition, Joinable, SQLJoinOn, Verifiable { SQLBuilder builder; diff --git a/src/main/java/Builder/SQLString.java b/src/main/java/Builder/SQLString.java index a00a261..c1dddc6 100644 --- a/src/main/java/Builder/SQLString.java +++ b/src/main/java/Builder/SQLString.java @@ -11,7 +11,7 @@ public SQLString as(String as){ return this; } - public String compile(){ + public String transpile(){ return toString(); } diff --git a/src/main/java/Builder/SQLTableBuilder.java b/src/main/java/Builder/SQLTableBuilder.java index 55146ed..b033287 100644 --- a/src/main/java/Builder/SQLTableBuilder.java +++ b/src/main/java/Builder/SQLTableBuilder.java @@ -1,8 +1,9 @@ package Builder; -import com.jiantech.SearchQueryForSQL.Builder.Model.VerificationErrorMsg; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.BuildPipeable; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Verifiable; + +import Builder.Model.VerificationErrorMsg; +import Builder.interfaces.BuildPipeable; +import Builder.interfaces.Verifiable; public class SQLTableBuilder implements Verifiable, BuildPipeable { SQLBuilder builder; diff --git a/src/main/java/Builder/SQLUtils.java b/src/main/java/Builder/SQLUtils.java index cf8955d..78c5f05 100644 --- a/src/main/java/Builder/SQLUtils.java +++ b/src/main/java/Builder/SQLUtils.java @@ -1,6 +1,5 @@ package Builder; -import com.jiantech.SearchQueryForSQL.Builder.SQLValidator; public class SQLUtils { public static String formatValue(String value){ diff --git a/src/main/java/Builder/SelectorBuilder.java b/src/main/java/Builder/SelectorBuilder.java index f07be01..0581c69 100644 --- a/src/main/java/Builder/SelectorBuilder.java +++ b/src/main/java/Builder/SelectorBuilder.java @@ -1,7 +1,8 @@ package Builder; -import com.jiantech.SearchQueryForSQL.Builder.Model.VerificationErrorMsg; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Verifiable; + +import Builder.Model.VerificationErrorMsg; +import Builder.interfaces.Verifiable; public class SelectorBuilder implements Verifiable { SQLBuilder builder; diff --git a/src/main/java/Builder/interfaces/BuildPipeable.java b/src/main/java/Builder/interfaces/BuildPipeable.java index d3b9b2d..d9109aa 100644 --- a/src/main/java/Builder/interfaces/BuildPipeable.java +++ b/src/main/java/Builder/interfaces/BuildPipeable.java @@ -1,6 +1,6 @@ package Builder.interfaces; -import com.jiantech.SearchQueryForSQL.Builder.SQLBuilder; +import Builder.SQLBuilder; public interface BuildPipeable { public SQLBuilder nextPipe() throws Exception; diff --git a/src/main/java/Builder/interfaces/Joinable.java b/src/main/java/Builder/interfaces/Joinable.java index 067a028..edcb92c 100644 --- a/src/main/java/Builder/interfaces/Joinable.java +++ b/src/main/java/Builder/interfaces/Joinable.java @@ -1,6 +1,7 @@ package Builder.interfaces; -import com.jiantech.SearchQueryForSQL.Builder.SQLBuilder; + +import Builder.SQLBuilder; public interface Joinable { public SQLJoinOn innerJoin(); diff --git a/src/main/java/Builder/interfaces/SQLConfiguration.java b/src/main/java/Builder/interfaces/SQLConfiguration.java index d099825..89da0c7 100644 --- a/src/main/java/Builder/interfaces/SQLConfiguration.java +++ b/src/main/java/Builder/interfaces/SQLConfiguration.java @@ -1,7 +1,5 @@ package Builder.interfaces; -import com.jiantech.SearchQueryForSQL.Builder.interfaces.Buildable; - public interface SQLConfiguration { public Buildable set(String query); } diff --git a/src/main/java/Builder/interfaces/SQLJoinCondition.java b/src/main/java/Builder/interfaces/SQLJoinCondition.java index 0c55914..2a2c8cc 100644 --- a/src/main/java/Builder/interfaces/SQLJoinCondition.java +++ b/src/main/java/Builder/interfaces/SQLJoinCondition.java @@ -1,8 +1,8 @@ package Builder.interfaces; -import com.jiantech.SearchQueryForSQL.Builder.SQLBuilder; -import com.jiantech.SearchQueryForSQL.Builder.SQLCompareType; -import com.jiantech.SearchQueryForSQL.Builder.SQLJoinBuilder; +import Builder.SQLBuilder; +import Builder.SQLCompareType; +import Builder.SQLJoinBuilder; public interface SQLJoinCondition { public SQLJoinBuilder isEqualTo(String value); diff --git a/src/main/java/Builder/interfaces/SQLWhereConditions.java b/src/main/java/Builder/interfaces/SQLWhereConditions.java index f34aed3..2a50ea4 100644 --- a/src/main/java/Builder/interfaces/SQLWhereConditions.java +++ b/src/main/java/Builder/interfaces/SQLWhereConditions.java @@ -1,10 +1,9 @@ package Builder.interfaces; -import com.jiantech.SearchQueryForSQL.Builder.ConditionBuilder; -import com.jiantech.SearchQueryForSQL.Builder.SQLBuilder; -import com.jiantech.SearchQueryForSQL.Builder.SQLCompareType; -import java.util.concurrent.locks.Condition; +import Builder.ConditionBuilder; +import Builder.SQLBuilder; +import Builder.SQLCompareType; public interface SQLWhereConditions { diff --git a/src/main/java/Builder/interfaces/Verifiable.java b/src/main/java/Builder/interfaces/Verifiable.java index e0f3724..0d7ae8d 100644 --- a/src/main/java/Builder/interfaces/Verifiable.java +++ b/src/main/java/Builder/interfaces/Verifiable.java @@ -1,6 +1,6 @@ package Builder.interfaces; -import com.jiantech.SearchQueryForSQL.Builder.Model.VerificationErrorMsg; +import Builder.Model.VerificationErrorMsg; public interface Verifiable { public VerificationErrorMsg verify(); diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 6d66b7b..8c69111 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,6 +1,6 @@ -import com.jiantech.SearchQueryForSQL.Builder.SQLBuilder; -import com.jiantech.SearchQueryForSQL.Builder.SQLCompareType; -import com.jiantech.SearchQueryForSQL.Builder.SQLFun; +import Builder.SQLBuilder; +import Builder.SQLCompareType; +import Builder.SQLFun; public class Main { @@ -40,15 +40,32 @@ public static void main(String[] args) throws Exception { // .setDefaultEncoding("fdsafd") // .nextPipe().build(); - sqlQuery = SQLBuilder.getMySQLBuilder() - .select( - SQLFun.sum("pawn_amount").as("sum").compile() - ).from("goldpawndata") - .join("goldchangedata").leftOuterJoin() - .on("voucher_id").isEqualTo("goldpawndata.voucher_id").nextPipe() - .where().field("item_name").isEqualTo("စောက်သံကွင်းကြိုး(၁)", SQLCompareType.STRING).and() - .field("goldchangedata.is_delete").isFalse().nextPipe() - .orderBy("item_name").ascending().nextPipe().build(); +// sqlQuery = SQLBuilder.getMySQLBuilder() +// .select( +// SQLFun.sum("pawn_amount").as("sum").transpile() +// ).from("goldpawndata") +// .join("goldchangedata").leftOuterJoin() +// .on("voucher_id").isEqualTo("goldpawndata.voucher_id").nextPipe() +// .where().field("item_name").isEqualTo("စောက်သံကွင်းကြိုး(၁)", SQLCompareType.STRING).and() +// .field("goldchangedata.is_delete").isFalse().nextPipe() +// .orderBy("item_name").ascending().nextPipe().build(); + + + sqlQuery = SQLBuilder.getMySQLBuilder().select("fields").from("table").build(); +// sqlQuery = SQLBuilder.getMySQLBuilder().select("field1, field2") +// .from("table") +// .where().field("field1").isGraterThan("20") +// .nextPipe().build(); + +// sqlQuery = 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(); System.out.println(sqlQuery); } diff --git a/target/classes/Builder/CombinedSyntax.class b/target/classes/Builder/CombinedSyntax.class new file mode 100644 index 0000000..5e17b67 Binary files /dev/null and b/target/classes/Builder/CombinedSyntax.class differ diff --git a/target/classes/Builder/ConditionBuilder.class b/target/classes/Builder/ConditionBuilder.class new file mode 100644 index 0000000..611a966 Binary files /dev/null and b/target/classes/Builder/ConditionBuilder.class differ diff --git a/target/classes/Builder/Model/SQLFunctionModel.class b/target/classes/Builder/Model/SQLFunctionModel.class new file mode 100644 index 0000000..688d835 Binary files /dev/null and b/target/classes/Builder/Model/SQLFunctionModel.class differ diff --git a/target/classes/Builder/Model/VerificationErrorMsg.class b/target/classes/Builder/Model/VerificationErrorMsg.class new file mode 100644 index 0000000..db9a103 Binary files /dev/null and b/target/classes/Builder/Model/VerificationErrorMsg.class differ diff --git a/target/classes/Builder/MySqlQueryBuilder.class b/target/classes/Builder/MySqlQueryBuilder.class new file mode 100644 index 0000000..7a97b06 Binary files /dev/null and b/target/classes/Builder/MySqlQueryBuilder.class differ diff --git a/target/classes/Builder/OrderBuilder.class b/target/classes/Builder/OrderBuilder.class new file mode 100644 index 0000000..c008282 Binary files /dev/null and b/target/classes/Builder/OrderBuilder.class differ diff --git a/target/classes/Builder/SQLBuilder.class b/target/classes/Builder/SQLBuilder.class new file mode 100644 index 0000000..69b90d2 Binary files /dev/null and b/target/classes/Builder/SQLBuilder.class differ diff --git a/target/classes/Builder/SQLCompareType.class b/target/classes/Builder/SQLCompareType.class new file mode 100644 index 0000000..687e2ff Binary files /dev/null and b/target/classes/Builder/SQLCompareType.class differ diff --git a/target/classes/Builder/SQLConditionClauseBuilder$1.class b/target/classes/Builder/SQLConditionClauseBuilder$1.class new file mode 100644 index 0000000..d95fbb4 Binary files /dev/null and b/target/classes/Builder/SQLConditionClauseBuilder$1.class differ diff --git a/target/classes/Builder/SQLConditionClauseBuilder.class b/target/classes/Builder/SQLConditionClauseBuilder.class new file mode 100644 index 0000000..c7d3382 Binary files /dev/null and b/target/classes/Builder/SQLConditionClauseBuilder.class differ diff --git a/target/classes/Builder/SQLFun.class b/target/classes/Builder/SQLFun.class new file mode 100644 index 0000000..f28b72c Binary files /dev/null and b/target/classes/Builder/SQLFun.class differ diff --git a/target/classes/Builder/SQLJoinBuilder.class b/target/classes/Builder/SQLJoinBuilder.class new file mode 100644 index 0000000..391195b Binary files /dev/null and b/target/classes/Builder/SQLJoinBuilder.class differ diff --git a/target/classes/Builder/SQLString.class b/target/classes/Builder/SQLString.class new file mode 100644 index 0000000..4a2c37f Binary files /dev/null and b/target/classes/Builder/SQLString.class differ diff --git a/target/classes/Builder/SQLTableBuilder.class b/target/classes/Builder/SQLTableBuilder.class new file mode 100644 index 0000000..62f5ed8 Binary files /dev/null and b/target/classes/Builder/SQLTableBuilder.class differ diff --git a/target/classes/Builder/SQLUtils.class b/target/classes/Builder/SQLUtils.class new file mode 100644 index 0000000..b4628bc Binary files /dev/null and b/target/classes/Builder/SQLUtils.class differ diff --git a/target/classes/Builder/SQLValidator.class b/target/classes/Builder/SQLValidator.class new file mode 100644 index 0000000..6fcd613 Binary files /dev/null and b/target/classes/Builder/SQLValidator.class differ diff --git a/target/classes/Builder/SelectorBuilder.class b/target/classes/Builder/SelectorBuilder.class new file mode 100644 index 0000000..6ff4d65 Binary files /dev/null and b/target/classes/Builder/SelectorBuilder.class differ diff --git a/target/classes/Builder/interfaces/BuildPipeable.class b/target/classes/Builder/interfaces/BuildPipeable.class new file mode 100644 index 0000000..88c7efb Binary files /dev/null and b/target/classes/Builder/interfaces/BuildPipeable.class differ diff --git a/target/classes/Builder/interfaces/Buildable.class b/target/classes/Builder/interfaces/Buildable.class new file mode 100644 index 0000000..a549af4 Binary files /dev/null and b/target/classes/Builder/interfaces/Buildable.class differ diff --git a/target/classes/Builder/interfaces/Joinable.class b/target/classes/Builder/interfaces/Joinable.class new file mode 100644 index 0000000..33fd934 Binary files /dev/null and b/target/classes/Builder/interfaces/Joinable.class differ diff --git a/target/classes/Builder/interfaces/SQLConfiguration.class b/target/classes/Builder/interfaces/SQLConfiguration.class new file mode 100644 index 0000000..d71b960 Binary files /dev/null and b/target/classes/Builder/interfaces/SQLConfiguration.class differ diff --git a/target/classes/Builder/interfaces/SQLJoinCondition.class b/target/classes/Builder/interfaces/SQLJoinCondition.class new file mode 100644 index 0000000..9413a05 Binary files /dev/null and b/target/classes/Builder/interfaces/SQLJoinCondition.class differ diff --git a/target/classes/Builder/interfaces/SQLJoinOn.class b/target/classes/Builder/interfaces/SQLJoinOn.class new file mode 100644 index 0000000..89016c0 Binary files /dev/null and b/target/classes/Builder/interfaces/SQLJoinOn.class differ diff --git a/target/classes/Builder/interfaces/SQLWhereConditions.class b/target/classes/Builder/interfaces/SQLWhereConditions.class new file mode 100644 index 0000000..6160fdb Binary files /dev/null and b/target/classes/Builder/interfaces/SQLWhereConditions.class differ diff --git a/target/classes/Builder/interfaces/Verifiable.class b/target/classes/Builder/interfaces/Verifiable.class new file mode 100644 index 0000000..ee1dde3 Binary files /dev/null and b/target/classes/Builder/interfaces/Verifiable.class differ diff --git a/target/classes/Main.class b/target/classes/Main.class new file mode 100644 index 0000000..6c994fb Binary files /dev/null and b/target/classes/Main.class differ