File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
backend/jvm/src/main/kotlin/dev/suresh/db Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 11package dev.suresh.db
22
33import 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
2930typealias 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
3237val people = sql { Table <People >() }
3338val address = sql { Table <Address >() }
@@ -54,7 +59,9 @@ val distinct = sql { people.map { it.name to it.age }.distinct() }
5459
5560val 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
5966data 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 )
You can’t perform that action at this time.
0 commit comments