condition/engine/engine_case.go

25 lines
527 B
Go
Raw Normal View History

2023-07-20 14:55:00 +08:00
package engine
import (
2024-05-09 09:26:57 +08:00
"git.fsdpf.net/go/condition"
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 {
2024-05-09 09:26:57 +08:00
predicate *condition.Condition
cb func(data T, g req.GlobalParams) error
2023-07-20 14:55:00 +08:00
}
2024-05-09 09:26:57 +08:00
func (this EngineCase[T]) ToSql(param condition.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)
}