github.com/yongjacky/phoenix-go-orm-builder@v0.3.5/cond_null.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 // IsNull defines IS NULL condition 10 type IsNull [1]string 11 12 var _ Cond = IsNull{""} 13 14 // WriteTo write SQL to Writer 15 func (isNull IsNull) WriteTo(w Writer) error { 16 _, err := fmt.Fprintf(w, "%s IS NULL", isNull[0]) 17 return err 18 } 19 20 // And implements And with other conditions 21 func (isNull IsNull) And(conds ...Cond) Cond { 22 return And(isNull, And(conds...)) 23 } 24 25 // Or implements Or with other conditions 26 func (isNull IsNull) Or(conds ...Cond) Cond { 27 return Or(isNull, Or(conds...)) 28 } 29 30 // IsValid tests if this condition is valid 31 func (isNull IsNull) IsValid() bool { 32 return len(isNull[0]) > 0 33 } 34 35 // NotNull defines NOT NULL condition 36 type NotNull [1]string 37 38 var _ Cond = NotNull{""} 39 40 // WriteTo write SQL to Writer 41 func (notNull NotNull) WriteTo(w Writer) error { 42 _, err := fmt.Fprintf(w, "%s IS NOT NULL", notNull[0]) 43 return err 44 } 45 46 // And implements And with other conditions 47 func (notNull NotNull) And(conds ...Cond) Cond { 48 return And(notNull, And(conds...)) 49 } 50 51 // Or implements Or with other conditions 52 func (notNull NotNull) Or(conds ...Cond) Cond { 53 return Or(notNull, Or(conds...)) 54 } 55 56 // IsValid tests if this condition is valid 57 func (notNull NotNull) IsValid() bool { 58 return len(notNull[0]) > 0 59 }