Skip to content

Commit

Permalink
Merge pull request #28 from darkredz/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
darkredz authored May 7, 2020
2 parents 89b078c + c1f490c commit 1057e3a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ Add this to your maven pom.xml
<dependency>
<groupId>io.zeko</groupId>
<artifactId>zeko-sql-builder</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>
</dependency>

<!-- Jasync Mysql driver if needed -->
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.zeko</groupId>
<artifactId>zeko-sql-builder</artifactId>
<version>1.1.7-SNAPSHOT</version>
<version>1.1.8-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
102 changes: 76 additions & 26 deletions src/main/kotlin/io/zeko/db/sql/dsl/declarations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ infix fun String.eq(value: Double): QueryBlock {
return io.zeko.db.sql.operators.eq(this, value)
}

infix fun String.eq(value: Any): QueryBlock {
return io.zeko.db.sql.operators.eq(this, value)
}

infix fun String.neq(value: String): QueryBlock {
return io.zeko.db.sql.operators.neq(this, value)
}
Expand All @@ -35,6 +39,10 @@ infix fun String.neq(value: Double): QueryBlock {
return io.zeko.db.sql.operators.neq(this, value)
}

infix fun String.neq(value: Any): QueryBlock {
return io.zeko.db.sql.operators.neq(this, value)
}

infix fun String.greater(value: String): QueryBlock {
return io.zeko.db.sql.operators.greater(this, value)
}
Expand Down Expand Up @@ -99,102 +107,141 @@ infix fun String.lessEq(value: Double): QueryBlock {
return io.zeko.db.sql.operators.lessEq(this, value)
}

