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