database/gdb: add unscoped tag support for orm struct (#3464)

This commit is contained in:
PickMeUp
2024-05-22 21:52:21 +08:00
committed by GitHub
parent 17385eeaef
commit b675d01418
3 changed files with 128 additions and 9 deletions

View File

@ -59,12 +59,13 @@ type iTableName interface {
}
const (
OrmTagForStruct = "orm"
OrmTagForTable = "table"
OrmTagForWith = "with"
OrmTagForWithWhere = "where"
OrmTagForWithOrder = "order"
OrmTagForDo = "do"
OrmTagForStruct = "orm"
OrmTagForTable = "table"
OrmTagForWith = "with"
OrmTagForWithWhere = "where"
OrmTagForWithOrder = "order"
OrmTagForWithUnscoped = "unscoped"
OrmTagForDo = "do"
)
var (

View File

@ -162,6 +162,9 @@ func (m *Model) doWithScanStruct(pointer interface{}) error {
if parsedTagOutput.Order != "" {
model = model.Order(parsedTagOutput.Order)
}
if parsedTagOutput.Unscoped == "true" {
model = model.Unscoped()
}
// With cache feature.
if m.cacheEnabled && m.cacheOption.Name == "" {
model = model.Cache(m.cacheOption)
@ -277,6 +280,9 @@ func (m *Model) doWithScanStructs(pointer interface{}) error {
if parsedTagOutput.Order != "" {
model = model.Order(parsedTagOutput.Order)
}
if parsedTagOutput.Unscoped == "true" {
model = model.Unscoped()
}
// With cache feature.
if m.cacheEnabled && m.cacheOption.Name == "" {
model = model.Cache(m.cacheOption)
@ -293,9 +299,10 @@ func (m *Model) doWithScanStructs(pointer interface{}) error {
}
type parseWithTagInFieldStructOutput struct {
With string
Where string
Order string
With string
Where string
Order string
Unscoped string
}
func (m *Model) parseWithTagInFieldStruct(field gstructs.Field) (output parseWithTagInFieldStructOutput) {
@ -320,5 +327,6 @@ func (m *Model) parseWithTagInFieldStruct(field gstructs.Field) (output parseWit
output.With = data[OrmTagForWith]
output.Where = data[OrmTagForWithWhere]
output.Order = data[OrmTagForWithOrder]
output.Unscoped = data[OrmTagForWithUnscoped]
return
}