bd23d12bb9
Change-Id: Ia30fbba55c926892702fa96fb9dd01b75347d351
65 lines
1.7 KiB
Cheetah
65 lines
1.7 KiB
Cheetah
{{- 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...)
|
|
|
|
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
|
|
}
|
|
|
|
return rows, next, nil
|
|
}()
|
|
if err != nil {
|
|
if obj.shouldRetry(err) {
|
|
continue
|
|
}
|
|
return nil, nil, obj.makeErr(err)
|
|
}
|
|
return rows, next, nil
|
|
}
|
|
{{ end -}}
|