-
Notifications
You must be signed in to change notification settings - Fork 0
/
expression.go
26 lines (21 loc) · 822 Bytes
/
expression.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
package dat
import "gopkg.in/mgutz/dat.v1/common"
// Expression holds a sub expression.
type Expression struct {
Sql string
Args []interface{}
}
// Expr is a SQL expression with placeholders, and a slice of args to replace them with
func Expr(sql string, values ...interface{}) *Expression {
return &Expression{Sql: sql, Args: values}
}
// WriteRelativeArgs writes the args to buf adjusting the placeholder to start at pos.
func (exp *Expression) WriteRelativeArgs(buf common.BufferWriter, args *[]interface{}, pos *int64) {
remapPlaceholders(buf, exp.Sql, *pos)
*args = append(*args, exp.Args...)
*pos += int64(len(exp.Args))
}
// Expression implements Expressioner interface (used in Interpolate).
func (exp *Expression) Expression() (string, []interface{}, error) {
return Interpolate(exp.Sql, exp.Args)
}