mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Add: Room database (2/5 in replacing SQLite with Room)
This commit is contained in:
parent
da5b6108c8
commit
28a5481872
41
src/main/kotlin/com/looker/droidify/database/DatabaseX.kt
Normal file
41
src/main/kotlin/com/looker/droidify/database/DatabaseX.kt
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package com.looker.droidify.database
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
|
||||||
|
@Database(
|
||||||
|
entities = [
|
||||||
|
Repository::class,
|
||||||
|
Product::class,
|
||||||
|
Category::class,
|
||||||
|
Installed::class,
|
||||||
|
Lock::class
|
||||||
|
], version = 1
|
||||||
|
)
|
||||||
|
abstract class DatabaseX : RoomDatabase() {
|
||||||
|
// TODO add the DAOs for the tables
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Volatile
|
||||||
|
private var INSTANCE: DatabaseX? = null
|
||||||
|
|
||||||
|
fun getInstance(context: Context): DatabaseX {
|
||||||
|
synchronized(this) {
|
||||||
|
if (INSTANCE == null) {
|
||||||
|
INSTANCE = Room
|
||||||
|
.databaseBuilder(
|
||||||
|
context.applicationContext,
|
||||||
|
DatabaseX::class.java,
|
||||||
|
"main_database.db"
|
||||||
|
)
|
||||||
|
.fallbackToDestructiveMigration()
|
||||||
|
.allowMainThreadQueries()
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
return INSTANCE!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user