Expand typed SQL DSL
This commit is contained in:
parent
72606e7818
commit
314c8fb207
17 changed files with 1082 additions and 498 deletions
24
examples/sql_expanded.gt
Normal file
24
examples/sql_expanded.gt
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
@table("accounts")
|
||||
data class AccountRow(@id var id: String, var customerId: String, var balance: Double)
|
||||
|
||||
@table("customers")
|
||||
data class CustomerRow(@id var id: String, var name: String)
|
||||
|
||||
data class AccountSummary(var customerId: String, var customerName: String, var total: Double, var entries: Long)
|
||||
|
||||
fun summaries(): GotlinSQLQuery = sql.from<AccountRow>()
|
||||
.alias("account")
|
||||
.leftJoin<CustomerRow>("customer") { account, customer -> account.customerId == customer.id }
|
||||
.select { account, customer -> AccountSummary(account.customerId, customer.name, sum(account.balance), count()) }
|
||||
.groupBy { account, customer -> listOf(account.customerId, customer.name) }
|
||||
.offset(20)
|
||||
.build()
|
||||
|
||||
fun bulk(rows: List<AccountRow>): GotlinSQLQuery = sql.insertAll<AccountRow>(rows).build()
|
||||
|
||||
fun main() {
|
||||
println(summaries().sql)
|
||||
println(bulk(listOf(AccountRow("a-1", "c-1", 10.0))).sql)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue