-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
155 additions
and
93 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
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
15 changes: 15 additions & 0 deletions
15
common/src/commonMain/kotlin/dev/johnoreilly/common/database/AppDatabase.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dev.johnoreilly.common.database | ||
|
||
import androidx.room.* | ||
import dev.johnoreilly.common.model.Network | ||
|
||
internal expect object AppDatabaseCtor : RoomDatabaseConstructor<AppDatabase> | ||
|
||
@Database(entities = [Network::class], version = 1) | ||
@ConstructedBy(AppDatabaseCtor::class) | ||
abstract class AppDatabase : RoomDatabase() { | ||
abstract fun bikeShareDao(): BikeShareDao | ||
} | ||
|
||
internal const val dbFileName = "bikeshare.db" | ||
|
17 changes: 17 additions & 0 deletions
17
common/src/commonMain/kotlin/dev/johnoreilly/common/database/BikeShareDao.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dev.johnoreilly.common.database | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import dev.johnoreilly.common.model.Network | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface BikeShareDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertNetworkList(networkList: List<Network>) | ||
|
||
@Query("SELECT * FROM Network") | ||
fun getNetworkListAsFlow(): Flow<List<Network>> | ||
} |
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
6 changes: 5 additions & 1 deletion
6
common/src/commonMain/kotlin/dev/johnoreilly/common/model/Network.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
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
14 changes: 14 additions & 0 deletions
14
common/src/jvmMain/kotlin/dev/johnoreilly/common/di/DesktopApplicationComponent.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,13 +1,27 @@ | ||
package dev.johnoreilly.common.di | ||
|
||
import androidx.room.Room | ||
import androidx.sqlite.driver.bundled.BundledSQLiteDriver | ||
import dev.johnoreilly.common.database.AppDatabase | ||
import dev.johnoreilly.common.database.dbFileName | ||
import io.ktor.client.engine.java.Java | ||
import me.tatarka.inject.annotations.Component | ||
import java.io.File | ||
|
||
@Component | ||
@Singleton | ||
abstract class DesktopApplicationComponent: SharedApplicationComponent { | ||
|
||
override fun getHttpClientEngine() = Java.create() | ||
|
||
override fun getRoomDatabase() = createRoomDatabase() | ||
|
||
companion object | ||
} | ||
|
||
fun createRoomDatabase(): AppDatabase { | ||
val dbFile = File(System.getProperty("java.io.tmpdir"), dbFileName) | ||
return Room.databaseBuilder<AppDatabase>(name = dbFile.absolutePath,) | ||
.setDriver(BundledSQLiteDriver()) | ||
.build() | ||
} |
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.