This commit is contained in:
InsanusMokrassar committed 2023-03-10 18:37:48 +06:00
1 parent afc6aeea15
commit eeebbff70d
30 files changed
+154 -5

No files matched your search

@@ -32,6 +32,18 @@ abstract class AbstractAndroidCRUDRepo<ObjectType, IdType>(
}
}
override suspend fun getAll(): Map<IdType, ObjectType> = helper.readableTransaction {
select(
tableName,
null,
""
).use {
it.map {
it.toId() to it.toObject()
}
}
}.toMap()
override suspend fun getById(id: IdType): ObjectType? = helper.readableTransaction {
select(
tableName,
@@ -104,6 +104,15 @@ class KeyValueStore<T : Any> internal constructor (
override suspend fun contains(key: String): Boolean = sharedPreferences.contains(key)
override suspend fun getAll(): Map<String, T> {
val resultMap = mutableMapOf<String, T>()
sharedPreferences.all.forEach { (k, v) ->
@Suppress("UNCHECKED_CAST")
resultMap[k] = (v as? T) ?: return@forEach
}
return resultMap.toMap()
}
override suspend fun count(): Long = sharedPreferences.all.size.toLong()
override suspend fun set(toSet: Map<String, T>) {