diff --git a/app/src/main/kotlin/app/AppModule.kt b/app/src/main/kotlin/app/AppModule.kt index 71c48ffc..185798f0 100644 --- a/app/src/main/kotlin/app/AppModule.kt +++ b/app/src/main/kotlin/app/AppModule.kt @@ -1,5 +1,6 @@ package app +import android.content.Context import api.Api import api.ApiImpl import area.AreaModel @@ -36,7 +37,7 @@ import user.UsersModel import user.UsersRepo val appModule = module { - single { Database(get()) } + single { Database(get().getDatabasePath("btcmap-2024-05-15.db").absolutePath) } single { ApiImpl() }.bind(Api::class) diff --git a/app/src/main/kotlin/db/Database.kt b/app/src/main/kotlin/db/Database.kt index a36c3a6a..27ce85af 100644 --- a/app/src/main/kotlin/db/Database.kt +++ b/app/src/main/kotlin/db/Database.kt @@ -1,6 +1,5 @@ package db -import android.content.Context import androidx.sqlite.SQLiteConnection import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.sqlite.execSQL @@ -15,10 +14,10 @@ import user.UserQueries import java.time.LocalDateTime import java.util.concurrent.locks.ReentrantLock -class Database(context: Context) { +class Database(path: String) { private val conn: SQLiteConnection = - BundledSQLiteDriver().open(context.getDatabasePath("btcmap-2024-05-15.db").absolutePath) + BundledSQLiteDriver().open(path) .apply { execSQL("PRAGMA journal_mode=WAL") execSQL("PRAGMA synchronous=NORMAL") diff --git a/app/src/test/kotlin/area/AreaQueriesTest.kt b/app/src/test/kotlin/area/AreaQueriesTest.kt index 6aaca533..7fc1bec2 100644 --- a/app/src/test/kotlin/area/AreaQueriesTest.kt +++ b/app/src/test/kotlin/area/AreaQueriesTest.kt @@ -1,15 +1,19 @@ package area +import db.Database +import org.json.JSONObject +import org.junit.Ignore import org.junit.Test +import java.time.ZonedDateTime class AreaQueriesTest { + @Ignore @Test fun insert() { -// val queries = AreaQueries( -// BundledSQLiteDriver().open(":memory:").apply { execSQL(Database.CREATE_AREA_TABLE) }) -// val area = Area(id = 1, tags = JSONObject(), updatedAt = ZonedDateTime.now()) -// queries.insertOrReplace(area) -// assert(queries.selectById(area.id) == area) + val queries = AreaQueries(Database(":memory:")) + val area = Area(id = 1, tags = JSONObject(), updatedAt = ZonedDateTime.now()) + queries.insertOrReplace(listOf(area)) + assert(queries.selectById(area.id) == area) } } \ No newline at end of file