Skip to content

Commit 09994a9

Browse files
committed
Merge branch 'streaming' into unisea
2 parents 2c6a780 + 9533102 commit 09994a9

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

internal/tmpl/ktiface.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ interface Queries {
1818
{{- if eq .Cmd ":many"}}
1919
fun {{.MethodName}}({{.Arg.Args}}): List<{{.Ret.Type}}>
2020
{{- end}}
21+
{{- if eq .Cmd ":iter"}}
22+
fun {{.MethodName}}(iter: ({{.Ret.Name}}: {{.Ret.Type}}) -> Unit{{ if .Arg.Args }}, {{ .Arg.Args}}{{end}})
23+
{{- end}}
2124
{{- if eq .Cmd ":exec"}}
2225
fun {{.MethodName}}({{.Arg.Args}})
2326
{{- end}}

internal/tmpl/ktsql.tmpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,27 @@ class QueriesImpl(private val conn: Connection) : Queries {
6464
}
6565
{{end}}
6666

67+
{{if eq .Cmd ":iter"}}
68+
{{range .Comments}}//{{.}}
69+
{{end}}
70+
@Throws(SQLException::class)
71+
override fun {{.MethodName}}(iter: ({{.Ret.Name}}: {{.Ret.Type}}) -> Unit{{ if .Arg.Args }}, {{ .Arg.Args}}{{end}}) {
72+
return conn.prepareStatement({{.ConstantName}}).use { stmt ->
73+
{{.Arg.Bindings}}
74+
75+
val results = stmt.executeQuery()
76+
while (results.next()) {
77+
val ret = {{.Ret.ResultSet}}
78+
try {
79+
iter(ret)
80+
} catch (e: Exception) {
81+
throw SQLException("error calling iter function at row %d".format(results.row), e)
82+
}
83+
}
84+
}
85+
}
86+
{{end}}
87+
6788
{{if eq .Cmd ":exec"}}
6889
{{range .Comments}}//{{.}}
6990
{{end}}

0 commit comments

Comments
 (0)