Last active
January 1, 2016 09:19
-
-
Save cheptsov/8124099 to your computer and use it in GitHub Desktop.
A type-safe DSL for NoSQL using Kotlin language (experiment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.nosql.* | |
object Cities : Table() { | |
val id = integer("id").id().generated() // GeneratedPKColumn<Int, Cities> | |
val name = varchar("name", 50) // Column<String, Cities> | |
val all = id + name // Template2<Cities, Int, String> Select template | |
val values = name // Column<String, Cities> | |
} | |
Cities insert { values("St. Petersburg") } | |
// INSERT INTO Cities (name) VALUES ('St. Petersburg') | |
for ((id, name) in Cities select { all }) { | |
println("$id: $name") | |
} | |
// SELECT Cities.id, Cities.name FROM Cities | |
Cities select { all } filter { name.eq("St. Petersburg") } forEach { id, name -> | |
println("$id: $name") | |
} | |
// SELECT Cities.id, Cities.name FROM Cities WHERE Cities.name = 'St. Petersburg' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment