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 {
18
18
{{- if eq .Cmd ":many"}}
19
19
fun {{.MethodName}}({{.Arg.Args}}): List<{{.Ret.Type}}>
20
20
{{- end}}
21
+ {{- if eq .Cmd ":iter"}}
22
+ fun {{.MethodName}}(iter: ({{.Ret.Name}}: {{.Ret.Type}}) -> Unit{{ if .Arg.Args }}, {{ .Arg.Args}}{{end}})
23
+ {{- end}}
21
24
{{- if eq .Cmd ":exec"}}
22
25
fun {{.MethodName}}({{.Arg.Args}})
23
26
{{- end}}
Original file line number Diff line number Diff line change @@ -64,6 +64,27 @@ class QueriesImpl(private val conn: Connection) : Queries {
64
64
}
65
65
{{end}}
66
66
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
+
67
88
{{if eq .Cmd ":exec"}}
68
89
{{range .Comments}}//{{.}}
69
90
{{end}}
You can’t perform that action at this time.
0 commit comments