Skip to content

Instantly share code, notes, and snippets.

@cheptsov
Created December 27, 2013 12:42
Show Gist options
  • Save cheptsov/8146503 to your computer and use it in GitHub Desktop.
Save cheptsov/8146503 to your computer and use it in GitHub Desktop.
Access Amazon DynamoDB using the type-safe Kotlin DSL for NoSQL databases. For more details: https://github.com/cheptsov/Exposed/tree/NoSQL
import kotlin.nosql.*
import kotlin.nosql.dynamodb.*
object Users : Table() {
val id = string("id", length = 10).id() // PKColumn<String, Users>
val name = string("name", length = 50) // Column<String, Users>
val requiredCityId = integer("required_city_id") // Column<Int, Users>
val optionalCityId = integer("optional_city_id").nullable() // Column<Int?, Users>
val all = id + name + requiredCityId + optionalCityId // Template4<Users, String, Int, Int?>
}
object Cities : Table() {
val id = integer("id").id() // PKColumn<Int, Cities>
val name = string("name", 50) // Column<String, Cities>
val all = id + name // Template2<Cities, Int, String>
}
fun main(args: Array<String>) {
var db = DynamoDB(accessKey = "...", secretKey = "...")
db {
Cities columns { all } insert { values(1, "St. Petersburg") }
for ((id, name) in Cities columns { all }) {
println("$id: $name")
}
Cities columns { all } filter { name eq "St. Petersburg" } forEach { id, name ->
println("$id: $name")
}
Users columns { name + requiredCityId } forEach { userName, requiredCityId ->
val cityName = Cities columns { name } find { id eq requiredCityId }
println("${userName}'s required city is $cityName")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment