@@ -31,8 +31,6 @@ data class Robot(
3131 val name : String ,
3232)
3333
34- typealias sql = capture
35-
3634// Applicative capture
3735val people = sql { Table <People >() }
3836val address = sql { Table <Address >() }
@@ -60,7 +58,7 @@ val distinct = sql { people.map { it.name to it.age }.distinct() }
6058val limitAndOffest = sql { people.drop(1 ).take(10 ) }
6159
6260val union = sql {
63- people.filter { it.name.like(" aaa%" ).use } union people.filter { it.name.like(" bbb%" ).use }
61+ people.filter { it.name.like(" aaa%" ) } union people.filter { it.name.like(" bbb%" ) }
6462}
6563
6664data class CommonType (val id : Long , val name : String )
@@ -74,7 +72,7 @@ fun select() {
7472 val s =
7573 sql.select {
7674 val p = from(people)
77- val a = join(address) { it.id == p.addressId && it.city.like(" %San Francisco%" ).use }
75+ val a = join(address) { it.id == p.addressId && it.city.like(" %San Francisco%" ) }
7876 where { p.age > 10 }
7977 groupBy(p.name, p.age)
8078 having { p95(p.age).use > 50 }
@@ -117,12 +115,11 @@ fun batch(p: Sequence<People>) {
117115 sql.batch(p) { p -> insert<People > { setParams(p).excluding(id) } }
118116}
119117
120- @CapturedFunction
121- // context(_: CapturedBlock)
118+ @SqlFragment
122119fun String.like (value : String ) =
123- capture .expression { free(" ${this @like} LIKE $value " ).asPure<Boolean >() }
120+ sql .expression { free(" ${this @like} LIKE $value " ).asPure<Boolean >() }
124121
125- @CapturedFunction fun p95 (measure : Int ) = sql.expression { avg(measure) + 1.645 * stddev(measure) }
122+ @SqlFragment fun p95 (measure : Int ) = sql.expression { avg(measure) + 1.645 * stddev(measure) }
126123
127124// data class User(val id: Long, val name: String, val active: Int)
128125//
0 commit comments