github.com/wangyougui/gf/v2@v2.6.5/database/gdb/gdb_model_where.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://githum.com/gogf/gf. 6 7 package gdb 8 9 // callWhereBuilder creates and returns a new Model, and sets its WhereBuilder if current Model is safe. 10 // It sets the WhereBuilder and returns current Model directly if it is not safe. 11 func (m *Model) callWhereBuilder(builder *WhereBuilder) *Model { 12 model := m.getModel() 13 model.whereBuilder = builder 14 return model 15 } 16 17 // Where sets the condition statement for the builder. The parameter `where` can be type of 18 // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, 19 // multiple conditions will be joined into where statement using "AND". 20 // See WhereBuilder.Where. 21 func (m *Model) Where(where interface{}, args ...interface{}) *Model { 22 return m.callWhereBuilder(m.whereBuilder.Where(where, args...)) 23 } 24 25 // Wheref builds condition string using fmt.Sprintf and arguments. 26 // Note that if the number of `args` is more than the placeholder in `format`, 27 // the extra `args` will be used as the where condition arguments of the Model. 28 // See WhereBuilder.Wheref. 29 func (m *Model) Wheref(format string, args ...interface{}) *Model { 30 return m.callWhereBuilder(m.whereBuilder.Wheref(format, args...)) 31 } 32 33 // WherePri does the same logic as Model.Where except that if the parameter `where` 34 // is a single condition like int/string/float/slice, it treats the condition as the primary 35 // key value. That is, if primary key is "id" and given `where` parameter as "123", the 36 // WherePri function treats the condition as "id=123", but Model.Where treats the condition 37 // as string "123". 38 // See WhereBuilder.WherePri. 39 func (m *Model) WherePri(where interface{}, args ...interface{}) *Model { 40 return m.callWhereBuilder(m.whereBuilder.WherePri(where, args...)) 41 } 42 43 // WhereLT builds `column < value` statement. 44 // See WhereBuilder.WhereLT. 45 func (m *Model) WhereLT(column string, value interface{}) *Model { 46 return m.callWhereBuilder(m.whereBuilder.WhereLT(column, value)) 47 } 48 49 // WhereLTE builds `column <= value` statement. 50 // See WhereBuilder.WhereLTE. 51 func (m *Model) WhereLTE(column string, value interface{}) *Model { 52 return m.callWhereBuilder(m.whereBuilder.WhereLTE(column, value)) 53 } 54 55 // WhereGT builds `column > value` statement. 56 // See WhereBuilder.WhereGT. 57 func (m *Model) WhereGT(column string, value interface{}) *Model { 58 return m.callWhereBuilder(m.whereBuilder.WhereGT(column, value)) 59 } 60 61 // WhereGTE builds `column >= value` statement. 62 // See WhereBuilder.WhereGTE. 63 func (m *Model) WhereGTE(column string, value interface{}) *Model { 64 return m.callWhereBuilder(m.whereBuilder.WhereGTE(column, value)) 65 } 66 67 // WhereBetween builds `column BETWEEN min AND max` statement. 68 // See WhereBuilder.WhereBetween. 69 func (m *Model) WhereBetween(column string, min, max interface{}) *Model { 70 return m.callWhereBuilder(m.whereBuilder.WhereBetween(column, min, max)) 71 } 72 73 // WhereLike builds `column LIKE like` statement. 74 // See WhereBuilder.WhereLike. 75 func (m *Model) WhereLike(column string, like string) *Model { 76 return m.callWhereBuilder(m.whereBuilder.WhereLike(column, like)) 77 } 78 79 // WhereIn builds `column IN (in)` statement. 80 // See WhereBuilder.WhereIn. 81 func (m *Model) WhereIn(column string, in interface{}) *Model { 82 return m.callWhereBuilder(m.whereBuilder.WhereIn(column, in)) 83 } 84 85 // WhereNull builds `columns[0] IS NULL AND columns[1] IS NULL ...` statement. 86 // See WhereBuilder.WhereNull. 87 func (m *Model) WhereNull(columns ...string) *Model { 88 return m.callWhereBuilder(m.whereBuilder.WhereNull(columns...)) 89 } 90 91 // WhereNotBetween builds `column NOT BETWEEN min AND max` statement. 92 // See WhereBuilder.WhereNotBetween. 93 func (m *Model) WhereNotBetween(column string, min, max interface{}) *Model { 94 return m.callWhereBuilder(m.whereBuilder.WhereNotBetween(column, min, max)) 95 } 96 97 // WhereNotLike builds `column NOT LIKE like` statement. 98 // See WhereBuilder.WhereNotLike. 99 func (m *Model) WhereNotLike(column string, like interface{}) *Model { 100 return m.callWhereBuilder(m.whereBuilder.WhereNotLike(column, like)) 101 } 102 103 // WhereNot builds `column != value` statement. 104 // See WhereBuilder.WhereNot. 105 func (m *Model) WhereNot(column string, value interface{}) *Model { 106 return m.callWhereBuilder(m.whereBuilder.WhereNot(column, value)) 107 } 108 109 // WhereNotIn builds `column NOT IN (in)` statement. 110 // See WhereBuilder.WhereNotIn. 111 func (m *Model) WhereNotIn(column string, in interface{}) *Model { 112 return m.callWhereBuilder(m.whereBuilder.WhereNotIn(column, in)) 113 } 114 115 // WhereNotNull builds `columns[0] IS NOT NULL AND columns[1] IS NOT NULL ...` statement. 116 // See WhereBuilder.WhereNotNull. 117 func (m *Model) WhereNotNull(columns ...string) *Model { 118 return m.callWhereBuilder(m.whereBuilder.WhereNotNull(columns...)) 119 }