Skip to content

Commit

Permalink
codegen: wpgx use CountIntent for cache hit rate stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Stumble committed Aug 30, 2023
1 parent 5fa426a commit 610efea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/codegen/golang/templates/wpgx/copyfromCopy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (r iteratorFor{{.MethodName}}) Err() error {
{{range .Comments}}//{{.}}
{{end -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.SlicePair}}) (int64, error) {
q.db.CountIntent("{{.UniqueLabel}}")
return q.db.WCopyFrom(ctx, "{{.UniqueLabel}}", {{.TableIdentifierAsGoSlice}}, {{.Arg.ColumnNamesAsGoSlice}}, &iteratorFor{{.MethodName}}{rows: {{.Arg.Name}}})
}

Expand Down
5 changes: 5 additions & 0 deletions internal/codegen/golang/templates/wpgx/queryCode.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type {{.Ret.Type}} struct { {{- range .Ret.Struct.Fields}}
{{range .Comments}}//{{.}}
{{end -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) (*{{.Ret.Type}}, error) {
q.db.CountIntent("{{.UniqueLabel}}")
{{- if eq .Option.Cache.Milliseconds 0}}
row := q.db.WQueryRow(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}})
var {{.Ret.Name}} *{{.Ret.Type}} = new({{.Ret.Type}})
Expand Down Expand Up @@ -98,6 +99,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida
{{range .Comments}}//{{.}}
{{end -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) ([]{{.Ret.Type}}, error) {
q.db.CountIntent("{{.UniqueLabel}}")
{{- if eq .Option.Cache.Milliseconds 0}}
rows, err := q.db.WQuery(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}})
if err != nil {
Expand Down Expand Up @@ -177,6 +179,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida
{{range .Comments}}//{{.}}
{{end -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) error {
q.db.CountIntent("{{.UniqueLabel}}")
_, err := q.db.WExec(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}})
if err != nil {
return err
Expand Down Expand Up @@ -211,6 +214,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida
{{range .Comments}}//{{.}}
{{end -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) (int64, error) {
q.db.CountIntent("{{.UniqueLabel}}")
result, err := q.db.WExec(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}})
if err != nil {
return 0, err
Expand Down Expand Up @@ -245,6 +249,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida
{{range .Comments}}//{{.}}
{{end -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) (pgconn.CommandTag, error) {
q.db.CountIntent("{{.UniqueLabel}}")
rv, err := q.db.WExec(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}})
if err != nil {
return rv, err
Expand Down

0 comments on commit 610efea

Please sign in to comment.