qb: removed error from builder ToCql function

Builder is not in a position to validate the statement and the effort is
duplicated when the query is build. The checked errors are simple and
do not occur most of the time.
This commit is contained in:
Michał Matczuk
2017-07-28 09:43:58 +02:00
parent 2afe71e2b9
commit eb033c4922
8 changed files with 8 additions and 67 deletions

View File

@@ -5,8 +5,6 @@ package qb
import (
"bytes"
"errors"
"fmt"
"time"
)
@@ -26,16 +24,7 @@ func Delete(table string) *DeleteBuilder {
}
}
func (b *DeleteBuilder) ToCql() (stmt string, names []string, err error) {
if b.table == "" {
err = errors.New("delete statements must specify a table")
return
}
if len(b.where) == 0 {
err = fmt.Errorf("delete statements must have at least one WHERE clause")
return
}
func (b *DeleteBuilder) ToCql() (stmt string, names []string) {
cql := bytes.Buffer{}
cql.WriteString("DELETE ")

View File

@@ -60,10 +60,7 @@ func TestDeleteBuilder(t *testing.T) {
}
for _, test := range table {
stmt, names, err := test.B.ToCql()
if err != nil {
t.Error("unexpected error", err)
}
stmt, names := test.B.ToCql()
if diff := cmp.Diff(test.S, stmt); diff != "" {
t.Error(diff)
}

View File

@@ -5,7 +5,6 @@ package qb
import (
"bytes"
"errors"
"time"
)
@@ -23,17 +22,7 @@ func Insert(table string) *InsertBuilder {
}
}
func (b *InsertBuilder) ToCql() (stmt string, names []string, err error) {
if b.table == "" {
err = errors.New("insert statements must specify a table")
return
}
if len(b.columns) == 0 {
err = errors.New("insert statements must specify columns")
return
}
func (b *InsertBuilder) ToCql() (stmt string, names []string) {
cql := bytes.Buffer{}
cql.WriteString("INSERT ")

View File

@@ -53,10 +53,7 @@ func TestInsertBuilder(t *testing.T) {
}
for _, test := range table {
stmt, names, err := test.B.ToCql()
if err != nil {
t.Error("unexpected error", err)
}
stmt, names := test.B.ToCql()
if diff := cmp.Diff(test.S, stmt); diff != "" {
t.Error(diff)
}

View File

@@ -5,7 +5,6 @@ package qb
import (
"bytes"
"errors"
"fmt"
)
@@ -36,16 +35,7 @@ func Select(table string) *SelectBuilder {
}
}
func (b *SelectBuilder) ToCql() (stmt string, names []string, err error) {
if b.table == "" {
err = errors.New("select statements must specify a table")
return
}
if b.distinct != "" && len(b.columns) > 0 {
err = fmt.Errorf("select statements must specify either a column list or DISTINCT partition_key")
return
}
func (b *SelectBuilder) ToCql() (stmt string, names []string) {
cql := bytes.Buffer{}
cql.WriteString("SELECT ")

View File

@@ -72,10 +72,7 @@ func TestSelectBuilder(t *testing.T) {
}
for _, test := range table {
stmt, names, err := test.B.ToCql()
if err != nil {
t.Error("unexpected error", err)
}
stmt, names := test.B.ToCql()
if diff := cmp.Diff(test.S, stmt); diff != "" {
t.Error(diff)
}

View File

@@ -2,8 +2,6 @@ package qb
import (
"bytes"
"errors"
"fmt"
)
// UPDATE reference:
@@ -29,20 +27,7 @@ func Update(table string) *UpdateBuilder {
}
}
func (b *UpdateBuilder) ToCql() (stmt string, names []string, err error) {
if b.table == "" {
err = errors.New("update statements must specify a table")
return
}
if len(b.columns) == 0 {
err = fmt.Errorf("update statements must have at least one SET clause")
return
}
if len(b.where) == 0 {
err = fmt.Errorf("update statements must have at least one WHERE clause")
return
}
func (b *UpdateBuilder) ToCql() (stmt string, names []string) {
cql := bytes.Buffer{}
cql.WriteString("UPDATE ")

View File

@@ -66,10 +66,7 @@ func TestUpdateBuilder(t *testing.T) {
}
for _, test := range table {
stmt, names, err := test.B.ToCql()
if err != nil {
t.Error("unexpected error", err)
}
stmt, names := test.B.ToCql()
if diff := cmp.Diff(test.S, stmt); diff != "" {
t.Error(diff)
}