github.com/gogf/gf@v1.16.9/database/gdb/gdb_model_option.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  const (
    10  	optionOmitNil        = optionOmitNilWhere | optionOmitNilData
    11  	optionOmitEmpty      = optionOmitEmptyWhere | optionOmitEmptyData
    12  	optionOmitEmptyWhere = 1 << iota // 8
    13  	optionOmitEmptyData              // 16
    14  	optionOmitNilWhere               // 32
    15  	optionOmitNilData                // 64
    16  )
    17  
    18  // Option adds extra operation option for the model.
    19  // Deprecated, use separate operations instead.
    20  func (m *Model) Option(option int) *Model {
    21  	model := m.getModel()
    22  	model.option = model.option | option
    23  	return model
    24  }
    25  
    26  // OmitEmpty sets optionOmitEmpty option for the model, which automatically filers
    27  // the data and where parameters for `empty` values.
    28  func (m *Model) OmitEmpty() *Model {
    29  	model := m.getModel()
    30  	model.option = model.option | optionOmitEmpty
    31  	return model
    32  }
    33  
    34  // OmitEmptyWhere sets optionOmitEmptyWhere option for the model, which automatically filers
    35  // the Where/Having parameters for `empty` values.
    36  func (m *Model) OmitEmptyWhere() *Model {
    37  	model := m.getModel()
    38  	model.option = model.option | optionOmitEmptyWhere
    39  	return model
    40  }
    41  
    42  // OmitEmptyData sets optionOmitEmptyData option for the model, which automatically filers
    43  // the Data parameters for `empty` values.
    44  func (m *Model) OmitEmptyData() *Model {
    45  	model := m.getModel()
    46  	model.option = model.option | optionOmitEmptyData
    47  	return model
    48  }
    49  
    50  // OmitNil sets optionOmitNil option for the model, which automatically filers
    51  // the data and where parameters for `nil` values.
    52  func (m *Model) OmitNil() *Model {
    53  	model := m.getModel()
    54  	model.option = model.option | optionOmitNil
    55  	return model
    56  }
    57  
    58  // OmitNilWhere sets optionOmitNilWhere option for the model, which automatically filers
    59  // the Where/Having parameters for `nil` values.
    60  func (m *Model) OmitNilWhere() *Model {
    61  	model := m.getModel()
    62  	model.option = model.option | optionOmitNilWhere
    63  	return model
    64  }
    65  
    66  // OmitNilData sets optionOmitNilData option for the model, which automatically filers
    67  // the Data parameters for `nil` values.
    68  func (m *Model) OmitNilData() *Model {
    69  	model := m.getModel()
    70  	model.option = model.option | optionOmitNilData
    71  	return model
    72  }