add UseColums function to avoid extra allocation performed by Colums function
fix name tidy adding SetWhere adding SetWhere fix go mod fix comment style revert go mod Avoid to append if no needed fix git ignore revert change in go.sum/go.mod adding specific benchmark
This commit is contained in:
committed by
Michal Jan Matczuk
parent
a57d58f38f
commit
9239d9c4b4
3
.gitignore
vendored
3
.gitignore
vendored
@@ -12,3 +12,6 @@
|
||||
|
||||
# Go vendor dir
|
||||
vendor
|
||||
|
||||
# GoLand IDE
|
||||
.idea/
|
||||
|
||||
24
qb/select.go
24
qb/select.go
@@ -132,7 +132,11 @@ func (b *SelectBuilder) Json() *SelectBuilder {
|
||||
|
||||
// Columns adds result columns to the query.
|
||||
func (b *SelectBuilder) Columns(columns ...string) *SelectBuilder {
|
||||
b.columns = append(b.columns, columns...)
|
||||
if len(b.columns) == 0 {
|
||||
b.columns = columns
|
||||
} else {
|
||||
b.columns = append(b.columns, columns...)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -143,21 +147,33 @@ func As(column, name string) string {
|
||||
|
||||
// Distinct sets DISTINCT clause on the query.
|
||||
func (b *SelectBuilder) Distinct(columns ...string) *SelectBuilder {
|
||||
b.distinct = append(b.distinct, columns...)
|
||||
if len(b.where) == 0 {
|
||||
b.distinct = columns
|
||||
} else {
|
||||
b.distinct = append(b.distinct, columns...)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// Where adds an expression to the WHERE clause of the query. Expressions are
|
||||
// ANDed together in the generated CQL.
|
||||
func (b *SelectBuilder) Where(w ...Cmp) *SelectBuilder {
|
||||
b.where = append(b.where, w...)
|
||||
if len(b.where) == 0 {
|
||||
b.where = w
|
||||
} else {
|
||||
b.where = append(b.where, w...)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// GroupBy sets GROUP BY clause on the query. Columns must be a primary key,
|
||||
// this will automatically add the the columns as first selectors.
|
||||
func (b *SelectBuilder) GroupBy(columns ...string) *SelectBuilder {
|
||||
b.groupBy = append(b.groupBy, columns...)
|
||||
if len(b.groupBy) == 0 {
|
||||
b.groupBy = columns
|
||||
} else {
|
||||
b.groupBy = append(b.groupBy, columns...)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,23 @@ import "testing"
|
||||
func BenchmarkSelectBuilder(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Select("cycling.cyclist_name").Columns("id", "user_uuid", "firstname", "stars").Where(Eq("id")).ToCql()
|
||||
Select("cycling.cyclist_name").
|
||||
Columns("id", "user_uuid", "firstname", "surname", "stars").
|
||||
Where(Eq("id")).
|
||||
ToCql()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSelectBuildAssign(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
cols := []string{
|
||||
"id", "user_uuid", "firstname",
|
||||
"surname", "stars",
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
Select("cycling.cyclist_name").
|
||||
Columns(cols...).
|
||||
Where(Eq("id")).
|
||||
ToCql()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ type TokenBuilder []string
|
||||
|
||||
// Token creates a new TokenBuilder.
|
||||
func Token(columns ...string) TokenBuilder {
|
||||
return TokenBuilder(columns)
|
||||
return columns
|
||||
}
|
||||
|
||||
// Eq produces token(column)=token(?).
|
||||
|
||||
12
qb/update.go
12
qb/update.go
@@ -212,14 +212,22 @@ func (b *UpdateBuilder) removeValue(column string, value value) *UpdateBuilder {
|
||||
// Where adds an expression to the WHERE clause of the query. Expressions are
|
||||
// ANDed together in the generated CQL.
|
||||
func (b *UpdateBuilder) Where(w ...Cmp) *UpdateBuilder {
|
||||
b.where = append(b.where, w...)
|
||||
if len(b.where) == 0 {
|
||||
b.where = w
|
||||
} else {
|
||||
b.where = append(b.where, w...)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// If adds an expression to the IF clause of the query. Expressions are ANDed
|
||||
// together in the generated CQL.
|
||||
func (b *UpdateBuilder) If(w ...Cmp) *UpdateBuilder {
|
||||
b._if = append(b._if, w...)
|
||||
if len(b._if) == 0 {
|
||||
b._if = w
|
||||
} else {
|
||||
b._if = append(b._if, w...)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user