mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
improve room database flow
This commit is contained in:
parent
6678a82578
commit
1196eb6cc5
3 changed files with 22 additions and 17 deletions
|
|
@ -1,26 +1,20 @@
|
|||
package com.geeksville.mesh.database
|
||||
|
||||
import android.app.Application
|
||||
import androidx.room.Room
|
||||
import com.geeksville.mesh.database.dao.PacketDao
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@InstallIn(SingletonComponent::class)
|
||||
@Module
|
||||
class DatabaseModule {
|
||||
@Provides
|
||||
fun provideDatabase(application: Application): MeshtasticDatabase {
|
||||
return Room.databaseBuilder(
|
||||
application.applicationContext,
|
||||
MeshtasticDatabase::class.java,
|
||||
"meshtastic_database"
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
@Singleton
|
||||
fun provideDatabase(app: Application): MeshtasticDatabase =
|
||||
MeshtasticDatabase.getDatabase(app)
|
||||
|
||||
@Provides
|
||||
fun providePacketDao(database: MeshtasticDatabase): PacketDao {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue