database setup
This commit is contained in:
parent
004824636d
commit
f45f1cc77b
4 changed files with 88 additions and 1 deletions
|
|
@ -38,6 +38,9 @@ android {
|
|||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
ksp {
|
||||
arg("room.schemaLocation", "$projectDir/schemas")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
|||
43
DBTApp/app/schemas/de.cdaut.dbtapp.model.AppDatabase/1.json
Normal file
43
DBTApp/app/schemas/de.cdaut.dbtapp.model.AppDatabase/1.json
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "9293dc46eca03d297eae6183174db499",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "Skill",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`identifier` BLOB NOT NULL, `title` TEXT NOT NULL, `description` TEXT NOT NULL, PRIMARY KEY(`identifier`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "identifier",
|
||||
"columnName": "identifier",
|
||||
"affinity": "BLOB",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "description",
|
||||
"columnName": "description",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"identifier"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '9293dc46eca03d297eae6183174db499')"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -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,20 +1,37 @@
|
|||
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"
|
||||
)
|
||||
|
|
@ -22,3 +39,18 @@ class Skill(val title: String, val description: String) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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