I have created 1 room database following best practices in kotlin. I want to create 2 table columns within 1 database. How can I stack tables within the database? Any advice is appreciated!
Something similar to this: https://gyazo.com/6327f163f463a4b19b59c5aece2136e3
Age database: https://gyazo.com/0074f2e4f002de9a3ad07ec593a826d4
Gender database: https://gyazo.com/c8b800b8f2f4fc6b43a9de2ddfdb1e7d
My age database:
@Database(entities = [Age::class], version = 1, exportSchema = false)
abstract class AgeDb : RoomDatabase() {
abstract fun AgeDao() : AgeDao
companion object {
@Volatile
private var INSTANCE : AgeDb? = null
fun getDatabase(context: Context) : AgeDb {
val tempInstance = INSTANCE
if (tempInstance != null) {
return tempInstance
}
synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
AgeDb::class.java,
"dropdown_age"
).build()
INSTANCE = instance
return instance
}
}
}
}
i see your code. actually,I can't understand why don't you use only one database? and create two table,even you can only create one table to save age attribute and gender attribute. so,maybe you would think about it, did you design the right databases and tabels
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.