mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 10:56:54 -04:00
add base room implementation
This commit is contained in:
16
base/src/main/java/com/hako/base/di/BaseModules.kt
Normal file
16
base/src/main/java/com/hako/base/di/BaseModules.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.hako.base.di
|
||||
|
||||
import androidx.room.Room
|
||||
import com.hako.base.BuildConfig
|
||||
import com.hako.base.room.BaseDatabase
|
||||
import org.koin.dsl.module
|
||||
|
||||
val baseModule = module {
|
||||
|
||||
// Room database
|
||||
single { Room.databaseBuilder(get(), BaseDatabase::class.java, BuildConfig.DB_NAME).build() }
|
||||
factory { get<BaseDatabase>().userDao() }
|
||||
factory { get<BaseDatabase>().albumDao() }
|
||||
factory { get<BaseDatabase>().photoDao() }
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import com.hako.base.room.entities.PhotoEntity
|
||||
import com.hako.base.room.entities.UserEntity
|
||||
|
||||
@Database(entities = [UserEntity::class, AlbumEntity::class, PhotoEntity::class], version = 1, exportSchema = false)
|
||||
abstract class Database : RoomDatabase() {
|
||||
abstract class BaseDatabase : RoomDatabase() {
|
||||
abstract fun userDao(): UserDao
|
||||
abstract fun albumDao(): AlbumDao
|
||||
abstract fun photoDao(): PhotoDao
|
||||
@@ -19,7 +19,7 @@ interface AlbumDao {
|
||||
val all: List<AlbumEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${AlbumEntity.TABLE_NAME}")
|
||||
fun count(page: Int): Int
|
||||
fun count(): Int
|
||||
|
||||
@Query("DELETE FROM ${AlbumEntity.TABLE_NAME}")
|
||||
fun nukeDatabase()
|
||||
|
||||
@@ -19,7 +19,7 @@ interface PhotoDao {
|
||||
val all: List<PhotoEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${PhotoEntity.TABLE_NAME}")
|
||||
fun count(page: Int): Int
|
||||
fun count(): Int
|
||||
|
||||
@Query("DELETE FROM ${PhotoEntity.TABLE_NAME}")
|
||||
fun nukeDatabase()
|
||||
|
||||
@@ -19,7 +19,7 @@ interface UserDao {
|
||||
val all: List<UserEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${UserEntity.TABLE_NAME}")
|
||||
fun count(page: Int): Int
|
||||
fun count(): Int
|
||||
|
||||
@Query("DELETE FROM ${UserEntity.TABLE_NAME}")
|
||||
fun nukeDatabase()
|
||||
|
||||
Reference in New Issue
Block a user