-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate room to sqldelight for multiplatform database (#455)
BREAKING CHANGE: renamed database to `musicsearch.db`, changed some order, default values, and constraints
- Loading branch information
David Ly
committed
Oct 1, 2023
1 parent
a7b66a9
commit 8485f42
Showing
505 changed files
with
8,910 additions
and
38,840 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ly.david.mbjc | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.core.context.startKoin | ||
import org.koin.core.context.stopKoin | ||
|
||
class KoinTestRule : TestWatcher() { | ||
override fun starting(description: Description) { | ||
startKoin { | ||
androidContext(InstrumentationRegistry.getInstrumentation().targetContext.applicationContext) | ||
modules(testAndroidAppModule) | ||
} | ||
} | ||
|
||
override fun finished(description: Description) { | ||
stopKoin() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
app/src/androidTest/java/ly/david/mbjc/MusicSearchRoomDatabaseTestRule.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,5 @@ | ||
package ly.david.mbjc | ||
|
||
import android.app.Application | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.core.context.startKoin | ||
import org.koin.core.context.stopKoin | ||
|
||
class TestApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
startKoin { | ||
androidContext(this@TestApplication) | ||
modules(testAndroidAppModule) | ||
} | ||
} | ||
|
||
override fun onTerminate() { | ||
super.onTerminate() | ||
stopKoin() | ||
} | ||
} | ||
class TestApplication : Application() |
23 changes: 7 additions & 16 deletions
23
app/src/androidTest/java/ly/david/mbjc/di/TestCoroutinesDispatchersModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,17 @@ | ||
package ly.david.mbjc.di | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.TestDispatcher | ||
import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import ly.david.data.di.coroutines.MusicSearchDispatchers | ||
import org.koin.core.qualifier.named | ||
import ly.david.data.core.CoroutineDispatchers | ||
import org.koin.dsl.module | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
val testDispatcherModule = module { | ||
single { | ||
UnconfinedTestDispatcher() | ||
} | ||
} | ||
|
||
val testCoroutineDispatchersModule = module { | ||
includes(testDispatcherModule) | ||
factory<CoroutineDispatcher>(named(MusicSearchDispatchers.Default)) { | ||
get<TestDispatcher>() | ||
} | ||
factory<CoroutineDispatcher>(named(MusicSearchDispatchers.IO)) { | ||
get<TestDispatcher>() | ||
factory { | ||
val testDispatcher = UnconfinedTestDispatcher() | ||
CoroutineDispatchers( | ||
default = testDispatcher, | ||
io = testDispatcher, | ||
) | ||
} | ||
} |
30 changes: 17 additions & 13 deletions
30
app/src/androidTest/java/ly/david/mbjc/di/TestDatabaseModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
package ly.david.mbjc.di | ||
|
||
import androidx.room.Room | ||
import ly.david.data.room.MusicSearchDatabase | ||
import ly.david.data.room.MusicSearchRoomDatabase | ||
import org.koin.dsl.binds | ||
import androidx.sqlite.db.SupportSQLiteDatabase | ||
import app.cash.sqldelight.db.SqlDriver | ||
import app.cash.sqldelight.driver.android.AndroidSqliteDriver | ||
import ly.david.musicsearch.data.database.Database | ||
import org.koin.dsl.module | ||
|
||
// TODO: dupe | ||
val testDatabaseModule = module { | ||
single { | ||
Room.inMemoryDatabaseBuilder( | ||
get(), | ||
MusicSearchRoomDatabase::class.java | ||
val testDatabaseDriverModule = module { | ||
single<SqlDriver> { | ||
AndroidSqliteDriver( | ||
schema = Database.Schema, | ||
context = get(), | ||
name = null, | ||
callback = object : AndroidSqliteDriver.Callback(Database.Schema) { | ||
override fun onOpen(db: SupportSQLiteDatabase) { | ||
super.onConfigure(db) | ||
db.setForeignKeyConstraintsEnabled(true) | ||
} | ||
} | ||
) | ||
.allowMainThreadQueries() | ||
.build() | ||
} binds arrayOf(MusicSearchDatabase::class, MusicSearchRoomDatabase::class) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.