Skip to content

Commit ec73170

Browse files
author
Krzysztof Borowy
committed
room ktx extension
1 parent d948069 commit ec73170

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ dependencies {
114114
def coroutinesTest_version = "1.4.2"
115115

116116
implementation "androidx.room:room-runtime:$room_version"
117+
implementation "androidx.room:room-ktx:$room_version"
117118
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
118119
kapt "androidx.room:room-compiler:$room_version"
119120

android/src/main/java/com/reactnativecommunity/asyncstorage/next/StorageSupplier.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import androidx.room.Query
1212
import androidx.room.Room
1313
import androidx.room.RoomDatabase
1414
import androidx.room.Transaction
15-
import androidx.room.Update
1615
import androidx.room.migration.Migration
1716
import androidx.sqlite.db.SupportSQLiteDatabase
1817
import org.json.JSONObject
@@ -35,18 +34,18 @@ internal interface StorageDao {
3534

3635
@Transaction
3736
@Query("SELECT * FROM $TABLE_NAME WHERE `$COLUMN_KEY` IN (:keys)")
38-
fun getValues(keys: List<String>): List<Entry>
37+
suspend fun getValues(keys: List<String>): List<Entry>
3938

4039
@Transaction
4140
@Insert(onConflict = OnConflictStrategy.REPLACE)
42-
fun setValues(entries: List<Entry>)
41+
suspend fun setValues(entries: List<Entry>)
4342

4443
@Transaction
4544
@Query("DELETE FROM $TABLE_NAME WHERE `$COLUMN_KEY` in (:keys)")
46-
fun removeValues(keys: List<String>)
45+
suspend fun removeValues(keys: List<String>)
4746

4847
@Transaction
49-
fun mergeValues(entries: List<Entry>) {
48+
suspend fun mergeValues(entries: List<Entry>) {
5049
val currentDbEntries = getValues(entries.map { it.key })
5150
val newEntries = mutableListOf<Entry>()
5251

@@ -67,11 +66,11 @@ internal interface StorageDao {
6766

6867
@Transaction
6968
@Query("SELECT `$COLUMN_KEY` FROM $TABLE_NAME")
70-
fun getKeys(): List<String>
69+
suspend fun getKeys(): List<String>
7170

7271
@Transaction
7372
@Query("DELETE FROM $TABLE_NAME")
74-
fun clear()
73+
suspend fun clear()
7574
}
7675

7776

@@ -148,6 +147,7 @@ class StorageSupplier internal constructor(db: StorageDb) : AsyncStorageAccess {
148147
return StorageSupplier(StorageDb.getDatabase(ctx))
149148
}
150149
}
150+
151151
private val access = db.storage()
152152

153153
override suspend fun getValues(keys: List<String>) = access.getValues(keys)

0 commit comments

Comments
 (0)