-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcondition.go
More file actions
26 lines (21 loc) · 837 Bytes
/
condition.go
File metadata and controls
26 lines (21 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package q2sql
const ErrUndefinedCondition = Error("condition is not defined")
// Condition returns wrapped SQL representation which describes certain condition
// and a list of the condition arguments
type Condition func(field string, args ...interface{}) (Sqlizer, error)
// ConditionFactory creates specific conditions by the name
type ConditionFactory interface {
// CreateCondition creates condition by the name
CreateCondition(name string) (Condition, error)
}
// ConditionMap maps a string key to a Condition.
// It is used to provide a simple way of provisioning ConditionFactory.
type ConditionMap map[string]Condition
// CreateCondition implements ConditionFactory
func (m ConditionMap) CreateCondition(name string) (Condition, error) {
c, ok := m[name]
if !ok {
return nil, ErrUndefinedCondition
}
return c, nil
}