Shoebox is a simple key-value store that supports the observer pattern, and is a sister project to Kweb. It supports a number of back-end storage engines including in-memory (userful for testing), and MapDB (the best for production use).
Kweb doesn't require you to use Shoebox. You're free to use any database, either directly, or via a database abstraction layer such as Exposed. Kotlin has a wide selection to choose from, as does Java.
The main benefit of using Shoebox is its integration with Kweb's state management.
We'll assume you've taken a minute or two to review Shoebox and get the general idea of how it's used.
This example shows how toVar can be used to convert a value in a Shoebox to a KVar:
fun main() {
data class User(val name : String, val email : String)
val users = Shoebox<User>()
users["aaa"] = User("Ian", "[email protected]")
Kweb(port = 16097) {
doc.body {
val user = toVar(users, "aaa")
ul {
li().text(user.map {"Name: ${it.name}"})
li().text(user.map {"Email: ${it.email}"})
}
}
}
}
In the future Shoebox will support back-end cloud services like AWS Pub/Sub Messaging and Dynamo DB, which would enable unlimited scalability. New storage backends can be added easily to Shoebox by implementing the Store interface.
For a more complete example of using Shoebox for persistent storage see the to do demo.