parent
e69cf0ca8d
commit
625822766a
@ -0,0 +1,14 @@
|
||||
package iut.android.pierrepierre.model.DB
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import iut.android.pierrepierre.model.Class.User
|
||||
import iut.android.pierrepierre.model.DB.DAO.UserDAO
|
||||
import iut.android.pierrepierre.model.DB.Entity.UserEntity
|
||||
|
||||
//@Database(entities = arrayOf(UserEntity::class), version = 1)
|
||||
//abstract class BDD : RoomDatabase(){
|
||||
// abstract fun daoUser() : UserDAO
|
||||
//}
|
||||
|
||||
//FIXME useless car "abstract fun daoUser() : UserDAO" definis dans room
|
@ -0,0 +1,29 @@
|
||||
package iut.android.pierrepierre.model.DB.DAO
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import iut.android.pierrepierre.model.DB.Entity.UserEntity
|
||||
|
||||
@Dao
|
||||
interface UserDAO {
|
||||
@Insert
|
||||
fun insererUser(u : UserEntity)
|
||||
|
||||
@Delete
|
||||
fun DeleteUser(u : UserEntity)
|
||||
|
||||
|
||||
@Query("SELECT * FROM user WHERE user.id = :id")
|
||||
fun getUserById(id: String): UserEntity?
|
||||
|
||||
@Query("SELECT score FROM user ")
|
||||
fun getUserScore()//liste des scores
|
||||
|
||||
@Query("SELECT nbMiss FROM user ")
|
||||
fun getUserMiss()//liste des scores
|
||||
|
||||
@Query("SELECT max(score) FROM user ")
|
||||
fun getUserBestScore()//list des scores
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package iut.android.pierrepierre.model.DB.Entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import iut.android.pierrepierre.model.Class.User
|
||||
import java.util.*
|
||||
|
||||
|
||||
@Entity(tableName = "user")
|
||||
class UserEntity(
|
||||
@PrimaryKey val id: String = UUID.randomUUID().toString(),
|
||||
val score: Int,
|
||||
val nbMiss: Int
|
||||
)
|
@ -0,0 +1,30 @@
|
||||
package iut.android.pierrepierre.model.DB
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import iut.android.pierrepierre.model.DB.DAO.UserDAO
|
||||
import iut.android.pierrepierre.model.DB.Entity.UserEntity
|
||||
|
||||
@Database(entities = [UserEntity::class], version = 1)
|
||||
abstract class RoomDB : RoomDatabase() {
|
||||
|
||||
abstract fun userDao(): UserDAO //remplace BDD.kt
|
||||
|
||||
companion object {
|
||||
private var INSTANCE: RoomDB? = null
|
||||
|
||||
fun getDatabase(context: Context) {
|
||||
INSTANCE ?: synchronized(this) {
|
||||
val instance = Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
RoomDB::class.java,
|
||||
"MyDataBase"
|
||||
).build()
|
||||
INSTANCE = instance
|
||||
instance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue