-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Realm to Room and up Kotlin to 2.0.20-beta02 (#245)
* Add Room to replace Realm * Remove Realm and update Kotlin
- Loading branch information
Showing
23 changed files
with
232 additions
and
157 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
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
11 changes: 0 additions & 11 deletions
11
...Main/kotlin/repository/model/DayCoffee.kt → ...in/kotlin/repository/model/DbDayCoffee.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,18 +1,7 @@ | ||
@file:Suppress("MatchingDeclarationName") | ||
|
||
package repository.model | ||
|
||
import ru.beryukhov.repository.SqlDayCoffee | ||
|
||
data class DbDayCoffee(val date: String, val coffeeName: String, val count: Int) | ||
|
||
internal fun DbDayCoffee.toRealm(): SqlDayCoffee { | ||
val dc = this | ||
return SqlDayCoffee( | ||
date = dc.date, | ||
coffeeName = dc.coffeeName, | ||
count = dc.count.toLong(), | ||
) | ||
} | ||
|
||
internal fun SqlDayCoffee.toDb() = DbDayCoffee(date = date, coffeeName = coffeeName, count = count.toInt()) |
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,49 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "1c0cceb170206d2746a2cd0a0cc3af34", | ||
"entities": [ | ||
{ | ||
"tableName": "DayCoffee", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `date` TEXT NOT NULL, `coffeeName` TEXT NOT NULL, `count` INTEGER NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "date", | ||
"columnName": "date", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "coffeeName", | ||
"columnName": "coffeeName", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "count", | ||
"columnName": "count", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": true, | ||
"columnNames": [ | ||
"id" | ||
] | ||
} | ||
} | ||
], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '1c0cceb170206d2746a2cd0a0cc3af34')" | ||
] | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
repository/src/androidMain/kotlin/repository/room/AppDatabase.android.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,28 @@ | ||
package repository.room | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import androidx.sqlite.driver.bundled.BundledSQLiteDriver | ||
import kotlinx.coroutines.Dispatchers | ||
import org.koin.dsl.module | ||
|
||
actual fun roomModule() = module { | ||
single<AppDatabase> { getDatabase(get()) } | ||
} | ||
|
||
fun getDatabaseBuilder(ctx: Context): RoomDatabase.Builder<AppDatabase> { | ||
val appContext = ctx.applicationContext | ||
val dbFile = appContext.getDatabasePath("my_room.db") | ||
return Room.databaseBuilder<AppDatabase>( | ||
context = appContext, | ||
name = dbFile.absolutePath | ||
) | ||
|
||
.setDriver(BundledSQLiteDriver()) | ||
.setQueryCoroutineContext(Dispatchers.IO) | ||
} | ||
|
||
fun getDatabase(ctx: Context): AppDatabase { | ||
return getDatabaseBuilder(ctx).build() | ||
} |
12 changes: 0 additions & 12 deletions
12
repository/src/androidUnitTest/kotlin/AndroidGreetingTest.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.