Skip to content

Commit

Permalink
Added where opt test
Browse files Browse the repository at this point in the history
  • Loading branch information
takapi327 committed Jan 3, 2025
1 parent 549da10 commit 6896a5b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,48 @@ 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)
.where(_.p1 >= 1)
.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)
Expand Down Expand Up @@ -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)(
Expand Down Expand Up @@ -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 ?")
}
49 changes: 49 additions & 0 deletions module/ldbc-schema/src/test/scala/ldbc/schema/TableQueryTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,48 @@ 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)
.where(_.p1 >= 1)
.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)
Expand Down Expand Up @@ -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)(
Expand Down Expand Up @@ -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 ?")
}

0 comments on commit 6896a5b

Please sign in to comment.