You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.3 KiB
75 lines
1.3 KiB
8 years ago
|
// Copyright 2016 The Xorm Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
8 years ago
|
package builder
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
)
|
||
|
|
||
8 years ago
|
// Writer defines the interface
|
||
8 years ago
|
type Writer interface {
|
||
|
io.Writer
|
||
|
Append(...interface{})
|
||
|
}
|
||
|
|
||
8 years ago
|
var _ Writer = NewWriter()
|
||
|
|
||
|
// BytesWriter implments Writer and save SQL in bytes.Buffer
|
||
|
type BytesWriter struct {
|
||
6 years ago
|
writer *StringBuilder
|
||
8 years ago
|
args []interface{}
|
||
|
}
|
||
|
|
||
8 years ago
|
// NewWriter creates a new string writer
|
||
|
func NewWriter() *BytesWriter {
|
||
6 years ago
|
w := &BytesWriter{
|
||
|
writer: &StringBuilder{},
|
||
|
}
|
||
8 years ago
|
return w
|
||
|
}
|
||
|
|
||
8 years ago
|
// Write writes data to Writer
|
||
|
func (s *BytesWriter) Write(buf []byte) (int, error) {
|
||
8 years ago
|
return s.writer.Write(buf)
|
||
|
}
|
||
|
|
||
8 years ago
|
// Append appends args to Writer
|
||
|
func (s *BytesWriter) Append(args ...interface{}) {
|
||
8 years ago
|
s.args = append(s.args, args...)
|
||
|
}
|
||
|
|
||
8 years ago
|
// Cond defines an interface
|
||
8 years ago
|
type Cond interface {
|
||
|
WriteTo(Writer) error
|
||
|
And(...Cond) Cond
|
||
|
Or(...Cond) Cond
|
||
|
IsValid() bool
|
||
|
}
|
||
|
|
||
|
type condEmpty struct{}
|
||
|
|
||
|
var _ Cond = condEmpty{}
|
||
|
|
||
8 years ago
|
// NewCond creates an empty condition
|
||
8 years ago
|
func NewCond() Cond {
|
||
|
return condEmpty{}
|
||
|
}
|
||
|
|
||
|
func (condEmpty) WriteTo(w Writer) error {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (condEmpty) And(conds ...Cond) Cond {
|
||
|
return And(conds...)
|
||
|
}
|
||
|
|
||
|
func (condEmpty) Or(conds ...Cond) Cond {
|
||
|
return Or(conds...)
|
||
|
}
|
||
|
|
||
|
func (condEmpty) IsValid() bool {
|
||
|
return false
|
||
|
}
|