diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt new file mode 100644 index 00000000..bb2627a5 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt @@ -0,0 +1,24 @@ +package com.pitchedapps.frost.dbflow + +import android.content.Context +import com.pitchedapps.frost.utils.L +import com.raizlabs.android.dbflow.config.FlowManager +import com.raizlabs.android.dbflow.structure.database.transaction.FastStoreModelTransaction + +/** + * Created by Allan Wang on 2017-05-30. + */ + +object DbUtils { + + fun db(name: String) = FlowManager.getDatabase(name) + fun dbName(name: String) = "$name.db" + fun deleteDatabase(c: Context, name: String) = c.deleteDatabase(dbName(name)) + +} + +inline fun <reified T : Any> List<T>.replace(context: Context, dbName: String) { + L.d("Replacing $dbName.db") + DbUtils.db(dbName).reset(context) + FastStoreModelTransaction.saveBuilder(FlowManager.getModelAdapter(T::class.java)).addAll(this).build() +}
\ No newline at end of file |