Skip to content

Commit

Permalink
fix: enforce timeout for copyFrom
Browse files Browse the repository at this point in the history
Stumble committed Jul 11, 2024
1 parent 95f14a4 commit 1811445
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/codegen/golang/imports.go
Original file line number Diff line number Diff line change
@@ -437,6 +437,7 @@ func (i *importer) copyfromImports() fileImports {
})

std["context"] = struct{}{}
std["time"] = struct{}{}
if i.Settings.Go.SqlDriver == SQLDriverGoSQLDriverMySQL {
std["io"] = struct{}{}
std["fmt"] = struct{}{}
7 changes: 7 additions & 0 deletions internal/codegen/golang/templates/wpgx/copyfromCopy.tmpl
Original file line number Diff line number Diff line change
@@ -38,10 +38,17 @@ func (r iteratorFor{{.MethodName}}) Err() error {
{{range .Comments}}//{{.}}
{{end -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.SlicePair}}) (int64, error) {
{{- if gt .Option.Timeout.Milliseconds 0 }}
ctx, cancel := context.WithTimeout(ctx, time.Millisecond * {{.Option.Timeout.Milliseconds}})
defer cancel()
{{- end}}
q.db.CountIntent("{{.UniqueLabel}}")
return q.db.WCopyFrom(ctx, "{{.UniqueLabel}}", {{.TableIdentifierAsGoSlice}}, {{.Arg.ColumnNamesAsGoSlice}}, &iteratorFor{{.MethodName}}{rows: {{.Arg.Name}}})
}

// eliminate unused error
var _ = time.Now()

{{end}}
{{end}}
{{end}}

0 comments on commit 1811445

Please sign in to comment.