diff --git a/module/ldbc-query-builder/src/test/scala/ldbc/query/builder/TableQueryTest.scala b/module/ldbc-query-builder/src/test/scala/ldbc/query/builder/TableQueryTest.scala index 186a73f86..46b6f22a8 100644 --- a/module/ldbc-query-builder/src/test/scala/ldbc/query/builder/TableQueryTest.scala +++ b/module/ldbc-query-builder/src/test/scala/ldbc/query/builder/TableQueryTest.scala @@ -30,6 +30,20 @@ class TableQueryTest extends AnyFlatSpec: .and(_.p2 === "test") .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ? AND test.p2 = ?" ) + assert( + query + .select(_.p1) + .whereOpt(Some(1))((test, value) => test.p1 orMore value) + .and(_.p2 === "test") + .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ? AND test.p2 = ?" + ) + assert( + query + .select(_.p1) + .whereOpt[Int](None)((test, value) => test.p1 orMore value) + .and(_.p2 === "test") + .statement === "SELECT test.p1 FROM test WHERE test.p2 = ?" + ) assert( query .select(_.p1) @@ -37,6 +51,27 @@ class TableQueryTest extends AnyFlatSpec: .and(_.p2 === "test", false) .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ?" ) + assert( + query + .select(_.p1) + .where(_.p1 >= 1) + .andOpt(Some("test"))((test, value) => test.p2 _equals value) + .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ? AND test.p2 = ?" + ) + assert( + query + .select(_.p1) + .where(_.p1 >= 1) + .andOpt[String](None)((test, value) => test.p2 _equals value) + .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ?" + ) + assert( + query + .select(_.p1) + .whereOpt[Int](None)((test, value) => test.p1 orMore value) + .andOpt[String](None)((test, value) => test.p2 _equals value) + .statement === "SELECT test.p1 FROM test" + ) assert( query .select(_.p1) @@ -304,6 +339,18 @@ class TableQueryTest extends AnyFlatSpec: .where(_.p1 === 1L) .statement === "UPDATE test SET p1 = ?, p2 = ?, p3 = ? WHERE test.p1 = ?" ) + assert( + query + .update(Test(1L, "p2", Some("p3"))) + .whereOpt(Some(1L))((test, value) => test.p1 === value) + .statement === "UPDATE test SET p1 = ?, p2 = ?, p3 = ? WHERE test.p1 = ?" + ) + assert( + query + .update(Test(1L, "p2", Some("p3"))) + .whereOpt[Long](None)((test, value) => test.p1 === value) + .statement === "UPDATE test SET p1 = ?, p2 = ?, p3 = ?" + ) assert( query .update(q => q.p1 *: q.p2 *: q.p3)( @@ -351,6 +398,8 @@ class TableQueryTest extends AnyFlatSpec: it should "The delete query statement generated from Table is equal to the specified query statement." in { assert(query.delete.statement === "DELETE FROM test") assert(query.delete.where(_.p1 === 1L).statement === "DELETE FROM test WHERE test.p1 = ?") + assert(query.delete.whereOpt(Some(1L))((test, value) => test.p1 === value).statement === "DELETE FROM test WHERE test.p1 = ?") + assert(query.delete.whereOpt[Long](None)((test, value) => test.p1 === value).statement === "DELETE FROM test") assert(query.delete.limit(1).statement === "DELETE FROM test LIMIT ?") assert(query.delete.where(_.p1 === 1L).limit(1).statement === "DELETE FROM test WHERE test.p1 = ? LIMIT ?") } diff --git a/module/ldbc-schema/src/test/scala/ldbc/schema/TableQueryTest.scala b/module/ldbc-schema/src/test/scala/ldbc/schema/TableQueryTest.scala index e8b8d9f0e..4f0de5e4e 100644 --- a/module/ldbc-schema/src/test/scala/ldbc/schema/TableQueryTest.scala +++ b/module/ldbc-schema/src/test/scala/ldbc/schema/TableQueryTest.scala @@ -49,6 +49,20 @@ class TableQueryTest extends AnyFlatSpec: .and(_.p2 === "test") .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ? AND test.p2 = ?" ) + assert( + query + .select(_.p1) + .whereOpt(Some(1))((test, value) => test.p1 orMore value) + .and(_.p2 === "test") + .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ? AND test.p2 = ?" + ) + assert( + query + .select(_.p1) + .whereOpt[Int](None)((test, value) => test.p1 orMore value) + .and(_.p2 === "test") + .statement === "SELECT test.p1 FROM test WHERE test.p2 = ?" + ) assert( query .select(_.p1) @@ -56,6 +70,27 @@ class TableQueryTest extends AnyFlatSpec: .and(_.p2 === "test", false) .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ?" ) + assert( + query + .select(_.p1) + .where(_.p1 >= 1) + .andOpt(Some("test"))((test, value) => test.p2 _equals value) + .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ? AND test.p2 = ?" + ) + assert( + query + .select(_.p1) + .where(_.p1 >= 1) + .andOpt[String](None)((test, value) => test.p2 _equals value) + .statement === "SELECT test.p1 FROM test WHERE test.p1 >= ?" + ) + assert( + query + .select(_.p1) + .whereOpt[Int](None)((test, value) => test.p1 orMore value) + .andOpt[String](None)((test, value) => test.p2 _equals value) + .statement === "SELECT test.p1 FROM test" + ) assert( query .select(_.p1) @@ -323,6 +358,18 @@ class TableQueryTest extends AnyFlatSpec: .where(_.p1 === 1L) .statement === "UPDATE test SET p1 = ?, p2 = ?, p3 = ? WHERE test.p1 = ?" ) + assert( + query + .update(Test(1L, "p2", Some("p3"))) + .whereOpt(Some(1L))((test, value) => test.p1 === value) + .statement === "UPDATE test SET p1 = ?, p2 = ?, p3 = ? WHERE test.p1 = ?" + ) + assert( + query + .update(Test(1L, "p2", Some("p3"))) + .whereOpt[Long](None)((test, value) => test.p1 === value) + .statement === "UPDATE test SET p1 = ?, p2 = ?, p3 = ?" + ) assert( query .update(q => q.p1 *: q.p2 *: q.p3)( @@ -370,6 +417,8 @@ class TableQueryTest extends AnyFlatSpec: it should "The delete query statement generated from Table is equal to the specified query statement." in { assert(query.delete.statement === "DELETE FROM test") assert(query.delete.where(_.p1 === 1L).statement === "DELETE FROM test WHERE test.p1 = ?") + assert(query.delete.whereOpt(Some(1L))((test, value) => test.p1 === value).statement === "DELETE FROM test WHERE test.p1 = ?") + assert(query.delete.whereOpt[Long](None)((test, value) => test.p1 === value).statement === "DELETE FROM test") assert(query.delete.limit(1).statement === "DELETE FROM test LIMIT ?") assert(query.delete.where(_.p1 === 1L).limit(1).statement === "DELETE FROM test WHERE test.p1 = ? LIMIT ?") }