diff --git a/query/src/main/java/com/blipblipcode/query/QueryDelete.kt b/query/src/main/java/com/blipblipcode/query/QueryDelete.kt index 2cd5ff2..23f2ea4 100644 --- a/query/src/main/java/com/blipblipcode/query/QueryDelete.kt +++ b/query/src/main/java/com/blipblipcode/query/QueryDelete.kt @@ -1,7 +1,6 @@ package com.blipblipcode.query import com.blipblipcode.query.operator.LogicalOperation -import com.blipblipcode.query.operator.LogicalType import com.blipblipcode.query.operator.SQLOperator /** @@ -14,7 +13,7 @@ import com.blipblipcode.query.operator.SQLOperator * @property operations A map of logical operations (AND, OR, etc.) to be appended to the WHERE clause. */ class QueryDelete private constructor( - private var where: SQLOperator<*>?, + private var where: Pair?, private val table: String, private val operations: LinkedHashMap, ):Queryable { @@ -54,7 +53,7 @@ class QueryDelete private constructor( * @return The current `QueryDelete` instance for chaining. */ fun setWhere(operator: SQLOperator<*>): QueryDelete { - where = operator + where = operator.column to LogicalOperation.Where(operator) return this } @@ -72,7 +71,7 @@ class QueryDelete private constructor( override fun getSqlOperators(): List> { return buildList { require(where != null) { "A WHERE clause must be specified." } - add(where!!) + add(where!!.second.operator) operations.values.forEach { add(it.operator) } } } @@ -92,7 +91,7 @@ class QueryDelete private constructor( */ override fun asSql(): String { require(where != null) { "A WHERE clause must be specified." } - return "DELETE FROM $table WHERE ${where!!.toSQLString()} ${operations.values.joinToString(" ") { it.asString() }}".trim() + return "DELETE FROM $table ${where!!.second.asString()} ${operations.values.joinToString(" ") { it.asString() }}".trim() } /** @@ -103,7 +102,7 @@ class QueryDelete private constructor( */ override fun asSql(predicate: (SQLOperator<*>) -> Boolean): String { require(where != null) { "A WHERE clause must be specified." } - return "DELETE FROM $table WHERE ${where!!.toSQLString()} ${operations.values.filter { predicate(it.operator) }.joinToString(" ") { it.asString() }}".trim() + return "DELETE FROM $table ${where!!.second.asString()} ${operations.values.filter { predicate(it.operator) }.joinToString(" ") { it.asString() }}".trim() } /** @@ -113,7 +112,7 @@ class QueryDelete private constructor( class QueryBuilder internal constructor( private val table: String, private val operations: LinkedHashMap ) { - private var where: SQLOperator<*>? = null + private var where: Pair? = null /** * Clears all conditions and resets the builder. @@ -132,7 +131,7 @@ class QueryDelete private constructor( * @return The `QueryBuilder` instance for chaining. */ fun and(key: String, operator: SQLOperator<*>): QueryBuilder { - operations[key] = LogicalOperation(LogicalType.AND, operator) + operations[key] = LogicalOperation.And(operator) return this } /** @@ -141,7 +140,7 @@ class QueryDelete private constructor( * @return The `QueryBuilder` instance for chaining. */ fun and(operator: SQLOperator<*>): QueryBuilder { - operations[operator.column] = LogicalOperation(LogicalType.AND, operator) + operations[operator.column] = LogicalOperation.And(operator) return this } @@ -151,7 +150,7 @@ class QueryDelete private constructor( * @return The `QueryBuilder` instance for chaining. */ fun andNot(operator: SQLOperator<*>): QueryBuilder { - operations[operator.column] = LogicalOperation(LogicalType.AND_NOT, operator) + operations[operator.column] = LogicalOperation.And(operator) return this } @@ -161,7 +160,7 @@ class QueryDelete private constructor( * @return The `QueryBuilder` instance for chaining. */ fun exists(operator: SQLOperator<*>): QueryBuilder { - operations[operator.column] = LogicalOperation(LogicalType.EXISTS, operator) + operations[operator.column] = LogicalOperation.Exists( operator) return this } @@ -171,7 +170,7 @@ class QueryDelete private constructor( * @return The `QueryBuilder` instance for chaining. */ fun not(operator: SQLOperator<*>): QueryBuilder { - operations[operator.column] = LogicalOperation(LogicalType.NOT, operator) + operations[operator.column] = LogicalOperation.Not(operator) return this } @@ -182,7 +181,7 @@ class QueryDelete private constructor( * @return The `QueryBuilder` instance for chaining. */ fun or(key: String, operator: SQLOperator<*>): QueryBuilder { - operations[key] = LogicalOperation(LogicalType.OR, operator) + operations[key] = LogicalOperation.Or(operator) return this } @@ -193,7 +192,7 @@ class QueryDelete private constructor( * @return The `QueryBuilder` instance for chaining. */ fun like(key: String, operator: SQLOperator.Like): QueryBuilder { - operations[key] = LogicalOperation(LogicalType.AND, operator) + operations[key] = LogicalOperation.And( operator) return this } @@ -204,7 +203,7 @@ class QueryDelete private constructor( * @return The `QueryBuilder` instance for chaining. */ fun all(key: String, operator: SQLOperator<*>): QueryBuilder { - operations[key] = LogicalOperation(LogicalType.ALL, operator) + operations[key] = LogicalOperation.All(operator) return this } @@ -224,7 +223,7 @@ class QueryDelete private constructor( * @return The `QueryBuilder` instance for chaining. */ fun where(operator: SQLOperator<*>): QueryBuilder { - where = operator + where = operator.column to LogicalOperation.Where(operator) return this } diff --git a/query/src/main/java/com/blipblipcode/query/QuerySelect.kt b/query/src/main/java/com/blipblipcode/query/QuerySelect.kt index f8455f4..1c8cc25 100644 --- a/query/src/main/java/com/blipblipcode/query/QuerySelect.kt +++ b/query/src/main/java/com/blipblipcode/query/QuerySelect.kt @@ -2,7 +2,6 @@ package com.blipblipcode.query import com.blipblipcode.query.operator.Limit import com.blipblipcode.query.operator.LogicalOperation -import com.blipblipcode.query.operator.LogicalType import com.blipblipcode.query.operator.OrderBy import com.blipblipcode.query.operator.SQLOperator @@ -17,7 +16,7 @@ import com.blipblipcode.query.operator.SQLOperator * @property fields The list of columns to be returned in the result set. Defaults to "*". */ class QuerySelect private constructor( - private var where: Pair>?, + private var where: Pair?, private val table: String, private val operations: LinkedHashMap, private val fields: List @@ -37,12 +36,13 @@ class QuerySelect private constructor( return QueryBuilder(table, LinkedHashMap()) } } + /** * Creates a new `QueryBuilder` instance initialized with the current state of this `QuerySelect`. * @param consumer A lambda that receives the `QueryBuilder` to customize the new query. * @return A new `QueryBuilder` instance. */ - fun newBuilder(consumer:(QueryBuilder)-> Unit): QueryBuilder { + fun newBuilder(consumer: (QueryBuilder) -> Unit): QueryBuilder { val builder = QueryBuilder(table, operations) where?.let { builder.where(it.first, it.second) } builder.setFields(*fields.toTypedArray()) @@ -70,6 +70,8 @@ class QuerySelect private constructor( fun clear(): QuerySelect { operations.clear() where = null + limit = null + orderBy = null return this } @@ -79,15 +81,17 @@ class QuerySelect private constructor( * @return The current `QuerySelect` instance for chaining. */ fun setWhere(operator: SQLOperator<*>): QuerySelect { - where = operator.column to operator + where = operator.column to LogicalOperation.Where(operator) return this - }/** + } + + /** * Sets or replaces the main WHERE clause of the query. * @param operator The new SQL operator for the WHERE clause. * @return The current `QuerySelect` instance for chaining. */ fun setWhere(key: String, operator: SQLOperator<*>): QuerySelect { - where = key to operator + where = key to LogicalOperation.Where(operator) return this } @@ -123,7 +127,7 @@ class QuerySelect private constructor( override fun getSqlOperators(): List> { return buildList { - where?.let { add(it.second) } + where?.let { add(it.second.operator) } operations.values.forEach { add(it.operator) } orderBy?.let { add(it) } limit?.let { add(it) } @@ -132,7 +136,7 @@ class QuerySelect private constructor( fun getOperations(): Map> { return buildMap { - where?.let { put(it.first, it.second) } + where?.let { put(it.first, it.second.operator) } operations.forEach { put(it.key, it.value.operator) } } } @@ -151,12 +155,13 @@ class QuerySelect private constructor( */ override fun asSql(): String { val fieldStr = if (fields.isEmpty()) "*" else fields.joinToString(", ") - val operationsStr = if (operations.isNotEmpty()) operations.values.joinToString(" ") { it.asString() } else "" + val operationsStr = + if (operations.isNotEmpty()) operations.values.joinToString(" ") { it.asString() } else "" return buildString { if (where == null) { append("SELECT $fieldStr FROM $table") - }else{ - append("SELECT $fieldStr FROM $table WHERE ${where?.second?.toSQLString()} $operationsStr".trim()) + } else { + append("SELECT $fieldStr FROM $table ${where?.second?.asString()} $operationsStr".trim()) } if (orderBy != null) { append(" ") @@ -168,19 +173,22 @@ class QuerySelect private constructor( } } } + /** * Generates the SQL string for the SELECT statement. * @param predicate The predicate to filter the operators. * @return The complete SELECT SQL query as a string. */ - override fun asSql(predicate: ( SQLOperator<*>) -> Boolean): String { + override fun asSql(predicate: (SQLOperator<*>) -> Boolean): String { val fieldStr = if (fields.isEmpty()) "*" else fields.joinToString(", ") - val operationsStr = if (operations.isNotEmpty()) operations.values.filter { predicate(it.operator) }.joinToString(" ") { it.asString() } else "" + val operationsStr = + if (operations.isNotEmpty()) operations.values.filter { predicate(it.operator) } + .joinToString(" ") { it.asString() } else "" return buildString { if (where == null) { append("SELECT $fieldStr FROM $table") - }else{ - append("SELECT $fieldStr FROM $table WHERE ${where?.second?.toSQLString()} $operationsStr".trim()) + } else { + append("SELECT $fieldStr FROM $table ${where?.second?.asString()} $operationsStr".trim()) } if (orderBy != null) { append(" ") @@ -241,11 +249,20 @@ class QuerySelect private constructor( private val table: String, private val operations: LinkedHashMap ) { - private var where: Pair>? = null + private var where: Pair? = null private var fields: List = listOf("*") private var orderBy: OrderBy? = null private var limit: Limit? = null + /** + * Retrieves the current SQL operator for a given key. + * @param key The key of the SQL operator to retrieve. + * @return The `SQLOperator` if found, otherwise null. + */ + fun getSqlOperation(key: String): SQLOperator<*>? { + return operations[key]?.operator + } + /** * Clears all logical operations and the main WHERE clause from the query. * @return The current `QuerySelect` instance for chaining. @@ -263,16 +280,17 @@ class QuerySelect private constructor( * @return The `QueryBuilder` instance for chaining. */ fun and(key: String, operator: SQLOperator<*>): QueryBuilder { - operations[key] = LogicalOperation(LogicalType.AND, operator) + operations[key] = LogicalOperation.And(operator) return this } + /** * Adds an AND condition to the WHERE clause. * @param operator The SQL operator for this condition. * @return The `QueryBuilder` instance for chaining. */ fun and(operator: SQLOperator<*>): QueryBuilder { - operations[operator.column] = LogicalOperation(LogicalType.AND, operator) + operations[operator.column] = LogicalOperation.And(operator) return this } @@ -282,7 +300,7 @@ class QuerySelect private constructor( * @return The `QueryBuilder` instance for chaining. */ fun andNot(operator: SQLOperator<*>): QueryBuilder { - operations[operator.column] = LogicalOperation(LogicalType.AND_NOT, operator) + operations[operator.column] = LogicalOperation.AndNot(operator) return this } @@ -292,7 +310,7 @@ class QuerySelect private constructor( * @return The `QueryBuilder` instance for chaining. */ fun exists(operator: SQLOperator<*>): QueryBuilder { - operations[operator.column] = LogicalOperation(LogicalType.EXISTS, operator) + operations[operator.column] = LogicalOperation.Exists(operator) return this } @@ -302,9 +320,10 @@ class QuerySelect private constructor( * @return The `QueryBuilder` instance for chaining. */ fun not(operator: SQLOperator<*>): QueryBuilder { - operations[operator.column] = LogicalOperation(LogicalType.NOT, operator) + operations[operator.column] = LogicalOperation.Not(operator) return this } + /** * Adds an OR condition to the WHERE clause. * @param key A unique key for this condition. @@ -312,7 +331,7 @@ class QuerySelect private constructor( * @return The `QueryBuilder` instance for chaining. */ fun or(key: String, operator: SQLOperator<*>): QueryBuilder { - operations[key] = LogicalOperation(LogicalType.OR, operator) + operations[key] = LogicalOperation.Or(operator) return this } @@ -323,7 +342,7 @@ class QuerySelect private constructor( * @return The `QueryBuilder` instance for chaining. */ fun like(key: String, operator: SQLOperator.Like): QueryBuilder { - operations[key] = LogicalOperation(LogicalType.AND, operator) + operations[key] = LogicalOperation.And(operator) return this } @@ -334,7 +353,7 @@ class QuerySelect private constructor( * @return The `QueryBuilder` instance for chaining. */ fun all(key: String, operator: SQLOperator<*>): QueryBuilder { - operations[key] = LogicalOperation(LogicalType.ALL, operator) + operations[key] = LogicalOperation.All(operator) return this } @@ -348,13 +367,24 @@ class QuerySelect private constructor( return this } + /** + * Adds a logical operation. + * @param key A unique key for the logical operation. + * @param operation The logical operation to add. + * @return The `QueryBuilder` instance for chaining. + */ + fun addLogicalOperation(key: String, operation: LogicalOperation): QueryBuilder { + operations[key] = operation + return this + } + /** * Sets the main WHERE clause for the query. * @param operator The SQL operator for the WHERE clause. * @return The `QueryBuilder` instance for chaining. */ fun where(operator: SQLOperator<*>): QueryBuilder { - where = operator.column to operator + where = operator.column to LogicalOperation.Where(operator) return this } @@ -364,6 +394,11 @@ class QuerySelect private constructor( * @return The `QueryBuilder` instance for chaining. */ fun where(key: String, operator: SQLOperator<*>): QueryBuilder { + where = key to LogicalOperation.Where(operator) + return this + } + + fun where(key: String, operator: LogicalOperation): QueryBuilder { where = key to operator return this } @@ -387,6 +422,7 @@ class QuerySelect private constructor( this.orderBy = orderBy return this } + /** * Returns the ORDER BY clause for the query. * @return The OrderBy object, or null if not set. @@ -422,28 +458,34 @@ class QuerySelect private constructor( * @param transform A lambda that takes the existing LogicalOperation and returns a new one. * @return The `QueryBuilder` instance for chaining. */ - fun transformOperation(key:String, transform: (LogicalOperation) -> LogicalOperation): QueryBuilder { + fun transformOperation( + key: String, + transform: (LogicalOperation) -> LogicalOperation + ): QueryBuilder { when { operations.containsKey(key) -> { val operator = operations[key] val newOperations = transform(operator!!) operations[key] = newOperations } + where?.first == key -> { - val newOperations = transform(LogicalOperation(LogicalType.AND, where!!.second)) - where = where?.copy(second = newOperations.operator) + val newOperations = transform(where!!.second) + where = where?.copy(second = newOperations) } + else -> Unit } return this } + /** * Builds the `QuerySelect` instance. * @return A new `QuerySelect` object. * @throws IllegalArgumentException if the WHERE clause is not set. */ fun build(): QuerySelect { - if(operations.isNotEmpty()){ + if (operations.isNotEmpty()) { require(where != null) { "WHERE clause is required for QuerySelect" } } return QuerySelect( @@ -457,4 +499,4 @@ class QuerySelect private constructor( } } } -} +} \ No newline at end of file diff --git a/query/src/main/java/com/blipblipcode/query/UnionQuery.kt b/query/src/main/java/com/blipblipcode/query/UnionQuery.kt index 603f8ee..6532c64 100644 --- a/query/src/main/java/com/blipblipcode/query/UnionQuery.kt +++ b/query/src/main/java/com/blipblipcode/query/UnionQuery.kt @@ -26,7 +26,7 @@ class UnionQuery private constructor( } override fun getSqlOperation(key: String): SQLOperator<*>? { - return queries.flatMap { it.getSqlOperators() }.firstOrNull { it.column.equals(key, ignoreCase = true) } + return queries.map { it.getSqlOperation(key) }.firstOrNull() } /** @@ -138,6 +138,28 @@ class UnionQuery private constructor( return this } + /** + * Retrieves the current SQL operator for a given key. + * @param key The key of the SQL operator to retrieve. + * @return The `SQLOperator` if found, otherwise null. + */ + fun getSqlOperation(key: String): SQLOperator<*>? { + return queries.map { it.getSqlOperation(key) }.firstOrNull() + } + + /** + * Adds a logical operation to all queries in the union. + * @param key The key for the logical operation. + * @param operation The `LogicalOperation` to add. + * @return The `QueryBuilder` instance for chaining. + */ + fun addLogicalOperation(key: String, operation: LogicalOperation):QueryBuilder{ + queries.forEach { + it.addLogicalOperation(key, operation) + } + return this + } + /** * Adds a query to the union. * @param query The `QuerySelect` to add. diff --git a/query/src/main/java/com/blipblipcode/query/operator/LogicalOperation.kt b/query/src/main/java/com/blipblipcode/query/operator/LogicalOperation.kt index 4b9337b..5acc8cb 100644 --- a/query/src/main/java/com/blipblipcode/query/operator/LogicalOperation.kt +++ b/query/src/main/java/com/blipblipcode/query/operator/LogicalOperation.kt @@ -1,21 +1,114 @@ package com.blipblipcode.query.operator +import kotlin.collections.forEachIndexed /** * Represents a logical operation in a SQL query, combining a [LogicalType] with a [SQLOperator]. * For example, "AND age > 18". * - * @property type The type of the logical operation (e.g., AND, OR). + * @property symbol The type of the logical operation (e.g., AND, OR). * @property operator The SQL operator that is part of the logical operation. */ -data class LogicalOperation( - val type: LogicalType, +sealed interface LogicalOperation{ + val symbol: String val operator: SQLOperator<*> -) { + + data class Where(override val operator: SQLOperator<*>) : LogicalOperation { + override val symbol: String = LogicalType.WHERE.sql + override fun asString(): String { + return "$symbol ${operator.toSQLString()}" + } + + override fun clone(vararg arg: Any?): LogicalOperation { + return Where(arg[0] as SQLOperator<*>) + } + } + data class And(override val operator: SQLOperator<*>) : LogicalOperation { + override val symbol: String = LogicalType.AND.sql + override fun asString(): String { + return "$symbol ${operator.toSQLString()}" + } + + override fun clone(vararg arg: Any?): LogicalOperation { + return And(arg[0] as SQLOperator<*>) + } + } + data class Or(override val operator: SQLOperator<*>) : LogicalOperation { + override val symbol: String = LogicalType.OR.sql + override fun asString(): String { + return "$symbol ${operator.toSQLString()}" + } + + override fun clone(vararg arg: Any?): LogicalOperation { + return Or(arg[0] as SQLOperator<*>) + } + } + data class AndNot(override val operator: SQLOperator<*>) : LogicalOperation { + override val symbol: String = LogicalType.AND_NOT.sql + override fun asString(): String { + return "$symbol ${operator.toSQLString()}" + } + override fun clone(vararg arg: Any?): LogicalOperation { + return And(arg[0] as SQLOperator<*>) + } + } + data class Exists(override val operator: SQLOperator<*>) : LogicalOperation{ + override val symbol: String = LogicalType.EXISTS.sql + override fun asString(): String { + return "$symbol ${operator.toSQLString()}" + } + override fun clone(vararg arg: Any?): LogicalOperation { + return Exists(arg[0] as SQLOperator<*>) + } + } + data class Not(override val operator: SQLOperator<*>) : LogicalOperation { + override val symbol: String = LogicalType.NOT.sql + override fun asString(): String { + return "$symbol ${operator.toSQLString()}" + } + override fun clone(vararg arg: Any?): LogicalOperation { + return Not(arg[0] as SQLOperator<*>) + } + } + data class All(override val operator: SQLOperator<*>) : LogicalOperation { + override val symbol: String = LogicalType.ALL.sql + override fun asString(): String { + return "$symbol ${operator.toSQLString()}" + } + override fun clone(vararg arg: Any?): LogicalOperation { + return All(arg[0] as SQLOperator<*>) + } + } + @Suppress("UNCHECKED_CAST") + data class Multiple(val operations: List, override val symbol: String = "AND") : LogicalOperation { + override val operator: SQLOperator<*> + get() = operations.first().operator + + override fun asString(): String { + return buildString { + append("$symbol (") + operations.forEachIndexed { index, logicalOperation -> + if (index == 0) { + append(logicalOperation.operator.asString()) + } else { + append(" ${logicalOperation.asString()}") + } + } + append(")") + + } + } + override fun clone(vararg arg: Any?): LogicalOperation { + return Multiple(arg[0] as List, symbol = arg[1] as? String ?: symbol) + } + } + /** * Converts the logical operation into its SQL string representation. * @return The SQL string for the logical operation (e.g., "AND age > '18'"). */ - fun asString(): String = "${type.sql} ${operator.toSQLString()}" + fun asString(): String + + fun clone(vararg arg: Any?): LogicalOperation } diff --git a/query/src/main/java/com/blipblipcode/query/operator/LogicalType.kt b/query/src/main/java/com/blipblipcode/query/operator/LogicalType.kt index 8ad523e..d6b804e 100644 --- a/query/src/main/java/com/blipblipcode/query/operator/LogicalType.kt +++ b/query/src/main/java/com/blipblipcode/query/operator/LogicalType.kt @@ -4,6 +4,7 @@ package com.blipblipcode.query.operator * Defines the types of logical operations that can be used in a SQL WHERE clause. */ enum class LogicalType(val sql: String) { + WHERE("WHERE"), /** Represents a logical AND operation. */ AND("AND"), /** Represents a logical OR operation. */ diff --git a/query/src/test/java/com/blipblipcode/query/QueryDeleteTest.kt b/query/src/test/java/com/blipblipcode/query/QueryDeleteTest.kt index fb0d7bf..0715a6d 100644 --- a/query/src/test/java/com/blipblipcode/query/QueryDeleteTest.kt +++ b/query/src/test/java/com/blipblipcode/query/QueryDeleteTest.kt @@ -1,7 +1,6 @@ package com.blipblipcode.query import com.blipblipcode.query.operator.LogicalOperation -import com.blipblipcode.query.operator.LogicalType import com.blipblipcode.query.operator.SQLOperator import com.blipblipcode.query.utils.asSQLiteQuery import org.junit.Assert.assertEquals @@ -78,7 +77,7 @@ class QueryDeleteTest { .where(SQLOperator.Equals("id", 1)) .build() - query.addLogicalOperation("status", LogicalOperation(LogicalType.AND, SQLOperator.Equals("status", "inactive"))) + query.addLogicalOperation("status", LogicalOperation.And( SQLOperator.Equals("status", "inactive"))) val expectedSql = "DELETE FROM users WHERE id = 1 AND status = 'inactive'" assertEquals(expectedSql, query.asSql()) diff --git a/query/src/test/java/com/blipblipcode/query/QuerySelectTest.kt b/query/src/test/java/com/blipblipcode/query/QuerySelectTest.kt index 557a9b5..aa695d3 100644 --- a/query/src/test/java/com/blipblipcode/query/QuerySelectTest.kt +++ b/query/src/test/java/com/blipblipcode/query/QuerySelectTest.kt @@ -2,7 +2,6 @@ package com.blipblipcode.query import com.blipblipcode.query.operator.CaseConversion import com.blipblipcode.query.operator.LogicalOperation -import com.blipblipcode.query.operator.LogicalType import com.blipblipcode.query.operator.OrderBy import com.blipblipcode.query.operator.SQLOperator import com.blipblipcode.query.utils.asSQLiteQuery @@ -97,7 +96,7 @@ class QuerySelectTest { val query = QuerySelect.builder("users") .where(SQLOperator.Equals("id", 1)) .build() - query.addLogicalOperation("status", LogicalOperation(LogicalType.AND, SQLOperator.Equals("status", "active"))) + query.addLogicalOperation("status", LogicalOperation.And(SQLOperator.Equals("status", "active"))) val expectedSql = "SELECT * FROM users WHERE id = 1 AND status = 'active'" assertEquals(expectedSql, query.asSql()) } @@ -108,7 +107,7 @@ class QuerySelectTest { .where(SQLOperator.Equals("id", 1)) .and("status", SQLOperator.Equals("status", "inactive")) .build() - query.addLogicalOperation("status", LogicalOperation(LogicalType.AND, SQLOperator.Equals("status", "active"))) + query.addLogicalOperation("status", LogicalOperation.And(SQLOperator.Equals("status", "active"))) val expectedSql = "SELECT * FROM users WHERE id = 1 AND status = 'active'" assertEquals(expectedSql, query.asSql()) } @@ -118,7 +117,7 @@ class QuerySelectTest { val query = QuerySelect.builder("users") .where(SQLOperator.Equals("id", 1)) .build() - query.addLogicalOperation("", LogicalOperation(LogicalType.AND, SQLOperator.Equals("status", "active"))) + query.addLogicalOperation("", LogicalOperation.And(SQLOperator.Equals("status", "active"))) val expectedSql = "SELECT * FROM users WHERE id = 1 AND status = 'active'" assertEquals(expectedSql, query.asSql()) } @@ -128,7 +127,7 @@ class QuerySelectTest { val query = QuerySelect.builder("users") .where(SQLOperator.Equals("id", 1)) .build() - .addLogicalOperation("age", LogicalOperation(LogicalType.OR, SQLOperator.GreaterThan("age", 30))) + .addLogicalOperation("age", LogicalOperation.Or(SQLOperator.GreaterThan("age", 30))) val expectedSql = "SELECT * FROM users WHERE id = 1 OR age > 30" assertEquals(expectedSql, query.asSql()) }