2020-11-29 20:10:59 +00:00
|
|
|
{{- define "signature" -}}
|
|
|
|
Find_{{ .Suffix }}({{ ctxparam .Args }}) (
|
|
|
|
{{ param .Row }}, err error)
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{- define "invoke" -}}
|
|
|
|
Find_{{ .Suffix }}({{ ctxarg .Args }})
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{- define "body" }}
|
|
|
|
{{ embedplaceholders .Info }}
|
|
|
|
{{ embedsql .Info "__embed_stmt" }}
|
|
|
|
|
|
|
|
var __values []interface{}
|
|
|
|
{{ embedvalues .Args "__values" }}
|
|
|
|
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
|
2020-11-29 20:53:09 +00:00
|
|
|
for {
|
|
|
|
{{ arg .Row }}, err = func() ({{ param .Row }}, err error) {
|
|
|
|
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer __rows.Close()
|
|
|
|
|
|
|
|
if !__rows.Next() {
|
|
|
|
if err := __rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
{{ init .Row }}
|
|
|
|
err = __rows.Scan({{ addrof (flatten .Row) }})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if __rows.Next() {
|
|
|
|
return nil, errTooManyRows
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := __rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return {{ arg .Row }}, nil
|
|
|
|
}()
|
|
|
|
if err != nil {
|
|
|
|
if obj.shouldRetry(err) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err == errTooManyRows {
|
|
|
|
return nil, tooManyRows({{ printf "%q" .Suffix }})
|
|
|
|
}
|
|
|
|
return nil, obj.makeErr(err)
|
|
|
|
}
|
|
|
|
return {{ arg .Row }}, nil
|
|
|
|
}
|
2020-11-29 20:10:59 +00:00
|
|
|
{{ end -}}
|