Created
December 27, 2013 12:42
-
-
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
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.* | |
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