mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-17 13:53:49 +00:00
fixes in OneToManyAndroidRepo and adding of CursorIterator
This commit is contained in:
parent
afe5a72c6f
commit
15e9254e00
@ -2,6 +2,11 @@
|
||||
|
||||
## 0.9.20
|
||||
|
||||
* `Repos`:
|
||||
* `Common`:
|
||||
* Fixes in `OneToManyAndroidRepo`
|
||||
* New `CursorIterator`
|
||||
|
||||
## 0.9.19
|
||||
|
||||
* `Versions`:
|
||||
|
@ -0,0 +1,27 @@
|
||||
package dev.inmo.micro_utils.repos
|
||||
|
||||
import android.database.Cursor
|
||||
|
||||
class CursorIterator(
|
||||
private val c: Cursor
|
||||
) : Iterator<Cursor> {
|
||||
private var i = 0
|
||||
|
||||
init {
|
||||
c.moveToFirst()
|
||||
}
|
||||
override fun hasNext(): Boolean {
|
||||
return i < c.count
|
||||
}
|
||||
|
||||
override fun next(): Cursor {
|
||||
i++
|
||||
return if (c.moveToNext()) {
|
||||
c
|
||||
} else {
|
||||
throw NoSuchElementException()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
operator fun Cursor.iterator(): CursorIterator = CursorIterator(this)
|
@ -143,7 +143,13 @@ class OneToManyAndroidRepo<Key, Value>(
|
||||
}.toLong()
|
||||
|
||||
override suspend fun count(k: Key): Long = helper.blockingReadableTransaction {
|
||||
selectDistinct(tableName, columns = valueColumnArray, selection = "$idColumnName=?", selectionArgs = arrayOf(k.keyAsString()), limit = FirstPagePagination(1).limitClause()).use {
|
||||
select(
|
||||
tableName,
|
||||
columns = valueColumnArray,
|
||||
selection = "$idColumnName=?",
|
||||
selectionArgs = arrayOf(k.keyAsString()),
|
||||
limit = FirstPagePagination(1).limitClause()
|
||||
).use {
|
||||
it.count
|
||||
}
|
||||
}.toLong()
|
||||
|
Loading…
Reference in New Issue
Block a user