Skip to content

Commit 288238c

Browse files
bluestreak01claude
andcommitted
Use stdlib string functions and add connection cleanup
- Replace custom joinStrings/replaceFirst with strings.Join/strings.Replace - Add Close() method to processor for pgx connection cleanup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent db1ccef commit 288238c

File tree

2 files changed

+9
-22
lines changed
  • cmd

2 files changed

+9
-22
lines changed

cmd/tsbs_generate_queries/databases/questdb/common.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/url"
7+
"strings"
78
"time"
89

910
"github.com/questdb/tsbs/cmd/tsbs_generate_queries/uses/devops"
@@ -74,31 +75,11 @@ func substituteParams(sql string, params []interface{}) string {
7475
for j, s := range v {
7576
quoted[j] = fmt.Sprintf("'%s'", s)
7677
}
77-
replacement = fmt.Sprintf("(%s)", joinStrings(quoted, ", "))
78+
replacement = fmt.Sprintf("(%s)", strings.Join(quoted, ", "))
7879
default:
7980
replacement = fmt.Sprintf("%v", v)
8081
}
81-
result = replaceFirst(result, placeholder, replacement)
82-
}
83-
return result
84-
}
85-
86-
func replaceFirst(s, old, new string) string {
87-
for i := 0; i <= len(s)-len(old); i++ {
88-
if s[i:i+len(old)] == old {
89-
return s[:i] + new + s[i+len(old):]
90-
}
91-
}
92-
return s
93-
}
94-
95-
func joinStrings(strs []string, sep string) string {
96-
if len(strs) == 0 {
97-
return ""
98-
}
99-
result := strs[0]
100-
for i := 1; i < len(strs); i++ {
101-
result += sep + strs[i]
82+
result = strings.Replace(result, placeholder, replacement, 1)
10283
}
10384
return result
10485
}

cmd/tsbs_run_queries_questdb/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ func (p *processor) ProcessQuery(q query.Query, _ bool) ([]*query.Stat, error) {
138138
return []*query.Stat{stat}, nil
139139
}
140140

141+
func (p *processor) Close() {
142+
if p.conn != nil {
143+
p.conn.Close(p.ctx)
144+
}
145+
}
146+
141147
// processQueryPgx extracts SQL from HTTP query and runs it via native pgx v5
142148
// Supports parameterized queries with bind variables for better performance
143149
func (p *processor) processQueryPgx(hq *query.HTTP) (float64, error) {

0 commit comments

Comments
 (0)