infix fun io.zeko.db.sql.QueryBlock.eq(value: String): QueryBlock {
infix fun String.greater(value: Any): QueryBlock {
return io.zeko.db.sql.operators.greater(this, value)
}

infix fun String.greaterEq(value: Any): QueryBlock {
return io.zeko.db.sql.operators.greaterEq(this, value)
}

infix fun String.less(value: Any): QueryBlock {
return io.zeko.db.sql.operators.less(this, value)
}

infix fun String.lessEq(value: Any): QueryBlock {
return io.zeko.db.sql.operators.lessEq(this, value)
}

infix fun QueryBlock.eq(value: String): QueryBlock {
return io.zeko.db.sql.operators.eq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.eq(value: Int): QueryBlock {
infix fun QueryBlock.eq(value: Int): QueryBlock {
return io.zeko.db.sql.operators.eq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.eq(value: Long): QueryBlock {
infix fun QueryBlock.eq(value: Long): QueryBlock {
return io.zeko.db.sql.operators.eq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.eq(value: Double): QueryBlock {
infix fun QueryBlock.eq(value: Double): QueryBlock {
return io.zeko.db.sql.operators.eq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.neq(value: String): QueryBlock {
infix fun QueryBlock.eq(value: Any): QueryBlock {
return io.zeko.db.sql.operators.eq(this.toString(), value)
}

infix fun QueryBlock.neq(value: String): QueryBlock {
return io.zeko.db.sql.operators.neq(this.toString(), value)
}

infix fun QueryBlock.neq(value: Int): QueryBlock {
return io.zeko.db.sql.operators.neq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.neq(value: Int): QueryBlock {
infix fun QueryBlock.neq(value: Long): QueryBlock {
return io.zeko.db.sql.operators.neq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.neq(value: Long): QueryBlock {
infix fun QueryBlock.neq(value: Double): QueryBlock {
return io.zeko.db.sql.operators.neq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.neq(value: Double): QueryBlock {
infix fun QueryBlock.neq(value: Any): QueryBlock {
return io.zeko.db.sql.operators.neq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.greater(value: String): QueryBlock {
infix fun QueryBlock.greater(value: String): QueryBlock {
return io.zeko.db.sql.operators.greater(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.greaterEq(value: String): QueryBlock {
infix fun QueryBlock.greaterEq(value: String): QueryBlock {
return io.zeko.db.sql.operators.greaterEq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.less(value: String): QueryBlock {
infix fun QueryBlock.less(value: String): QueryBlock {
return io.zeko.db.sql.operators.less(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.lessEq(value: String): QueryBlock {
infix fun QueryBlock.lessEq(value: String): QueryBlock {
return io.zeko.db.sql.operators.lessEq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.greater(value: Int): QueryBlock {
infix fun QueryBlock.greater(value: Int): QueryBlock {
return io.zeko.db.sql.operators.greater(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.greaterEq(value: Int): QueryBlock {
infix fun QueryBlock.greaterEq(value: Int): QueryBlock {
return io.zeko.db.sql.operators.greaterEq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.less(value: Int): QueryBlock {
infix fun QueryBlock.less(value: Int): QueryBlock {
return io.zeko.db.sql.operators.less(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.lessEq(value: Int): QueryBlock {
infix fun QueryBlock.lessEq(value: Int): QueryBlock {
return io.zeko.db.sql.operators.lessEq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.greater(value: Long): QueryBlock {
infix fun QueryBlock.greater(value: Long): QueryBlock {
return io.zeko.db.sql.operators.greater(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.greaterEq(value: Long): QueryBlock {
infix fun QueryBlock.greaterEq(value: Long): QueryBlock {
return io.zeko.db.sql.operators.greaterEq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.less(value: Long): QueryBlock {
infix fun QueryBlock.less(value: Long): QueryBlock {
return io.zeko.db.sql.operators.less(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.lessEq(value: Long): QueryBlock {
infix fun QueryBlock.lessEq(value: Long): QueryBlock {
return io.zeko.db.sql.operators.lessEq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.greater(value: Double): QueryBlock {
infix fun QueryBlock.greater(value: Double): QueryBlock {
return io.zeko.db.sql.operators.greater(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.greaterEq(value: Double): QueryBlock {
infix fun QueryBlock.greaterEq(value: Double): QueryBlock {
return io.zeko.db.sql.operators.greaterEq(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.less(value: Double): QueryBlock {
infix fun QueryBlock.less(value: Double): QueryBlock {
return io.zeko.db.sql.operators.less(this.toString(), value)
}

infix fun io.zeko.db.sql.QueryBlock.lessEq(value: Double): QueryBlock {
infix fun QueryBlock.lessEq(value: Double): QueryBlock {
return io.zeko.db.sql.operators.lessEq(this.toString(), value)
}

infix fun QueryBlock.greater(value: Any): QueryBlock {
return io.zeko.db.sql.operators.greater(this.toString(), value)
}

infix fun QueryBlock.greaterEq(value: Any): QueryBlock {
return io.zeko.db.sql.operators.greaterEq(this.toString(), value)
}

infix fun QueryBlock.less(value: Any): QueryBlock {
return io.zeko.db.sql.operators.less(this.toString(), value)
}

infix fun QueryBlock.lessEq(value: Any): QueryBlock {
return io.zeko.db.sql.operators.lessEq(this.toString(), value)
}

infix fun String.like(value: String): QueryBlock {
return io.zeko.db.sql.operators.like(this, value)
Expand Down Expand Up @@ -224,14 +271,14 @@ infix fun String.isNotNull(value: Boolean): QueryBlock {
if (value) {
return io.zeko.db.sql.operators.isNotNull(this)
}
return io.zeko.db.sql.QueryBlock("", "")
return QueryBlock("", "")
}

infix fun String.isNull(value: Boolean): QueryBlock {
if (value) {
return io.zeko.db.sql.operators.isNull(this)
}
return io.zeko.db.sql.QueryBlock("", "")
return QueryBlock("", "")
}

infix fun String.inList(values: String): QueryBlock {
Expand Down Expand Up @@ -288,6 +335,9 @@ infix fun String.between(values: Pair<*, *>): QueryBlock {
} else if (value1 is Double) {
val value2 = values.second as Double
return io.zeko.db.sql.operators.between(this, value1, value2)
} else {
val value2 = values.second
return io.zeko.db.sql.operators.between(this, value1.toString(), value2.toString())
}
return QueryBlock("", "")
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/io/zeko/db/sql/operators/declarations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ fun neq(field: String, value: Long): QueryBlock {
return QueryBlock(field, "!=", value.toString())
}

fun eq(field: String, value: Any): QueryBlock {
return QueryBlock(field, "=", "?")
}

fun neq(field: String, value: Any): QueryBlock {
return QueryBlock(field, "!=", "?")
}

fun greater(field: String, field2: String): QueryBlock {
return QueryBlock(field, ">", field2)
}
Expand Down Expand Up @@ -87,6 +95,19 @@ fun lessEq(field: String, value: Double): QueryBlock {
return QueryBlock(field, "<=", value.toString())
}

fun greater(field: String, value: Any): QueryBlock {
return QueryBlock(field, ">", "?")
}
fun greaterEq(field: String, value: Any): QueryBlock {
return QueryBlock(field, ">=", "?")
}
fun less(field: String, value: Any): QueryBlock {
return QueryBlock(field, "<", "?")
}
fun lessEq(field: String, value: Any): QueryBlock {
return QueryBlock(field, "<=", "?")
}

fun like(field: String, value: String, useRawValue: Boolean = false): QueryBlock {
return QueryBlock(field, "LIKE", if (useRawValue) "'${value.replace("'", "''")}'" else "?")
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/io/zeko/model/Entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,17 @@ abstract class Entity {
if (dateStr.indexOf("T") > 0) {
pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
} else {
pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SXXX")
// Apache ignite returns "2020-05-06 17:15:03.322Z" for timestamp columns
if (dateStr.length > 21 && dateStr[19] + "" == "." && dateStr[21] + "" != "Z") {
pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSXXX")
} else {
pattern = if (dateStr.indexOf(".") > 0)
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SXXX")
else
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssXXX")
}
}
ZonedDateTime.parse(dateStr + "Z", pattern)
ZonedDateTime.parse(dateStr.removeSuffix("Z") + "Z", pattern)
} else {
//Vertx JDBC client returns date time field as String and already converted to UTC
val pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX")
Expand Down

0 comments on commit 1057e3a

Please sign in to comment.