From 8618670b82641d5fbaec9c333f1290bab429ce27 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 31 May 2017 17:11:46 -0700 Subject: add more cookie handling --- .../kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt (limited to 'app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt') 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 List.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 -- cgit v1.2.3