bob/append.go

43 lines
853 B
Go
Raw Normal View History

2021-06-24 07:43:28 +00:00
package bob
import "io"
// appendToSQL - Documentation coming soon
func appendToSQL(parts []BobBuilder, w io.Writer, sep string, args []interface{}) ([]interface{}, error) {
2021-06-24 07:43:28 +00:00
for i, p := range parts {
partSQL, partArgs, err := p.ToSQL()
2021-06-24 07:43:28 +00:00
if err != nil {
return nil, err
} else if len(partSQL) == 0 {
2021-06-24 07:43:28 +00:00
continue
}
if i > 0 {
_, err := io.WriteString(w, sep)
if err != nil {
return nil, err
}
}
_, err = io.WriteString(w, partSQL)
2021-06-24 07:43:28 +00:00
if err != nil {
return nil, err
}
args = append(args, partArgs...)
}
return args, nil
}
2021-06-25 17:04:41 +00:00
// createArgs should create an argument []interface{} for SQL query
// I'm using the idiot approach for creating args
func createArgs(keys ...string) []interface{} {
var args []interface{}
for _, v := range keys {
if v == "" {
continue
}
args = append(args, v)
}
return args
}