Code Poet
Code Poet

Reputation: 7995

Is it best to use two room databases in this situation?

I currently have a prepopulated database with a long list of words. I am using this database to also save some app data in a different table. In this scenario, would it be better to have two separate databases to avoid problems further down the line?

My database currently looks like this:

@Database(
    entities = [Word::class, SavedValues::class, SavedWords::class],
    version = 8,
    exportSchema = false
)
abstract class WordDatabase : RoomDatabase() {
    abstract fun wordDAO(): WordDao
    abstract fun savedValuesDao(): SavedValuesDao
}

and my module:

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {

        @Singleton
        @Provides
        fun provideDatabase(
            @ApplicationContext context: Context
        ) = Room.databaseBuilder(
            context,
            WordDatabase::class.java,
            "word_database"
        ).createFromAsset("database/wordlist.db").build()
    
        @Singleton
        @Provides
        fun provideDao(database: WordDatabase) = database.wordDAO()
    
    }

When I say "problems further down the line" I mean this specific problem that I explain here in this question.

Thanks for your help!

Upvotes: 0

Views: 148

Answers (1)

GuilhermeMagro
GuilhermeMagro

Reputation: 321

I don't think you need two databases, the problems might be because of wrong use of the queries or data management. Maybe just change your database name to something more generic, like AppDatabase, and make sure you are managing the data correctly.

Upvotes: 1

Related Questions