writer.go 803 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package builder
  5. import (
  6. "io"
  7. "strings"
  8. )
  9. // Writer defines the interface
  10. type Writer interface {
  11. io.Writer
  12. Append(...interface{})
  13. }
  14. var _ Writer = NewWriter()
  15. // BytesWriter implments Writer and save SQL in bytes.Buffer
  16. type BytesWriter struct {
  17. *strings.Builder
  18. args []interface{}
  19. }
  20. // NewWriter creates a new string writer
  21. func NewWriter() *BytesWriter {
  22. w := &BytesWriter{
  23. Builder: &strings.Builder{},
  24. }
  25. return w
  26. }
  27. // Append appends args to Writer
  28. func (w *BytesWriter) Append(args ...interface{}) {
  29. w.args = append(w.args, args...)
  30. }
  31. // Args returns args
  32. func (w *BytesWriter) Args() []interface{} {
  33. return w.args
  34. }