Swap strings.Builder for bytes.Buffer for go 1.9 support

This commit is contained in:
Edvard 2018-12-13 16:08:57 +01:00
parent 129964f3bc
commit 35f7f719e6

View File

@ -1,12 +1,12 @@
package shared package shared
import ( import (
"bytes"
"database/sql" "database/sql"
"database/sql/driver" "database/sql/driver"
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"strings"
) )
type Repository struct{} type Repository struct{}
@ -85,18 +85,19 @@ func (_ Repository) GetCheckedColumnNames(db *postgres.DB) ([]string, error) {
// Ex: ["columnA", "columnB"] => "NOT (columnA AND columnB)" // Ex: ["columnA", "columnB"] => "NOT (columnA AND columnB)"
// [] => "FALSE" // [] => "FALSE"
func (_ Repository) CreateNotCheckedSQL(boolColumns []string) string { func (_ Repository) CreateNotCheckedSQL(boolColumns []string) string {
var result strings.Builder var result bytes.Buffer
if len(boolColumns) == 0 { if len(boolColumns) == 0 {
return "FALSE" return "FALSE"
} }
result.WriteString("NOT (") result.WriteString("NOT (")
// Loop excluding last column name
for _, column := range boolColumns[:len(boolColumns)-1] { for _, column := range boolColumns[:len(boolColumns)-1] {
result.WriteString(fmt.Sprintf("%v AND ", column)) result.WriteString(fmt.Sprintf("%v AND ", column))
} }
// No trailing "OR" for last column name // No trailing "OR" for the last column name
result.WriteString(fmt.Sprintf("%v)", boolColumns[len(boolColumns)-1])) result.WriteString(fmt.Sprintf("%v)", boolColumns[len(boolColumns)-1]))
return result.String() return result.String()