Prep inMemory database

This commit is contained in:
Kgothatso Ngako
2026-03-31 23:37:39 +02:00
parent 16b278556c
commit 21230cf365
7 changed files with 33 additions and 1 deletions

View File

@@ -15,4 +15,10 @@ actual object PlatformDatabaseBuilder {
name = dbFile.absolutePath
)
}
actual fun getInMemoryDatabaseBuilder(platform: PlatformContext): RoomDatabase.Builder<AuxDatabase> {
return Room.inMemoryDatabaseBuilder(
context = platform.applicationContext
)
}
}

View File

@@ -9,6 +9,8 @@ import kotlinx.coroutines.IO
expect object PlatformDatabaseBuilder {
fun getDatabaseBuilder(platformContext: PlatformContext): RoomDatabase.Builder<AuxDatabase>
fun getInMemoryDatabaseBuilder(platform: PlatformContext): RoomDatabase.Builder<AuxDatabase>
}
fun getRoomDatabase(

View File

@@ -4,6 +4,7 @@ import ac.aux.compose.AuxGlobal
import ac.aux.compose.database.AuxDatabaseConstructor
import ac.aux.compose.database.builder.PlatformDatabaseBuilder
import ac.aux.compose.database.builder.getRoomDatabase
import androidx.room.Room
class DatabaseManager(
auxGlobal: AuxGlobal
@@ -15,4 +16,17 @@ class DatabaseManager(
)
)
}
/**
* Dynamic data like user feeds and the likes will be in a in-memory db.
*
* We may also decide to just use the normal DB and manage what's saved better...
*/
val inMemoryAuxDatabase by lazy {
getRoomDatabase(
PlatformDatabaseBuilder.getInMemoryDatabaseBuilder(
auxGlobal.platformContext
)
)
}
}

View File

@@ -127,7 +127,6 @@ fun FeedScreen(
horizontalAlignment = Alignment.CenterHorizontally
) {
stickyHeader {
Surface() {
Row(
modifier = Modifier.fillMaxWidth().padding(10.dp)

View File

@@ -68,6 +68,9 @@ fun AuxNavHost(
val nostrRepository = DatabaseNostrRepository(
database = databaseManager.auxDatabase
)
val inMemoryNostrRepository = DatabaseNostrRepository(
database = databaseManager.inMemoryAuxDatabase
)
val exceptionHandler =
CoroutineExceptionHandler { _, throwable ->

View File

@@ -29,4 +29,8 @@ actual object PlatformDatabaseBuilder {
return requireNotNull(documentDirectory?.path)
}
actual fun getInMemoryDatabaseBuilder(platform: PlatformContext): RoomDatabase.Builder<AuxDatabase> {
return Room.inMemoryDatabaseBuilder()
}
}

View File

@@ -13,4 +13,8 @@ actual object PlatformDatabaseBuilder {
name = dbFile.absolutePath,
)
}
actual fun getInMemoryDatabaseBuilder(platform: PlatformContext): RoomDatabase.Builder<AuxDatabase> {
return Room.inMemoryDatabaseBuilder()
}
}