Merge pull request 'Realization of the DAO Competition and the Database 💾' (#10) from Data_Persistence into master
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #10master
commit
3e3fbe2dd0
@ -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
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "competitions")
|
||||
class Competition(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val code: String,
|
||||
val type: String,
|
||||
val emblem: String,
|
||||
val currentSeason: Season,
|
||||
@PrimaryKey val id: Int,
|
||||
@ColumnInfo val name: String,
|
||||
@ColumnInfo val code: String,
|
||||
@ColumnInfo val type: String,
|
||||
@ColumnInfo val emblem: String,
|
||||
@ColumnInfo val currentSeason: Season,
|
||||
val area: Area
|
||||
)
|
Loading…
Reference in new issue