Skip to content

Commit

Permalink
v0.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jianshangquan committed Aug 9, 2022
1 parent 3bc02a6 commit eb64dbe
Show file tree
Hide file tree
Showing 45 changed files with 123 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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;

```
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>SQLBuilder</artifactId>
<groupId>com.bytete.com</groupId>
<artifactId>MySQLBuilder</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/Builder/ConditionBuilder.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/Builder/MySqlQueryBuilder.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/Builder/OrderBuilder.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/Builder/SQLBuilder.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/Builder/SQLJoinBuilder.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Builder/SQLString.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public SQLString as(String as){
return this;
}

public String compile(){
public String transpile(){
return toString();
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/Builder/SQLTableBuilder.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/Builder/SQLUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package Builder;

import com.jiantech.SearchQueryForSQL.Builder.SQLValidator;

public class SQLUtils {
public static String formatValue(String value){
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/Builder/SelectorBuilder.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Builder/interfaces/BuildPipeable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package Builder.interfaces;

import com.jiantech.SearchQueryForSQL.Builder.SQLBuilder;
import Builder.SQLBuilder;

public interface BuildPipeable {
public SQLBuilder nextPipe() throws Exception;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/Builder/interfaces/Joinable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Builder.interfaces;

import com.jiantech.SearchQueryForSQL.Builder.SQLBuilder;

import Builder.SQLBuilder;

public interface Joinable {
public SQLJoinOn innerJoin();
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Builder/interfaces/SQLConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package Builder.interfaces;

import com.jiantech.SearchQueryForSQL.Builder.interfaces.Buildable;

public interface SQLConfiguration {
public Buildable set(String query);
}
6 changes: 3 additions & 3 deletions src/main/java/Builder/interfaces/SQLJoinCondition.java
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/Builder/interfaces/SQLWhereConditions.java
Original file line number Diff line number Diff line change
@@ -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<T> {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Builder/interfaces/Verifiable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package Builder.interfaces;

import com.jiantech.SearchQueryForSQL.Builder.Model.VerificationErrorMsg;
import Builder.Model.VerificationErrorMsg;

public interface Verifiable {
public VerificationErrorMsg verify();
Expand Down
41 changes: 29 additions & 12 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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);
}
Expand Down
Binary file added target/classes/Builder/CombinedSyntax.class
Binary file not shown.
Binary file added target/classes/Builder/ConditionBuilder.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added target/classes/Builder/MySqlQueryBuilder.class
Binary file not shown.
Binary file added target/classes/Builder/OrderBuilder.class
Binary file not shown.
Binary file added target/classes/Builder/SQLBuilder.class
Binary file not shown.
Binary file added target/classes/Builder/SQLCompareType.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added target/classes/Builder/SQLFun.class
Binary file not shown.
Binary file added target/classes/Builder/SQLJoinBuilder.class
Binary file not shown.
Binary file added target/classes/Builder/SQLString.class
Binary file not shown.
Binary file added target/classes/Builder/SQLTableBuilder.class
Binary file not shown.
Binary file added target/classes/Builder/SQLUtils.class
Binary file not shown.
Binary file added target/classes/Builder/SQLValidator.class
Binary file not shown.
Binary file added target/classes/Builder/SelectorBuilder.class
Binary file not shown.
Binary file not shown.
Binary file added target/classes/Builder/interfaces/Buildable.class
Binary file not shown.
Binary file added target/classes/Builder/interfaces/Joinable.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added target/classes/Builder/interfaces/SQLJoinOn.class
Binary file not shown.
Binary file not shown.
Binary file added target/classes/Builder/interfaces/Verifiable.class
Binary file not shown.
Binary file added target/classes/Main.class
Binary file not shown.

0 comments on commit eb64dbe

Please sign in to comment.