diff --git a/database/gdb/gdb_model.go b/database/gdb/gdb_model.go index 909103bf7..bc532c59b 100644 --- a/database/gdb/gdb_model.go +++ b/database/gdb/gdb_model.go @@ -61,8 +61,6 @@ type whereHolder struct { } const ( - OptionOmitEmpty = 1 - OptionAllowEmpty = 2 linkTypeMaster = 1 linkTypeSlave = 2 whereHolderWhere = 1 @@ -128,7 +126,6 @@ func (c *Core) Model(tableNameQueryOrStruct ...interface{}) *Model { fields: "*", start: -1, offset: -1, - option: OptionAllowEmpty, filter: true, extraArgs: extraArgs, } diff --git a/database/gdb/gdb_model_condition.go b/database/gdb/gdb_model_condition.go index cf991c6d3..c98d9485e 100644 --- a/database/gdb/gdb_model_condition.go +++ b/database/gdb/gdb_model_condition.go @@ -386,7 +386,7 @@ func (m *Model) formatCondition(limit1 bool, isCountStatement bool) (conditionWh case whereHolderWhere: if conditionWhere == "" { newWhere, newArgs := formatWhere( - m.db, v.where, v.args, m.option&OptionOmitEmpty > 0, m.schema, m.tables, + m.db, v.where, v.args, m.option&optionOmitEmptyWhere > 0, m.schema, m.tables, ) if len(newWhere) > 0 { conditionWhere = newWhere @@ -398,7 +398,7 @@ func (m *Model) formatCondition(limit1 bool, isCountStatement bool) (conditionWh case whereHolderAnd: newWhere, newArgs := formatWhere( - m.db, v.where, v.args, m.option&OptionOmitEmpty > 0, m.schema, m.tables, + m.db, v.where, v.args, m.option&optionOmitEmptyWhere > 0, m.schema, m.tables, ) if len(newWhere) > 0 { if len(conditionWhere) == 0 { @@ -413,7 +413,7 @@ func (m *Model) formatCondition(limit1 bool, isCountStatement bool) (conditionWh case whereHolderOr: newWhere, newArgs := formatWhere( - m.db, v.where, v.args, m.option&OptionOmitEmpty > 0, m.schema, m.tables, + m.db, v.where, v.args, m.option&optionOmitEmptyWhere > 0, m.schema, m.tables, ) if len(newWhere) > 0 { if len(conditionWhere) == 0 { @@ -455,7 +455,7 @@ func (m *Model) formatCondition(limit1 bool, isCountStatement bool) (conditionWh // HAVING. if len(m.having) > 0 { havingStr, havingArgs := formatWhere( - m.db, m.having[0], gconv.Interfaces(m.having[1]), m.option&OptionOmitEmpty > 0, m.schema, m.tables, + m.db, m.having[0], gconv.Interfaces(m.having[1]), m.option&optionOmitEmptyWhere > 0, m.schema, m.tables, ) if len(havingStr) > 0 { conditionExtra += " HAVING " + havingStr diff --git a/database/gdb/gdb_model_option.go b/database/gdb/gdb_model_option.go index 21b0acf1d..6b3de8813 100644 --- a/database/gdb/gdb_model_option.go +++ b/database/gdb/gdb_model_option.go @@ -6,22 +6,40 @@ package gdb +const ( + optionOmitEmpty = optionOmitEmptyWhere | optionOmitEmptyData + optionOmitEmptyWhere = 1 << iota // 8 + optionOmitEmptyData // 16 +) + // Option adds extra operation option for the model. +// Deprecated, use separate operations instead. func (m *Model) Option(option int) *Model { model := m.getModel() model.option = model.option | option return model } -// OptionOmitEmpty sets OptionOmitEmpty option for the model, which automatically filers -// the data and where attributes for empty values. -// Deprecated, use OmitEmpty instead. -func (m *Model) OptionOmitEmpty() *Model { - return m.Option(OptionOmitEmpty) +// OmitEmpty sets OmitEmpty option for the model, which automatically filers +// the data and where parameters for `empty` values. +func (m *Model) OmitEmpty() *Model { + model := m.getModel() + model.option = model.option | optionOmitEmpty + return model } -// OmitEmpty sets OptionOmitEmpty option for the model, which automatically filers -// the data and where attributes for empty values. -func (m *Model) OmitEmpty() *Model { - return m.Option(OptionOmitEmpty) +// OmitEmptyWhere sets OmitEmptyWhere option for the model, which automatically filers +// the Where/Having parameters for `empty` values. +func (m *Model) OmitEmptyWhere() *Model { + model := m.getModel() + model.option = model.option | optionOmitEmptyWhere + return model +} + +// OmitEmptyData sets OmitEmptyData option for the model, which automatically filers +// the Data parameters for `empty` values. +func (m *Model) OmitEmptyData() *Model { + model := m.getModel() + model.option = model.option | optionOmitEmptyData + return model } diff --git a/database/gdb/gdb_model_utility.go b/database/gdb/gdb_model_utility.go index 631160b19..a1a12b75e 100644 --- a/database/gdb/gdb_model_utility.go +++ b/database/gdb/gdb_model_utility.go @@ -110,7 +110,7 @@ func (m *Model) doMappingAndFilterForInsertOrUpdateDataMap(data Map, allowOmitEm return nil, err } // Remove key-value pairs of which the value is empty. - if allowOmitEmpty && m.option&OptionOmitEmpty > 0 { + if allowOmitEmpty && m.option&optionOmitEmptyData > 0 { tempMap := make(Map, len(data)) for k, v := range data { if empty.IsEmpty(v) { diff --git a/database/gdb/gdb_z_mysql_model_test.go b/database/gdb/gdb_z_mysql_model_test.go index 923ccb68a..dc83d4d95 100644 --- a/database/gdb/gdb_z_mysql_model_test.go +++ b/database/gdb/gdb_z_mysql_model_test.go @@ -1938,7 +1938,7 @@ func Test_Model_Option_Map(t *testing.T) { gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) - r, err := db.Model(table).Option(gdb.OptionOmitEmpty).Data(g.Map{ + r, err := db.Model(table).OmitEmptyData().Data(g.Map{ "id": 1, "passport": 0, "password": 0, @@ -1958,7 +1958,7 @@ func Test_Model_Option_Map(t *testing.T) { gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) - _, err := db.Model(table).Option(gdb.OptionOmitEmpty).Data(g.Map{ + _, err := db.Model(table).OmitEmptyData().Data(g.Map{ "id": 1, "passport": 0, "password": 0, @@ -1994,7 +1994,7 @@ func Test_Model_Option_Map(t *testing.T) { gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) - _, err := db.Model(table).Option(gdb.OptionOmitEmpty).Data(g.Map{ + _, err := db.Model(table).OmitEmptyData().Data(g.Map{ "id": 1, "passport": 0, "password": 0, @@ -2031,7 +2031,7 @@ func Test_Model_Option_Map(t *testing.T) { n, _ := r.RowsAffected() t.Assert(n, 1) - _, err = db.Model(table).Option(gdb.OptionOmitEmpty).Data(g.Map{"nickname": ""}).Where("id", 2).Update() + _, err = db.Model(table).OmitEmptyData().Data(g.Map{"nickname": ""}).Where("id", 2).Update() t.AssertNE(err, nil) r, err = db.Model(table).OmitEmpty().Data(g.Map{"nickname": "", "password": "123"}).Where("id", 3).Update() diff --git a/frame/gmvc/controller.go b/frame/gmvc/controller.go index 39b63f271..573d27ff7 100644 --- a/frame/gmvc/controller.go +++ b/frame/gmvc/controller.go @@ -5,6 +5,7 @@ // You can obtain one at https://github.com/gogf/gf. // Package gmvc provides basic object classes for MVC. +// Deprecated, no longer suggested. package gmvc import ( @@ -12,6 +13,7 @@ import ( ) // Controller is used for controller register of ghttp.Server. +// Deprecated, no longer suggested. type Controller struct { Request *ghttp.Request Response *ghttp.Response diff --git a/frame/gmvc/model.go b/frame/gmvc/model.go index 7e5f6a2b3..cc6a67c2b 100644 --- a/frame/gmvc/model.go +++ b/frame/gmvc/model.go @@ -9,6 +9,11 @@ package gmvc import "github.com/gogf/gf/database/gdb" type ( - M = Model // M is alias for Model, just for short write purpose. - Model = *gdb.Model // Model is alias for *gdb.Model. + // M is alias for Model, just for short write purpose. + // Deprecated, no longer suggested. + M = *gdb.Model + + // Model is alias for *gdb.Model. + // Deprecated, no longer suggested. + Model = *gdb.Model ) diff --git a/frame/gmvc/view.go b/frame/gmvc/view.go index 99d7d73c2..3f77dce2b 100644 --- a/frame/gmvc/view.go +++ b/frame/gmvc/view.go @@ -19,6 +19,7 @@ import ( // View is the view object for controller. // It's initialized when controller request initializes and destroyed // when the controller request closes. +// Deprecated, no longer suggested. type View struct { mu sync.RWMutex view *gview.View @@ -27,6 +28,7 @@ type View struct { } // NewView creates and returns a controller view object. +// Deprecated, no longer suggested. func NewView(w *ghttp.Response) *View { return &View{ view: gins.View(), @@ -76,7 +78,7 @@ func (view *View) LockFunc(f func(data gview.Params)) { f(view.data) } -// LockFunc locks reading for template variables by callback function . +// RLockFunc locks reading for template variables by callback function . func (view *View) RLockFunc(f func(data gview.Params)) { view.mu.RLock() defer view.mu.RUnlock()