Skip to content

Commit

Permalink
Change query.Replace() signature to output string
Browse files Browse the repository at this point in the history
  • Loading branch information
HnH committed Feb 20, 2024
1 parent f8405f1 commit 4cee236
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ type QuerySet map[string]Query
type Query string

// Replace part of a query
func (q Query) Replace(o, r string) Query {
func (q Query) Replace(o, r string) string {
if len(o) == 0 || len(r) == 0 {
return q
return string(q)
}

return Query(strings.Replace(string(q), o, r, 1))
return strings.Replace(string(q), o, r, 1)
}

func removeMultilineComments(q []byte) []byte {
Expand Down
4 changes: 2 additions & 2 deletions queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
)

func TestQuery(t *testing.T) {
var expected = Query("DELETE FROM `users` WHERE `user_id` IN (?,?,?);")
var expected = "DELETE FROM `users` WHERE `user_id` IN (?,?,?);"
if Query("DELETE FROM `users` WHERE `user_id` IN ({ids});").Replace("{ids}", In(3)) != expected {
t.Error("Invalid qry.In() result")
}
}

func TestReplaceEmpty(t *testing.T) {
var expected = Query("DELETE FROM `users` WHERE `user_id` IN ({ids});")
if expected.Replace("", "") != expected {
if expected.Replace("", "") != string(expected) {
t.Error("Expected empty qry.Replace() result")
}
}
Expand Down

0 comments on commit 4cee236

Please sign in to comment.