From 3eba8d690fe9fb0dde61bac488f81c0eab234753 Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 27 Nov 2020 13:28:18 +0800 Subject: [PATCH] add TimeMaintainDisabled configuration for automatic time maintaining feature --- .../{gdb_model_soft_time.go => gdb_model_time.go} | 12 ++++++++++++ 1 file changed, 12 insertions(+) rename database/gdb/{gdb_model_soft_time.go => gdb_model_time.go} (94%) diff --git a/database/gdb/gdb_model_soft_time.go b/database/gdb/gdb_model_time.go similarity index 94% rename from database/gdb/gdb_model_soft_time.go rename to database/gdb/gdb_model_time.go index 77caac8f3..e034188c6 100644 --- a/database/gdb/gdb_model_soft_time.go +++ b/database/gdb/gdb_model_time.go @@ -32,6 +32,10 @@ func (m *Model) Unscoped() *Model { // If there's no field name for storing creating time, it returns an empty string. // It checks the key with or without cases or chars '-'/'_'/'.'/' '. func (m *Model) getSoftFieldNameCreated(table ...string) string { + // It checks whether this feature disabled. + if m.db.GetConfig().TimeMaintainDisabled { + return "" + } tableName := "" if len(table) > 0 { tableName = table[0] @@ -49,6 +53,10 @@ func (m *Model) getSoftFieldNameCreated(table ...string) string { // If there's no field name for storing updating time, it returns an empty string. // It checks the key with or without cases or chars '-'/'_'/'.'/' '. func (m *Model) getSoftFieldNameUpdated(table ...string) (field string) { + // It checks whether this feature disabled. + if m.db.GetConfig().TimeMaintainDisabled { + return "" + } tableName := "" if len(table) > 0 { tableName = table[0] @@ -66,6 +74,10 @@ func (m *Model) getSoftFieldNameUpdated(table ...string) (field string) { // If there's no field name for storing deleting time, it returns an empty string. // It checks the key with or without cases or chars '-'/'_'/'.'/' '. func (m *Model) getSoftFieldNameDeleted(table ...string) (field string) { + // It checks whether this feature disabled. + if m.db.GetConfig().TimeMaintainDisabled { + return "" + } tableName := "" if len(table) > 0 { tableName = table[0]