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:
13
qb/delete.go
13
qb/delete.go
@@ -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 ")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
13
qb/insert.go
13
qb/insert.go
@@ -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 ")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
12
qb/select.go
12
qb/select.go
@@ -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 ")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
17
qb/update.go
17
qb/update.go
@@ -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 ")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user