Skip to content

Commit

Permalink
Separate querying examples into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vnikolova committed Dec 4, 2024
1 parent ab782ee commit 1425603
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun main() {
runAliasExamples()
runCustomSelectExamples()
//runDeleteExamples()
//runQueryingExamples()
runQueryingExamples()
}
}

Expand Down Expand Up @@ -79,7 +79,7 @@ fun runDeleteExamples() {

fun runQueryingExamples() {
val queryingExamples = QueryingExamples()
queryingExamples.printResults()
queryingExamples.aggregateAndSort()
}

fun runAliasExamples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
*/
class QueryingExamples {

fun printResults() {
fun useWhereConditions() {
val allMoviesLike = StarWarsFilmsTable.selectAll()
.where { StarWarsFilmsTable.name like "The %" }
println(allMoviesLike.toList())
Expand Down Expand Up @@ -49,7 +49,9 @@ class QueryingExamples {
StarWarsFilmsTable.sequelId eq anyFrom(arrayOf(6, 4))
}
println(anyFromArray.toList())
}

fun aggregateAndSort() {
val count = StarWarsFilmsTable.selectAll()
.where {
StarWarsFilmsTable.sequelId eq 8
Expand All @@ -65,7 +67,9 @@ class QueryingExamples {
.select(StarWarsFilmsTable.sequelId.count(), StarWarsFilmsTable.director)
.groupBy(StarWarsFilmsTable.director)
println("Grouped films: $groupedFilms")
}

fun limitResults() {
// Take 2 films after the first one.
val limitedFilms = StarWarsFilmsTable
.selectAll()
Expand Down

0 comments on commit 1425603

Please sign in to comment.