forked from doug-martin/goqu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_builder.go
28 lines (23 loc) · 833 Bytes
/
sql_builder.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
package goqu
import "bytes"
//Builder that is composed of a bytes.Buffer. It is used internally and by adapters to build SQL statements
type SqlBuilder struct {
bytes.Buffer
//True if the sql should not be interpolated
IsPrepared bool
//Current Number of arguments, used by adapters that need positional placeholders
CurrentArgPosition int
args []interface{}
}
func NewSqlBuilder(isPrepared bool) *SqlBuilder {
return &SqlBuilder{IsPrepared: isPrepared, args: make([]interface{}, 0), CurrentArgPosition: 1}
}
//Adds an argument to the builder, used when IsPrepared is false
func (me *SqlBuilder) WriteArg(i interface{}) {
me.CurrentArgPosition++
me.args = append(me.args, i)
}
//Returns the sql string, and arguments.
func (me *SqlBuilder) ToSql() (string, []interface{}) {
return me.String(), me.args
}