condition/engine/engine_case.go

25 lines
536 B
Go
Raw Normal View History

2023-07-20 14:55:00 +08:00
package engine
import (
"git.fsdpf.net/go/condition/contracts"
2023-07-20 14:55:00 +08:00
"git.fsdpf.net/go/db"
"git.fsdpf.net/go/req"
2023-07-20 14:55:00 +08:00
)
type EngineCase[T any] struct {
predicate contracts.Condition
cb func(data T, g req.GlobalParams) error
2023-07-20 14:55:00 +08:00
}
func (this EngineCase[T]) ToSql(param contracts.ConditionTokenValue) db.Expression {
if this.predicate == nil || this.predicate.IsEmpty() {
return db.Raw("NULL")
}
2023-07-20 14:55:00 +08:00
return this.predicate.ToSql(param)
}
func (this EngineCase[T]) Execute(data T, g req.GlobalParams) error {
2023-07-20 14:55:00 +08:00
return this.cb(data, g)
}