Skip to content

Commit 5203fb2

Browse files
committed
chore: LIKE operator support
1 parent 1a34813 commit 5203fb2

File tree

1 file changed

+9
-2
lines changed
  • backend/jvm/src/main/kotlin/dev/suresh/db

1 file changed

+9
-2
lines changed

backend/jvm/src/main/kotlin/dev/suresh/db/Query.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.suresh.db
22

33
import io.exoquery.*
4+
import io.exoquery.annotation.*
45

56
@JvmInline value class Email(val value: String)
67

@@ -28,6 +29,10 @@ data class Robot(
2829

2930
typealias sql = capture
3031

32+
@CapturedFunction
33+
fun String.like(value: String) =
34+
capture.expression { free("${this@like} LIKE $value").asPure<Boolean>() }
35+
3136
// Applicative capture
3237
val people = sql { Table<People>() }
3338
val address = sql { Table<Address>() }
@@ -54,7 +59,9 @@ val distinct = sql { people.map { it.name to it.age }.distinct() }
5459

5560
val limitAndOffest = sql { people.drop(1).take(10) }
5661

57-
val union = sql { people.filter { it.name == "aaa%" } union people.filter { it.name == "bbb%" } }
62+
val union = sql {
63+
people.filter { it.name.like("aaa%").use } union people.filter { it.name.like("bbb%").use }
64+
}
5865

5966
data class CommonType(val id: Long, val name: String)
6067

@@ -67,7 +74,7 @@ fun select() {
6774
val s =
6875
sql.select {
6976
val p = from(people)
70-
val a = join(address) { a -> a.id == p.addressId && a.city == "San Francisco%" }
77+
val a = join(address) { it.id == p.addressId && it.city.like("%San Francisco%").use }
7178
where { p.age > 10 }
7279
groupBy(p.name, p.age)
7380
sortBy(p.name to Ord.Asc, p.age to Ord.Desc)

0 commit comments

Comments
 (0)