aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-05-31 17:11:46 -0700
committerAllan Wang <me@allanwang.ca>2017-05-31 17:11:46 -0700
commit8618670b82641d5fbaec9c333f1290bab429ce27 (patch)
tree737c9a04f108ea68547eef2db1ae6e96caa64df6 /app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt
parent9a41937a33539dbfaae4d072361caaec79865c29 (diff)
downloadfrost-8618670b82641d5fbaec9c333f1290bab429ce27.tar.gz
frost-8618670b82641d5fbaec9c333f1290bab429ce27.tar.bz2
frost-8618670b82641d5fbaec9c333f1290bab429ce27.zip
add more cookie handling
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.kt24
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