Skip to content

Commit 89cb585

Browse files
Kotlin extensions: build query.
1 parent 57c8e80 commit 89cb585

File tree

1 file changed

+15
-0
lines changed
  • objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin

1 file changed

+15
-0
lines changed

objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin/Extensions.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package io.objectbox.kotlin
1919
import io.objectbox.Box
2020
import io.objectbox.BoxStore
2121
import io.objectbox.Property
22+
import io.objectbox.query.Query
2223
import io.objectbox.query.QueryBuilder
2324
import kotlin.reflect.KClass
2425

@@ -34,3 +35,17 @@ inline fun <reified T> QueryBuilder<T>.inValues(property: Property, values: Long
3435
/** An alias for the "in" method, which is a reserved keyword in Kotlin. */
3536
inline fun <reified T> QueryBuilder<T>.inValues(property: Property, values: IntArray): QueryBuilder<T>?
3637
= `in`(property, values)
38+
39+
/**
40+
* Allows building a query for this Box instance with a call to [build][QueryBuilder.build] to return a [Query] instance.
41+
* ```
42+
* val query = box.query {
43+
* equal(Entity_.property, value)
44+
* }
45+
* ```
46+
*/
47+
inline fun <T> Box<T>.query(block: QueryBuilder<T>.() -> Unit) : Query<T> {
48+
val builder = query()
49+
block(builder)
50+
return builder.build()
51+
}

0 commit comments

Comments
 (0)