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 1
1
package dev.suresh.db
2
2
3
3
import io.exoquery.*
4
+ import io.exoquery.annotation.*
4
5
5
6
@JvmInline value class Email (val value : String )
6
7
@@ -28,6 +29,10 @@ data class Robot(
28
29
29
30
typealias sql = capture
30
31
32
+ @CapturedFunction
33
+ fun String.like (value : String ) =
34
+ capture.expression { free(" ${this @like} LIKE $value " ).asPure<Boolean >() }
35
+
31
36
// Applicative capture
32
37
val people = sql { Table <People >() }
33
38
val address = sql { Table <Address >() }
@@ -54,7 +59,9 @@ val distinct = sql { people.map { it.name to it.age }.distinct() }
54
59
55
60
val limitAndOffest = sql { people.drop(1 ).take(10 ) }
56
61
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
+ }
58
65
59
66
data class CommonType (val id : Long , val name : String )
60
67
@@ -67,7 +74,7 @@ fun select() {
67
74
val s =
68
75
sql.select {
69
76
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 }
71
78
where { p.age > 10 }
72
79
groupBy(p.name, p.age)
73
80
sortBy(p.name to Ord .Asc , p.age to Ord .Desc )
You can’t perform that action at this time.
0 commit comments