database setup
This commit is contained in:
parent
004824636d
commit
f45f1cc77b
4 changed files with 88 additions and 1 deletions
|
|
@ -0,0 +1,9 @@
|
|||
package de.cdaut.dbtapp.model
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(entities = [Skill::class], version = 1)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun skillDao() : SkillDao
|
||||
}
|
||||
|
|
@ -1,24 +1,56 @@
|
|||
package de.cdaut.dbtapp.model
|
||||
|
||||
class Skill(val title: String, val description: String) {
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Insert
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.Query
|
||||
import java.util.UUID
|
||||
|
||||
@Entity
|
||||
class Skill(
|
||||
@PrimaryKey val identifier: UUID,
|
||||
@ColumnInfo(name = "title") val title: String,
|
||||
@ColumnInfo(name = "description") val description: String
|
||||
) {
|
||||
|
||||
|
||||
companion object {
|
||||
fun mockSkills(): List<Skill> {
|
||||
return listOf(
|
||||
Skill(
|
||||
identifier = UUID.randomUUID(),
|
||||
title = "Test Hallo :3",
|
||||
description = "lorem ipsum dolor sid amnet consequetur blabla yada yada"
|
||||
),
|
||||
Skill(
|
||||
identifier = UUID.randomUUID(),
|
||||
title = "5-4-3-2-1",
|
||||
description = "Hier kurz beschreiben wie die Übung funktioniert. Ggf. mehrere Zeilen aber nicht super lang"
|
||||
),
|
||||
Skill(
|
||||
identifier = UUID.randomUUID(),
|
||||
title = "UwU UwU awawawa",
|
||||
description = "Just arf a little like the good fopsgirl you are :3"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Dao
|
||||
interface SkillDao {
|
||||
@Query("SELECT * FROM Skill")
|
||||
fun getAll(): List<Skill>
|
||||
|
||||
@Query("SELECT * FROM Skill WHERE title LIKE :title LIMIT 1")
|
||||
fun findByName(title: String): Skill
|
||||
|
||||
@Insert
|
||||
fun insertAll(vararg skills: Skill)
|
||||
|
||||
@Delete
|
||||
fun delete(skill: Skill)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue