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
object Users : Table() { | |
val id = varchar("id", length = 10).id() // PKColumn<String, Users> | |
val name = varchar("name", length = 50) // Column<String, Users> | |
val requiredCityId = integer("required_city_id").references(Cities.id) // FKColumn<Int, Users> | |
val optionalCityId = integer("optional_city_id").references(Cities.id).optional() // FKOptionColumn<Int, Users> | |
val all = id + name + requiredCityId + optionalCityId // Template4<Users, String, Int, Int?> Select template | |
val values = id + name + requiredCityId + optionalCityId // Template4<Users, String, Int, Int?> Insert template | |
} |
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
(Users.name + Users.cityId * Cities.name).filter { Users.id.equals("andrey") } forEach { | |
val (userName, cityName) = it | |
println("$userName lives in $cityName") | |
} |
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
object Users : Table() { | |
val id = varchar("id", ColumnType.PRIMARY_KEY, length = 10) // PKColumn<String> | |
val name = varchar("name", length = 50) // Column<String> | |
val cityId = integer("city_id", ColumnType.NULLABLE, references = Cities.id) // Column<Int?> | |
val all = id + name + cityId // Column3<String, String, Int?> | |
} | |
object Cities : Table() { | |
val id = integer("id", ColumnType.PRIMARY_KEY, autoIncrement = true) // PKColumn<Int> |
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
object Cities : Table() { | |
val id = id("id", autoIncrement = true) | |
val name = varchar("name", 50) | |
val all = id + name | |
} | |
select (Cities.all) forEach { | |
val (id, name) = it | |
println("$id: $name") |
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
select (Cities.name, сount(Users.id)) from Cities join Users groupBy Cities.name forEach { | |
val (cityName, userCount) = it | |
if (userCount > 0) { | |
println("$userCount user(s) live(s) in $cityName") | |
} else { | |
println("Nobody lives in $cityName") | |
} | |
} |
NewerOlder