Skip to content
This repository has been archived by the owner on Oct 9, 2022. It is now read-only.

Latest commit

 

History

History
53 lines (38 loc) · 2.34 KB

database.rst

File metadata and controls

53 lines (38 loc) · 2.34 KB

Database

Overview

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.

Shoebox and State

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}"})

            }
        }
    }
}

Future Development

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.

Working Example

For a more complete example of using Shoebox for persistent storage see the to do demo.