Skip to content

Commit

Permalink
reafactor/104-core-remove-unnecessary-parentheses-to-group-conditions (
Browse files Browse the repository at this point in the history
…#105)

* Remove parenthesis for AND & OR criteria

* Update version.properties

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update README.md

---------

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
wax911 authored Sep 20, 2023
1 parent 0e4e806 commit 51b59d2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [ :biohazard: W.I.P :biohazard: ] support-query-builder &nbsp; [![Run unit tests](https://github.com/AniTrend/support-query-builder/actions/workflows/android-test.yml/badge.svg)](https://github.com/AniTrend/support-query-builder/actions/workflows/android-test.yml) &nbsp; [![Codacy Badge](https://app.codacy.com/project/badge/Grade/2bcc9217df74403a9d4afd8664b20c34)](https://www.codacy.com/gh/AniTrend/support-query-builder/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=AniTrend/support-query-builder&amp;utm_campaign=Badge_Grade) &nbsp; [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FAniTrend%2Fsupport-query-builder.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FAniTrend%2Fsupport-query-builder?ref=badge_shield) &nbsp; [![](https://jitpack.io/v/AniTrend/support-query-builder.svg)](https://jitpack.io/#AniTrend/support-query-builder)
# support-query-builder &nbsp; [![Run unit tests](https://github.com/AniTrend/support-query-builder/actions/workflows/android-test.yml/badge.svg)](https://github.com/AniTrend/support-query-builder/actions/workflows/android-test.yml) &nbsp; [![Codacy Badge](https://app.codacy.com/project/badge/Grade/2bcc9217df74403a9d4afd8664b20c34)](https://www.codacy.com/gh/AniTrend/support-query-builder/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=AniTrend/support-query-builder&amp;utm_campaign=Badge_Grade) &nbsp; [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FAniTrend%2Fsupport-query-builder.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FAniTrend%2Fsupport-query-builder?ref=badge_shield) &nbsp; [![](https://jitpack.io/v/AniTrend/support-query-builder.svg)](https://jitpack.io/#AniTrend/support-query-builder)

A simple yet comprehensive sql **select** query builder with featuring an annotation processor to generate schema objects from [Room](https://developer.android.com/reference/androidx/room/Room) annotations that plugs straight into [RawQuery](https://developer.android.com/reference/androidx/room/RawQuery)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sealed class Criteria : IQueryBuilder {
expression = "$expression${right.build()}"
}

return "(${expression.trim()})"
return expression.trim()
}

override fun buildParameters() =
Expand Down Expand Up @@ -123,7 +123,7 @@ sealed class Criteria : IQueryBuilder {
private val right: Criteria?,
) : Criteria() {
override fun build(): String {
val expression = "(${left?.build()} OR ${right?.build()})"
val expression = "${left?.build()} OR ${right?.build()}"
return expression.trim()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ import co.anitrend.support.query.builder.core.criteria.extensions.endsWith
import co.anitrend.support.query.builder.core.criteria.extensions.equal
import co.anitrend.support.query.builder.core.extensions.asFullSqlString
import co.anitrend.support.query.builder.core.from.From
import co.anitrend.support.query.builder.core.from.extentions.*
import co.anitrend.support.query.builder.core.from.extentions.`as`
import co.anitrend.support.query.builder.core.from.extentions.asTable
import co.anitrend.support.query.builder.core.from.extentions.innerJoin
import co.anitrend.support.query.builder.core.from.extentions.leftJoin
import co.anitrend.support.query.builder.core.projection.Projection
import co.anitrend.support.query.builder.core.projection.extensions.`as`
import co.anitrend.support.query.builder.dsl.*
import co.anitrend.support.query.builder.dsl.from
import co.anitrend.support.query.builder.dsl.groupBy
import co.anitrend.support.query.builder.dsl.innerJoin
import co.anitrend.support.query.builder.dsl.orderByDesc
import co.anitrend.support.query.builder.dsl.select
import co.anitrend.support.query.builder.dsl.where
import io.mockk.every
import io.mockk.mockk
import junit.framework.TestCase
Expand Down Expand Up @@ -117,7 +125,7 @@ class QueryBuilderTest : TestCase() {
}

fun `test select with inner join and where clause plus filter`() {
val expected = "SELECT * FROM table_name INNER JOIN other_table_name ON other_column_id = column_id WHERE (column_name = 'something' AND column_name LIKE '%pe')"
val expected = "SELECT * FROM table_name INNER JOIN other_table_name ON other_column_id = column_id WHERE column_name = 'something' AND column_name LIKE '%pe'"
builder from {
table.innerJoin("other_table_name").on(
"other_column_id", "column_id"
Expand All @@ -131,7 +139,7 @@ class QueryBuilderTest : TestCase() {
}

fun `test select with inner join, left join and where clause plus filter`() {
val expected = "SELECT * FROM table_name INNER JOIN other_table_name ON other_column_id = column_id LEFT JOIN some_table_name ON some_other_column_id = column_id WHERE (column_name = 'something' AND column_name LIKE '%pe')"
val expected = "SELECT * FROM table_name INNER JOIN other_table_name ON other_column_id = column_id LEFT JOIN some_table_name ON some_other_column_id = column_id WHERE column_name = 'something' AND column_name LIKE '%pe'"
builder from {
table.innerJoin("other_table_name").on(
"other_column_id", "column_id"
Expand All @@ -148,7 +156,7 @@ class QueryBuilderTest : TestCase() {
}

fun `test select with inner join, left join and where clause plus filter segmented`() {
val expected = "SELECT * FROM table_name INNER JOIN other_table_name ON other_column_id = column_id LEFT JOIN some_table_name ON some_other_column_id = column_id WHERE (column_name = 'something' AND column_name LIKE '%pe')"
val expected = "SELECT * FROM table_name INNER JOIN other_table_name ON other_column_id = column_id LEFT JOIN some_table_name ON some_other_column_id = column_id WHERE column_name = 'something' AND column_name LIKE '%pe'"
builder from table
builder from {
innerJoin("other_table_name") {
Expand All @@ -167,4 +175,4 @@ class QueryBuilderTest : TestCase() {

assertEquals(expected, actual)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
package co.anitrend.support.query.builder.core.criteria

import co.anitrend.support.query.builder.core.criteria.extensions.*
import co.anitrend.support.query.builder.core.criteria.extensions.and
import co.anitrend.support.query.builder.core.criteria.extensions.between
import co.anitrend.support.query.builder.core.criteria.extensions.exists
import co.anitrend.support.query.builder.core.criteria.extensions.greaterThan
import co.anitrend.support.query.builder.core.criteria.extensions.`in`
import co.anitrend.support.query.builder.core.criteria.extensions.isNull
import co.anitrend.support.query.builder.core.criteria.extensions.lesserThanOrEqual
import co.anitrend.support.query.builder.core.criteria.extensions.like
import co.anitrend.support.query.builder.core.criteria.extensions.match
import co.anitrend.support.query.builder.core.criteria.extensions.notExists
import co.anitrend.support.query.builder.core.criteria.extensions.notIsNull
import co.anitrend.support.query.builder.core.criteria.extensions.or
import co.anitrend.support.query.builder.core.projection.Projection
import io.mockk.every
import io.mockk.mockk
Expand All @@ -19,7 +30,7 @@ class CriteriaTest : TestCase() {
}

fun `test and criteria`() {
val expected = "(column_name IS NULL AND column_last IS NOT NULL)"
val expected = "column_name IS NULL AND column_last IS NOT NULL"
val criteria = columnName.isNull() and columnLast.notIsNull()
val actual = criteria.build()

Expand Down Expand Up @@ -67,7 +78,7 @@ class CriteriaTest : TestCase() {
}

fun `test or criteria`() {
val expected = "(column_name > ? OR column_last <= ?)"
val expected = "column_name > ? OR column_last <= ?"
val criteria = columnName greaterThan 6 or columnLast.lesserThanOrEqual(4)
val actual = criteria.build()

Expand All @@ -89,4 +100,4 @@ class CriteriaTest : TestCase() {

assertEquals(expected, actual)
}
}
}
5 changes: 3 additions & 2 deletions gradle/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
version=0.2.0
code=2000000
version=0.2.1
code=2001000
name=v0.2.1

0 comments on commit 51b59d2

Please sign in to comment.