Skip to content

Commit

Permalink
Merge pull request #1089 from Aoang/chore/use-itn
Browse files Browse the repository at this point in the history
chore(internal): utilize methods from the internal package
  • Loading branch information
j2gg0s authored Dec 20, 2024
2 parents 014b142 + 95491d8 commit 3fe02f1
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 106 deletions.
8 changes: 4 additions & 4 deletions dialect/pgdialect/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func decodeIntSlice(src interface{}) ([]int, error) {
continue
}

n, err := strconv.Atoi(bytesToString(elem))
n, err := strconv.Atoi(internal.String(elem))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -520,7 +520,7 @@ func decodeInt64Slice(src interface{}) ([]int64, error) {
continue
}

n, err := strconv.ParseInt(bytesToString(elem), 10, 64)
n, err := strconv.ParseInt(internal.String(elem), 10, 64)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -569,7 +569,7 @@ func scanFloat64Slice(src interface{}) ([]float64, error) {
continue
}

n, err := strconv.ParseFloat(bytesToString(elem), 64)
n, err := strconv.ParseFloat(internal.String(elem), 64)
if err != nil {
return nil, err
}
Expand All @@ -585,7 +585,7 @@ func scanFloat64Slice(src interface{}) ([]float64, error) {
func toBytes(src interface{}) ([]byte, error) {
switch src := src.(type) {
case string:
return stringToBytes(src), nil
return internal.Bytes(src), nil
case []byte:
return src, nil
default:
Expand Down
11 changes: 0 additions & 11 deletions dialect/pgdialect/safe.go

This file was deleted.

18 changes: 0 additions & 18 deletions dialect/pgdialect/unsafe.go

This file was deleted.

10 changes: 6 additions & 4 deletions driver/pgdriver/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strconv"
"strings"
"time"

"github.com/uptrace/bun/internal"
)

const (
Expand Down Expand Up @@ -84,7 +86,7 @@ func readIntCol(rd *reader, n int, bitSize int) (interface{}, error) {
return 0, err
}

return strconv.ParseInt(bytesToString(tmp), 10, bitSize)
return strconv.ParseInt(internal.String(tmp), 10, bitSize)
}

func readFloatCol(rd *reader, n int, bitSize int) (interface{}, error) {
Expand All @@ -97,7 +99,7 @@ func readFloatCol(rd *reader, n int, bitSize int) (interface{}, error) {
return 0, err
}

return strconv.ParseFloat(bytesToString(tmp), bitSize)
return strconv.ParseFloat(internal.String(tmp), bitSize)
}

func readStringCol(rd *reader, n int) (interface{}, error) {
Expand All @@ -111,7 +113,7 @@ func readStringCol(rd *reader, n int) (interface{}, error) {
return nil, err
}

return bytesToString(b), nil
return internal.String(b), nil
}

func readBytesCol(rd *reader, n int) (interface{}, error) {
Expand Down Expand Up @@ -146,7 +148,7 @@ func readTimeCol(rd *reader, n int) (interface{}, error) {
return time.Time{}, err
}

tm, err := ParseTime(bytesToString(tmp))
tm, err := ParseTime(internal.String(tmp))
if err != nil {
return time.Time{}, err
}
Expand Down
4 changes: 3 additions & 1 deletion driver/pgdriver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"strconv"
"sync/atomic"
"time"

"github.com/uptrace/bun/internal"
)

func init() {
Expand Down Expand Up @@ -515,7 +517,7 @@ func parseResult(b []byte) (driver.RowsAffected, error) {
}

b = b[i+1 : len(b)-1]
affected, err := strconv.ParseUint(bytesToString(b), 10, 64)
affected, err := strconv.ParseUint(internal.String(b), 10, 64)
if err != nil {
return 0, nil
}
Expand Down
8 changes: 5 additions & 3 deletions driver/pgdriver/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strconv"
"time"
"unicode/utf8"

"github.com/uptrace/bun/internal"
)

func formatQueryArgs(query string, args []interface{}) (string, error) {
Expand Down Expand Up @@ -56,7 +58,7 @@ func formatQuery(query string, args []driver.NamedValue) (string, error) {
}
}

return bytesToString(dst), nil
return internal.String(dst), nil
}

func appendArg(b []byte, v interface{}) ([]byte, error) {
Expand Down Expand Up @@ -137,7 +139,7 @@ type parser struct {

func newParser(s string) *parser {
return &parser{
b: stringToBytes(s),
b: internal.Bytes(s),
}
}

Expand Down Expand Up @@ -166,7 +168,7 @@ func (p *parser) Number() (int, bool) {
p.i = end
b := p.b[start:end]

n, err := strconv.Atoi(bytesToString(b))
n, err := strconv.Atoi(internal.String(b))
if err != nil {
return 0, false
}
Expand Down
3 changes: 2 additions & 1 deletion driver/pgdriver/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"
"unicode/utf8"

"github.com/uptrace/bun/internal"
"mellium.im/sasl"
)

Expand Down Expand Up @@ -617,7 +618,7 @@ func (d *rowDescription) addName(name []byte) {

i := len(d.buf)
d.buf = append(d.buf, name...)
d.names = append(d.names, bytesToString(d.buf[i:]))
d.names = append(d.names, internal.String(d.buf[i:]))
}

func (d *rowDescription) addType(dataType int32) {
Expand Down
11 changes: 0 additions & 11 deletions driver/pgdriver/safe.go

This file was deleted.

21 changes: 0 additions & 21 deletions driver/pgdriver/unsafe.go

This file was deleted.

3 changes: 2 additions & 1 deletion extra/bunotel/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect"
"github.com/uptrace/bun/internal"
"github.com/uptrace/bun/schema"
"github.com/uptrace/opentelemetry-go-extra/otelsql"
)
Expand Down Expand Up @@ -169,7 +170,7 @@ func (h *QueryHook) eventQuery(event *bun.QueryEvent) string {
func unformattedQuery(event *bun.QueryEvent) string {
if event.IQuery != nil {
if b, err := event.IQuery.AppendQuery(schema.NewNopFormatter(), nil); err == nil {
return bytesToString(b)
return internal.String(b)
}
}
return string(event.QueryTemplate)
Expand Down
11 changes: 0 additions & 11 deletions extra/bunotel/safe.go

This file was deleted.

20 changes: 0 additions & 20 deletions extra/bunotel/unsafe.go

This file was deleted.

0 comments on commit 3fe02f1

Please sign in to comment.