2020-11-29 20:10:59 +00:00
|
|
|
{{- define "signature" -}}
|
|
|
|
Paged_{{ .Suffix }}({{ ctxparam .Args }},
|
|
|
|
limit int, start *{{ .Continuation.Type }}) (
|
|
|
|
rows {{ sliceof .Row }}, next *{{ .Continuation.Type }}, err error)
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{- define "invoke" -}}
|
|
|
|
Paged_{{ .Suffix }}({{ ctxarg .Args }}, limit, start)
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{- define "body" }}
|
|
|
|
{{ embedplaceholders .Info }}
|
|
|
|
{{ embedsql .Info "__embed_stmt" }}
|
|
|
|
{{ embedsql .FirstInfo "__embed_first_stmt" }}
|
|
|
|
|
|
|
|
var __values []interface{}
|
|
|
|
{{ embedvalues .Args "__values" }}
|
|
|
|
|
|
|
|
var __stmt string
|
|
|
|
if start != nil && start._set {
|
|
|
|
__values = append(__values, {{ .Continuation | rename "start" | flatten | slice 0 -1 | value | comma }}limit)
|
|
|
|
__stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
|
|
} else {
|
|
|
|
__values = append(__values, limit)
|
|
|
|
__stmt = __sqlbundle_Render(obj.dialect, __embed_first_stmt)
|
|
|
|
}
|
|
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
|
2020-11-29 20:53:09 +00:00
|
|
|
for {
|
|
|
|
rows, next, err = func() (rows {{ sliceof .Row }}, next *{{ .Continuation.Type }}, err error) {
|
|
|
|
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
defer __rows.Close()
|
|
|
|
|
|
|
|
{{ declare .Continuation }}
|
|
|
|
{{ .Continuation.Name }}._set = true
|
|
|
|
|
|
|
|
for __rows.Next() {
|
|
|
|
{{ initnew .Row }}
|
|
|
|
err = __rows.Scan({{ .Row | flatten | addrof | comma }}{{ .Continuation | flatten | slice 0 -1 | addrof }})
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
rows = append(rows, {{ arg .Row }})
|
|
|
|
next = {{ addrof .Continuation }}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := __rows.Err(); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2020-11-29 20:10:59 +00:00
|
|
|
|
2020-11-29 20:53:09 +00:00
|
|
|
return rows, next, nil
|
|
|
|
}()
|
|
|
|
if err != nil {
|
|
|
|
if obj.shouldRetry(err) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nil, nil, obj.makeErr(err)
|
|
|
|
}
|
|
|
|
return rows, next, nil
|
|
|
|
}
|
2020-11-29 20:10:59 +00:00
|
|
|
{{ end -}}
|