From a595b160dbc402200d906c67509404620e2206d4 Mon Sep 17 00:00:00 2001 From: Leandro Colmenarez <89696212+LeandroLCD@users.noreply.github.com> Date: Mon, 17 Nov 2025 20:37:42 -0300 Subject: [PATCH 1/4] feat(Query): Automatically use the first logical operation as the WHERE clause This commit introduces a convenience feature where the first logical operation (`AND` or `OR`) is automatically used as the `WHERE` clause if one is not explicitly set in the query builder. This simplifies query construction by removing the requirement to call `where()` first. The changes include: - Modifying the `build()` method in `QuerySelect.Builder` and `QueryDelete.Builder` to automatically identify and set the `WHERE` clause from the existing logical operations. - Updating `getSqlOperators()` in `QuerySelect`, `QueryDelete`, and `QueryUpdate` to correctly include the `where` operator in the returned list, improving query introspection. --- .../java/com/blipblipcode/query/QueryDelete.kt | 15 ++++++++++++--- .../java/com/blipblipcode/query/QuerySelect.kt | 14 +++++++++++--- .../java/com/blipblipcode/query/QueryUpdate.kt | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/query/src/main/java/com/blipblipcode/query/QueryDelete.kt b/query/src/main/java/com/blipblipcode/query/QueryDelete.kt index 75cb19c..9de5d0d 100644 --- a/query/src/main/java/com/blipblipcode/query/QueryDelete.kt +++ b/query/src/main/java/com/blipblipcode/query/QueryDelete.kt @@ -64,8 +64,9 @@ class QueryDelete private constructor( } override fun getSqlOperators(): List> { - return operations.values.map { - it.operator + return buildList { + add(where) + operations.values.forEach { add(it.operator) } } } @@ -203,7 +204,15 @@ class QueryDelete private constructor( * @throws IllegalArgumentException if the WHERE clause is not set. */ fun build(): QueryDelete { - require(where != null) { "A WHERE clause must be specified." } + if(where == null){ + val w = operations.firstNotNullOfOrNull{it}.let { + it ?: throw IllegalArgumentException("A WHERE clause must be specified.") + } + operations.remove(w.key) + + where = w.value.operator + } + return QueryDelete( where = where!!, table = table, operations = operations ) diff --git a/query/src/main/java/com/blipblipcode/query/QuerySelect.kt b/query/src/main/java/com/blipblipcode/query/QuerySelect.kt index 29423d6..3ef0e0d 100644 --- a/query/src/main/java/com/blipblipcode/query/QuerySelect.kt +++ b/query/src/main/java/com/blipblipcode/query/QuerySelect.kt @@ -88,8 +88,9 @@ class QuerySelect private constructor( } override fun getSqlOperators(): List> { - return operations.values.map { - it.operator + return buildList { + add(where) + operations.values.forEach { add(it.operator) } } } @@ -319,7 +320,14 @@ class QuerySelect private constructor( * @throws IllegalArgumentException if the WHERE clause is not set. */ fun build(): QuerySelect { - require(where != null) { "A WHERE clause must be specified." } + if(where == null){ + val w = operations.firstNotNullOfOrNull{it}.let { + it ?: throw IllegalArgumentException("WHERE clause is required for QuerySelect") + } + operations.remove(w.key) + + where = w.value.operator + } return QuerySelect( where = where!!, table = table, diff --git a/query/src/main/java/com/blipblipcode/query/QueryUpdate.kt b/query/src/main/java/com/blipblipcode/query/QueryUpdate.kt index a5b85d2..c43398d 100644 --- a/query/src/main/java/com/blipblipcode/query/QueryUpdate.kt +++ b/query/src/main/java/com/blipblipcode/query/QueryUpdate.kt @@ -75,7 +75,7 @@ class QueryUpdate private constructor( } override fun getSqlOperators(): List> { - return emptyList() + return listOf(where) } override fun getTableName(): String { From 20e71ace6078aba2bd7589f61b069f8b2e479aeb Mon Sep 17 00:00:00 2001 From: Leandro Colmenarez <89696212+LeandroLCD@users.noreply.github.com> Date: Mon, 17 Nov 2025 20:46:22 -0300 Subject: [PATCH 2/4] test(QueryDelete): Fix test for building without a WHERE clause This commit corrects a test case for `QueryDelete`. The test `build without where clause throws exception` was incorrectly including a WHERE condition, which prevented it from accurately verifying that building a `QueryDelete` without any conditions throws an `IllegalArgumentException`. The extraneous condition has been removed. --- query/src/test/java/com/blipblipcode/query/QueryDeleteTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/query/src/test/java/com/blipblipcode/query/QueryDeleteTest.kt b/query/src/test/java/com/blipblipcode/query/QueryDeleteTest.kt index d54a8d0..fb0d7bf 100644 --- a/query/src/test/java/com/blipblipcode/query/QueryDeleteTest.kt +++ b/query/src/test/java/com/blipblipcode/query/QueryDeleteTest.kt @@ -43,7 +43,6 @@ class QueryDeleteTest { @Test fun `build without where clause throws exception`() { val builder = QueryDelete.builder("users") - .and("status", SQLOperator.Equals("status", "active")) assertThrows(IllegalArgumentException::class.java) { builder.build() From 6edf9d84cb0ec2b75ba01582a345590a54821c53 Mon Sep 17 00:00:00 2001 From: Leandro Colmenarez <89696212+LeandroLCD@users.noreply.github.com> Date: Mon, 17 Nov 2025 20:59:50 -0300 Subject: [PATCH 3/4] Update query/src/main/java/com/blipblipcode/query/QueryDelete.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../main/java/com/blipblipcode/query/QueryDelete.kt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/query/src/main/java/com/blipblipcode/query/QueryDelete.kt b/query/src/main/java/com/blipblipcode/query/QueryDelete.kt index 9de5d0d..239cec6 100644 --- a/query/src/main/java/com/blipblipcode/query/QueryDelete.kt +++ b/query/src/main/java/com/blipblipcode/query/QueryDelete.kt @@ -204,15 +204,7 @@ class QueryDelete private constructor( * @throws IllegalArgumentException if the WHERE clause is not set. */ fun build(): QueryDelete { - if(where == null){ - val w = operations.firstNotNullOfOrNull{it}.let { - it ?: throw IllegalArgumentException("A WHERE clause must be specified.") - } - operations.remove(w.key) - - where = w.value.operator - } - + require(where != null) { "A WHERE clause must be specified." } return QueryDelete( where = where!!, table = table, operations = operations ) From cd823c11c5a3a9e56a7758718e8646f58ad8f7c9 Mon Sep 17 00:00:00 2001 From: Leandro Colmenarez <89696212+LeandroLCD@users.noreply.github.com> Date: Mon, 17 Nov 2025 21:00:07 -0300 Subject: [PATCH 4/4] Update query/src/main/java/com/blipblipcode/query/QuerySelect.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/main/java/com/blipblipcode/query/QuerySelect.kt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/query/src/main/java/com/blipblipcode/query/QuerySelect.kt b/query/src/main/java/com/blipblipcode/query/QuerySelect.kt index 3ef0e0d..73a1ac9 100644 --- a/query/src/main/java/com/blipblipcode/query/QuerySelect.kt +++ b/query/src/main/java/com/blipblipcode/query/QuerySelect.kt @@ -320,14 +320,7 @@ class QuerySelect private constructor( * @throws IllegalArgumentException if the WHERE clause is not set. */ fun build(): QuerySelect { - if(where == null){ - val w = operations.firstNotNullOfOrNull{it}.let { - it ?: throw IllegalArgumentException("WHERE clause is required for QuerySelect") - } - operations.remove(w.key) - - where = w.value.operator - } + require(where != null) { "WHERE clause is required for QuerySelect" } return QuerySelect( where = where!!, table = table,