Open greenrobot-team opened 6 years ago
My suggestions:
// Regular
val query = box.query().run {
equal(property, value)
order(property)
build()
}
// With extension val query = box.query { equal(property, value) order(property) }
- **shipped with 2.0.0 beta** ToMany applyChangesToDb
```kotlin
// Regular
toMany.apply {
reset()
add(entity)
removeById(id)
applyChangesToDb()
}
// With extension
toMany.applyChangesToDb(resetFirst = true) { // default is false
add(entity)
removeById(id)
}
objectbox-android
, so add objectbox-android-ktx? compileOnly objectbox-android
?
// Regular
val liveData = ObjectBoxLiveData(query)
// With extension val liveData = query.toLiveData()
-ut
The first two suggestions are released as part of 2.0.0-beta
. Also added docs for the existing extensions. -ut
An upcoming release will add extensions that are shortcuts for query methods that accept Long
and Double
. However, the shortcuts can be used with Int
, Short
and Float
without having to call .toLong()
or .toDouble()
:
// Regular
queryBuilder.equal(Model_.type, typeId.toLong())
// With extension
queryBuilder.equal(Model_.type, typeId)
-ut
Could we also get "notIn" added for String Arrays or something the equivalent of not inValues for the Strings?
@irvine752 This issue is about Kotlin extension functions, not query conditions. Anyhow, not-in is not supported for String properties. Please thumbs up #941!
What about :
val query = box.query().notIn(User_.phone, stringListPhoneNumbers)
notIn
usage Error:
None of the following functions can be called with the arguments supplied.
notIn(Property<User!>!, IntArray!) defined in io.objectbox.query.QueryBuilder
notIn(Property<User!>!, LongArray!) defined in io.objectbox.query.QueryBuilder
@HosseinKurd The notIn (or notOneOf using the new query API) conditions are only supported for integers (Integer and Long)! For Strings only in/oneOf is possible.
@HosseinKurd The notIn (or notOneOf using the new query API) conditions are only supported for integers (Integer and Long)! For Strings only in/oneOf is possible.
So how can I Reverse in/oneOf
?
there is not any not()
function
@HosseinKurd You can't. Put differently: notIn
is not supported for String. You'll have to find another way, e.g. by changing your model or writing custom filter code.
ObjectBox already provides some minimal Kotlin extensions:
This issue is to track what other Kotlin extensions may be added.
Some ground rules:
Things to look out for:
-ut