gdb_model_option.go 2.3 KB

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