Skip to content

Commit

Permalink
rename .Append to .AppendTo
Browse files Browse the repository at this point in the history
  • Loading branch information
mitranim committed Mar 27, 2023
1 parent adfeca5 commit b92a312
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 211 deletions.
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func Example_composition() {

## Changelog

### v0.7.0

Renamed method `.Append` in various types to `.AppendTo` for consistency with other libraries.

Renamed interface `Appender` to `AppenderTo`.

### v0.6.8

Added `LaxDict`: dictionary of named arguments similar to `Dict`, but without support for validating unused arguments.
Expand Down
4 changes: 2 additions & 2 deletions sqlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ parameters such as "$1", renumerating them as necessary.
This method is allowed to panic. Use `(*Bui).CatchExprs` to catch
expression-encoding panics and convert them to errors.
All `Expr` types in this package also implement `Appender` and `fmt.Stringer`.
All `Expr` types in this package also implement `AppenderTo` and `fmt.Stringer`.
*/
type Expr interface {
AppendExpr([]byte, []any) ([]byte, []any)
Expand All @@ -31,7 +31,7 @@ type ParamExpr interface {
Appends a text repesentation. Sometimes allows better efficiency than
`fmt.Stringer`. Implemented by all `Expr` types in this package.
*/
type Appender interface{ Append([]byte) []byte }
type AppenderTo interface{ AppendTo([]byte) []byte }

/*
Dictionary of arbitrary arguments, ordinal and/or named. Used as input to
Expand Down
32 changes: 16 additions & 16 deletions sqlb_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "database/sql/driver"
Intermediary tool for implementing SQL array encoding. Has the same behavior as
`CommaAppender`, but the text output is always enclosed in `{}`.
*/
type ArrayAppender[A Appender] []A
type ArrayAppender[A AppenderTo] []A

/*
Implement `fmt.Stringer`. Same as `CommaAppender.String`, but the output is
Expand All @@ -15,12 +15,12 @@ always enclosed in `{}`.
func (self ArrayAppender[_]) String() string { return AppenderString(&self) }

/*
Implement `Appender`. Same as `CommaAppender.Append`, but the output is always
Implement `AppenderTo`. Same as `CommaAppender.AppendTo`, but the output is always
enclosed in `{}`.
*/
func (self ArrayAppender[A]) Append(buf []byte) []byte {
func (self ArrayAppender[A]) AppendTo(buf []byte) []byte {
buf = append(buf, `{`...)
buf = CommaAppender[A](self).Append(buf)
buf = CommaAppender[A](self).AppendTo(buf)
buf = append(buf, `}`...)
return buf
}
Expand All @@ -31,23 +31,23 @@ func (self ArrayAppender[_]) Value() (driver.Value, error) { return self.Get(),

/*
Intermediary tool for implementing SQL array encoding. Combines multiple
arbitrary text encoders. On demand (on a call to `.Append` or `.String`),
arbitrary text encoders. On demand (on a call to `.AppendTo` or `.String`),
combines their text representations, separating them with a comma, while
skipping any empty representations. The output will never contain a dangling
leading comma, double comma, or leading trailing comma, unless they were
explicitly generated by the inner encoders. Compare `SliceCommaAppender`
which takes an arbitrary slice.
*/
type CommaAppender[A Appender] []A
type CommaAppender[A AppenderTo] []A

// Implement `fmt.Stringer` by calling `.Append`.
// Implement `fmt.Stringer` by calling `.AppendTo`.
func (self CommaAppender[_]) String() string { return AppenderString(&self) }

/*
Implement `Appender`. Appends comma-separated text representations of the inner
Implement `AppenderTo`. Appends comma-separated text representations of the inner
encoders to the output buffer, skipping any empty representations.
*/
func (self CommaAppender[_]) Append(buf []byte) []byte {
func (self CommaAppender[_]) AppendTo(buf []byte) []byte {
var found bool

for _, val := range self {
Expand All @@ -62,7 +62,7 @@ func (self CommaAppender[_]) Append(buf []byte) []byte {
/*
Intermediary tool for implementing SQL array encoding. The inner value must be
either nil, a slice/array, or a pointer to a slice/array, where each element
must implement `Appender`. When `.Append` or `.String` is called, this combines
must implement `AppenderTo`. When `.AppendTo` or `.String` is called, this combines
the text representations of the elements, separating them with a comma, while
skipping any empty representations. The output will never contain a dangling
leading comma, double comma, or leading trailing comma, unless they were
Expand All @@ -71,21 +71,21 @@ itself is a slice.
*/
type SliceCommaAppender [1]any

// Implement `fmt.Stringer` by calling `.Append`.
// Implement `fmt.Stringer` by calling `.AppendTo`.
func (self SliceCommaAppender) String() string { return AppenderString(&self) }

/*
Implement `Appender`. Appends comma-separated text representations of the inner
Implement `AppenderTo`. Appends comma-separated text representations of the inner
encoders to the output buffer, skipping any empty representations.
*/
func (self SliceCommaAppender) Append(buf []byte) []byte {
func (self SliceCommaAppender) AppendTo(buf []byte) []byte {
if self[0] == nil {
return buf
}

val, _ := self[0].(Appender)
val, _ := self[0].(AppenderTo)
if val != nil {
return val.Append(buf)
return val.AppendTo(buf)
}

src := valueOf(self[0])
Expand All @@ -105,7 +105,7 @@ func (self SliceCommaAppender) Append(buf []byte) []byte {
continue
}

val := iface.(Appender)
val := iface.(AppenderTo)
if (found && TryAppendWith(&buf, `,`, val)) || TryAppendWith(&buf, ``, val) {
found = true
}
Expand Down
2 changes: 1 addition & 1 deletion sqlb_bui.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ argument.
*/
func (self *Bui) OrphanParam(val OrdinalParam) {
self.Space()
self.Text = val.Append(self.Text)
self.Text = val.AppendTo(self.Text)
}

/*
Expand Down
2 changes: 1 addition & 1 deletion sqlb_err.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (self Err) format(typ string) string {

if typ != `` {
bui.Space()
bui.Text = Ident(typ).Append(bui.Text)
bui.Text = Ident(typ).AppendTo(bui.Text)
}

if self.While != `` {
Expand Down
Loading

0 comments on commit b92a312

Please sign in to comment.