Add simple Dao to persistently store key, value pairs

This commit is contained in:
kageru 2019-07-18 18:55:39 +02:00
parent 7efeb9bace
commit 74c2f643f9
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
2 changed files with 18 additions and 0 deletions

View File

@ -37,6 +37,7 @@ dependencies {
implementation("com.moandjiezana.toml:toml4j:0.7.2")
implementation(kotlin("stdlib-jdk8"))
implementation("org.javacord:javacord:3.0.4")
implementation("org.mapdb:mapdb:3.0.7")
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.3.2")
testImplementation("io.mockk:mockk:1.9.3")

View File

@ -0,0 +1,17 @@
package moe.kageru.kagebot.persistence
import org.mapdb.DBMaker
import org.mapdb.Serializer
object Dao {
private val db = DBMaker.fileDB("kagebot.db").fileMmapEnable().closeOnJvmShutdown().make()
private val strings = db.hashMap("main", Serializer.STRING, Serializer.STRING).createOrOpen()
fun store(key: String, value: String) {
strings[key] = value
}
fun get(key: String): String? {
return strings[key]
}
}