github.com/gogf/gf/v2@v2.7.4/database/gdb/gdb_model_builder_whereor_prefix.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gdb 8 9 // WhereOrPrefix performs as WhereOr, but it adds prefix to each field in where statement. 10 // Eg: 11 // WhereOrPrefix("order", "status", "paid") => WHERE xxx OR (`order`.`status`='paid') 12 // WhereOrPrefix("order", struct{Status:"paid", "channel":"bank"}) => WHERE xxx OR (`order`.`status`='paid' AND `order`.`channel`='bank') 13 func (b *WhereBuilder) WhereOrPrefix(prefix string, where interface{}, args ...interface{}) *WhereBuilder { 14 where, args = b.convertWhereBuilder(where, args) 15 16 builder := b.getBuilder() 17 builder.whereHolder = append(builder.whereHolder, WhereHolder{ 18 Type: whereHolderTypeDefault, 19 Operator: whereHolderOperatorOr, 20 Where: where, 21 Args: args, 22 Prefix: prefix, 23 }) 24 return builder 25 } 26 27 // WhereOrPrefixNot builds `prefix.column != value` statement in `OR` conditions. 28 func (b *WhereBuilder) WhereOrPrefixNot(prefix string, column string, value interface{}) *WhereBuilder { 29 return b.WhereOrf(`%s.%s != ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) 30 } 31 32 // WhereOrPrefixLT builds `prefix.column < value` statement in `OR` conditions. 33 func (b *WhereBuilder) WhereOrPrefixLT(prefix string, column string, value interface{}) *WhereBuilder { 34 return b.WhereOrf(`%s.%s < ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) 35 } 36 37 // WhereOrPrefixLTE builds `prefix.column <= value` statement in `OR` conditions. 38 func (b *WhereBuilder) WhereOrPrefixLTE(prefix string, column string, value interface{}) *WhereBuilder { 39 return b.WhereOrf(`%s.%s <= ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) 40 } 41 42 // WhereOrPrefixGT builds `prefix.column > value` statement in `OR` conditions. 43 func (b *WhereBuilder) WhereOrPrefixGT(prefix string, column string, value interface{}) *WhereBuilder { 44 return b.WhereOrf(`%s.%s > ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) 45 } 46 47 // WhereOrPrefixGTE builds `prefix.column >= value` statement in `OR` conditions. 48 func (b *WhereBuilder) WhereOrPrefixGTE(prefix string, column string, value interface{}) *WhereBuilder { 49 return b.WhereOrf(`%s.%s >= ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), value) 50 } 51 52 // WhereOrPrefixBetween builds `prefix.column BETWEEN min AND max` statement in `OR` conditions. 53 func (b *WhereBuilder) WhereOrPrefixBetween(prefix string, column string, min, max interface{}) *WhereBuilder { 54 return b.WhereOrf(`%s.%s BETWEEN ? AND ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), min, max) 55 } 56 57 // WhereOrPrefixLike builds `prefix.column LIKE 'like'` statement in `OR` conditions. 58 func (b *WhereBuilder) WhereOrPrefixLike(prefix string, column string, like interface{}) *WhereBuilder { 59 return b.WhereOrf(`%s.%s LIKE ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), like) 60 } 61 62 // WhereOrPrefixIn builds `prefix.column IN (in)` statement in `OR` conditions. 63 func (b *WhereBuilder) WhereOrPrefixIn(prefix string, column string, in interface{}) *WhereBuilder { 64 return b.doWhereOrfType(whereHolderTypeIn, `%s.%s IN (?)`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), in) 65 } 66 67 // WhereOrPrefixNull builds `prefix.columns[0] IS NULL OR prefix.columns[1] IS NULL ...` statement in `OR` conditions. 68 func (b *WhereBuilder) WhereOrPrefixNull(prefix string, columns ...string) *WhereBuilder { 69 builder := b 70 for _, column := range columns { 71 builder = builder.WhereOrf(`%s.%s IS NULL`, b.model.QuoteWord(prefix), b.model.QuoteWord(column)) 72 } 73 return builder 74 } 75 76 // WhereOrPrefixNotBetween builds `prefix.column NOT BETWEEN min AND max` statement in `OR` conditions. 77 func (b *WhereBuilder) WhereOrPrefixNotBetween(prefix string, column string, min, max interface{}) *WhereBuilder { 78 return b.WhereOrf(`%s.%s NOT BETWEEN ? AND ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), min, max) 79 } 80 81 // WhereOrPrefixNotLike builds `prefix.column NOT LIKE 'like'` statement in `OR` conditions. 82 func (b *WhereBuilder) WhereOrPrefixNotLike(prefix string, column string, like interface{}) *WhereBuilder { 83 return b.WhereOrf(`%s.%s NOT LIKE ?`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), like) 84 } 85 86 // WhereOrPrefixNotIn builds `prefix.column NOT IN (in)` statement. 87 func (b *WhereBuilder) WhereOrPrefixNotIn(prefix string, column string, in interface{}) *WhereBuilder { 88 return b.doWhereOrfType(whereHolderTypeIn, `%s.%s NOT IN (?)`, b.model.QuoteWord(prefix), b.model.QuoteWord(column), in) 89 } 90 91 // WhereOrPrefixNotNull builds `prefix.columns[0] IS NOT NULL OR prefix.columns[1] IS NOT NULL ...` statement in `OR` conditions. 92 func (b *WhereBuilder) WhereOrPrefixNotNull(prefix string, columns ...string) *WhereBuilder { 93 builder := b 94 for _, column := range columns { 95 builder = builder.WhereOrf(`%s.%s IS NOT NULL`, b.model.QuoteWord(prefix), b.model.QuoteWord(column)) 96 } 97 return builder 98 }