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

     1  // Copyright 2016 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 "fmt"
     8  
     9  type expr struct {
    10  	sql  string
    11  	args []interface{}
    12  }
    13  
    14  var _ Cond = expr{}
    15  
    16  // Expr generate customerize SQL
    17  func Expr(sql string, args ...interface{}) Cond {
    18  	return expr{sql, args}
    19  }
    20  
    21  func (expr expr) OpWriteTo(op string, w Writer) error {
    22  	return expr.WriteTo(w)
    23  }
    24  
    25  func (expr expr) WriteTo(w Writer) error {
    26  	if _, err := fmt.Fprint(w, expr.sql); err != nil {
    27  		return err
    28  	}
    29  	w.Append(expr.args...)
    30  	return nil
    31  }
    32  
    33  func (expr expr) And(conds ...Cond) Cond {
    34  	return And(expr, And(conds...))
    35  }
    36  
    37  func (expr expr) Or(conds ...Cond) Cond {
    38  	return Or(expr, Or(conds...))
    39  }
    40  
    41  func (expr expr) IsValid() bool {
    42  	return len(expr.sql) > 0
    43  }