Realization of the DAO Competition and the Database 💾
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
5389b060eb
commit
cb95747e65
@ -0,0 +1,31 @@
|
|||||||
|
package uca.iut.clermont.data
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import uca.iut.clermont.data.dao.CompetitionDao
|
||||||
|
import uca.iut.clermont.model.Competition
|
||||||
|
|
||||||
|
@Database(entities = arrayOf(Competition::class), version = 1)
|
||||||
|
abstract class BDD : RoomDatabase() {
|
||||||
|
|
||||||
|
abstract fun competitionDao(): CompetitionDao
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private var INSTANCE: BDD? = null
|
||||||
|
|
||||||
|
fun getInstance(context: Context) =
|
||||||
|
INSTANCE ?: synchronized(this) {
|
||||||
|
val db = Room.databaseBuilder(
|
||||||
|
context,
|
||||||
|
BDD::class.java,
|
||||||
|
"ScorItDB"
|
||||||
|
).build()
|
||||||
|
INSTANCE = db
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package uca.iut.clermont.data.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Delete
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.Query
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import uca.iut.clermont.model.Competition
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface CompetitionDao {
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
fun deleteCompetition(competition: Competition)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM competition")
|
||||||
|
fun getAllCompetitions(): Flow<List<Competition>>
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
fun insertCompetition(competition: Competition)
|
||||||
|
|
||||||
|
}
|
@ -1,11 +1,16 @@
|
|||||||
package uca.iut.clermont.model
|
package uca.iut.clermont.model
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = "competitions")
|
||||||
class Competition(
|
class Competition(
|
||||||
val id: Int,
|
@PrimaryKey val id: Int,
|
||||||
val name: String,
|
@ColumnInfo val name: String,
|
||||||
val code: String,
|
@ColumnInfo val code: String,
|
||||||
val type: String,
|
@ColumnInfo val type: String,
|
||||||
val emblem: String,
|
@ColumnInfo val emblem: String,
|
||||||
val currentSeason: Season,
|
@ColumnInfo val currentSeason: Season,
|
||||||
val area: Area
|
val area: Area
|
||||||
)
|
)
|
Loading…
Reference in new issue