This commit is contained in:
2023-03-10 18:37:48 +06:00
parent afc6aeea15
commit eeebbff70d
30 changed files with 154 additions and 5 deletions

View File

@@ -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,

View File

@@ -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>) {