File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff 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}}
Original file line number Diff line number Diff 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}}
You can’t perform that action at this time.
0 commit comments