github.com/yongjacky/phoenix-go-orm-builder@v0.3.5/writer.go (about)

     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  
     5  package builder
     6  
     7  import (
     8  	"io"
     9  	"strings"
    10  )
    11  
    12  // Writer defines the interface
    13  type Writer interface {
    14  	io.Writer
    15  	Append(...interface{})
    16  }
    17  
    18  var _ Writer = NewWriter()
    19  
    20  // BytesWriter implments Writer and save SQL in bytes.Buffer
    21  type BytesWriter struct {
    22  	*strings.Builder
    23  	args []interface{}
    24  }
    25  
    26  // NewWriter creates a new string writer
    27  func NewWriter() *BytesWriter {
    28  	w := &BytesWriter{
    29  		Builder: &strings.Builder{},
    30  	}
    31  	return w
    32  }
    33  
    34  // Append appends args to Writer
    35  func (w *BytesWriter) Append(args ...interface{}) {
    36  	w.args = append(w.args, args...)
    37  }
    38  
    39  // Args returns args
    40  func (w *BytesWriter) Args() []interface{} {
    41  	return w.args
    42  }