-
Notifications
You must be signed in to change notification settings - Fork 2
/
stmt.go
51 lines (43 loc) · 1.22 KB
/
stmt.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package sol
import "fmt"
// Stmt is the base of all statements, including SELECT, UPDATE, DELETE, and
// INSERT statements
type Stmt struct {
errs stmtErrors
}
// AddMeta adds a meta errors to the Stmt errors
func (stmt *Stmt) AddMeta(msg string, args ...interface{}) {
// Create errs if they don't exist
if stmt.errs.fields == nil {
stmt.errs = stmtErrors{fields: make(map[fieldError]string)}
}
stmt.errs.meta = append(stmt.errs.meta, fmt.Sprintf(msg, args...))
}
// Error returns the statement's inner error
func (stmt Stmt) Error() error {
if stmt.errs.Exist() {
return stmt.errs
}
return nil
}
// TODO error setter
// ConditionalStmt includes SELECT, DELETE, and UPDATE statements
type ConditionalStmt struct {
Stmt
where Clause
}
// AddConditional adds a conditional clause to the statement.
// If a conditional clause already exists, it will be logically
// joined to the given clause with AND.
// TODO Additional logical operators?
func (stmt *ConditionalStmt) AddConditional(where Clause) {
if stmt.where == nil {
stmt.where = where
} else {
stmt.where = AllOf(stmt.where, where)
}
}
// Conditional returns the statement's conditional Clause
func (stmt ConditionalStmt) Conditional() Clause {
return stmt.where
}