Skip to content

Commit

Permalink
refactor: remove the 'always true' condition
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-poliushkin committed Dec 27, 2021
1 parent 420a698 commit 9f4fdd3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
4 changes: 1 addition & 3 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ func (s *ResourceSelectBuilder) Build(
if err != nil {
return nil, err
}
if len(conditions) == 0 && len(b.WhereParts) == 0 {
b.Where(alwaysTrue)
} else {
if len(conditions) > 0 {
b.Where(conditions...)
}
sortList := make([]qparser.Sort, len(query.Sort))
Expand Down
4 changes: 2 additions & 2 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ var resourceBuilderTests = []resourceBuilderTest{
{
title: "Default fields, no conditions",
query: "",
sql: fmt.Sprintf("SELECT * FROM %s WHERE 1 = 1", resourceName),
sql: fmt.Sprintf("SELECT * FROM %s", resourceName),
args: []interface{}{},
},
{
title: "Specific fields, no conditions",
query: fmt.Sprintf("fields[%s]=%s,%s", resourceName, resourceFieldID, resourceFieldTitle),
sql: fmt.Sprintf("SELECT %s, %s FROM %s WHERE 1 = 1", resourceFieldID, resourceFieldTitle, resourceName),
sql: fmt.Sprintf("SELECT %s, %s FROM %s", resourceFieldID, resourceFieldTitle, resourceName),
args: []interface{}{},
},
{
Expand Down
2 changes: 0 additions & 2 deletions expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/velmie/qparser"
)

const alwaysTrue = RawSql("1 = 1")

// Sqlizer return an SQL with the list of arguments
type Sqlizer interface {
ToSql() (string, []interface{}, error)
Expand Down

0 comments on commit 9f4fdd3

Please sign in to comment.