Skip to content

Commit

Permalink
go vet, lint, and spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
aodin committed May 31, 2016
1 parent 68daed3 commit 4339919
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 23 deletions.
14 changes: 7 additions & 7 deletions column.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/aodin/sol/types"
)

// Tabular is the interface that all dialects of a SQL column must implement
// Columnar is the interface that all dialects of a SQL column must implement
type Columnar interface {
// Two methods for neutral SQL element interfaces:
// (1) Require the interface to return the neutral implementation
Expand Down Expand Up @@ -242,14 +242,14 @@ func (col ColumnElem) NotLike(search string) BinaryClause {
return col.operator(" NOT LIKE ", search)
}

// Like creates a case insensitive pattern matching clause that can be used in
// conditional clauses.
// ILike creates a case insensitive pattern matching clause that can be
// used in conditional clauses.
// table.Select().Where(table.C("name").ILike(`_b%`))
func (col ColumnElem) ILike(search string) BinaryClause {
return col.operator(" ILIKE ", search)
}

// TODO common Not clause?
// NotILike creates a negated, case insensitive pattern matching clause
func (col ColumnElem) NotILike(search string) BinaryClause {
return col.operator(" NOT ILIKE ", search)
}
Expand Down Expand Up @@ -290,14 +290,14 @@ func (col ColumnElem) NotBetween(a, b interface{}) Clause {
// Ordering
// ----

// Orerable implements the Orderable interface that allows the column itself
// to be used in an OrderBy clause.
// Orderable implements the Orderable interface that allows the column
// to be used in an ORDER BY clause.
func (col ColumnElem) Orderable() OrderedColumn {
return OrderedColumn{inner: col}
}

// Asc returns an OrderedColumn. It is the same as passing the column itself
// to an OrderBy clause.
// to an ORDER BY clause.
func (col ColumnElem) Asc() OrderedColumn {
return OrderedColumn{inner: col}
}
Expand Down
4 changes: 2 additions & 2 deletions columnset.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (set ColumnSet) Exists() bool {
return len(set.order) > 0
}

// Filters returns a ColumnSet of columns from the original set that
// Filter returns a ColumnSet of columns from the original set that
// match the given names
func (set ColumnSet) Filter(names ...string) (out ColumnSet) {
for _, column := range set.order {
Expand Down Expand Up @@ -155,7 +155,7 @@ func (set UniqueColumnSet) EmptyValues() Values {
return values
}

// Filters returns a UniqueColumnSet of columns from the original
// Filter returns a UniqueColumnSet of columns from the original
// set that match the given names
func (set UniqueColumnSet) Filter(names ...string) (out UniqueColumnSet) {
return UniqueColumnSet{ColumnSet: set.ColumnSet.Filter(names...)}
Expand Down
1 change: 1 addition & 0 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func AlignFields(columns []string, fields []Field) []Field {
return out
}

// NoMatchingFields returns true if no fields exist
func NoMatchingFields(fields []Field) bool {
for _, field := range fields {
if field.Exists() {
Expand Down
9 changes: 9 additions & 0 deletions function.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
package sol

// Function adds a generic function to the column
func Function(name string, col Columnar) ColumnElem {
return col.Column().AddOperator(name)
}

// Avg returns a column wrapped in the AVG() function
func Avg(expression Columnar) ColumnElem {
return Function("AVG", expression)
}

// Count returns a column wrapped in the COUNT() function
func Count(expression Columnar) ColumnElem {
return Function("COUNT", expression)
}

// Date returns a column wrapped in the DATE() function
func Date(expression Columnar) ColumnElem {
return Function("DATE", expression)
}

// Max returns a column wrapped in the MAX() function
func Max(expression Columnar) ColumnElem {
return Function("MAX", expression)
}

// Min returns a column wrapped in the MIN() function
func Min(expression Columnar) ColumnElem {
return Function("MIN", expression)
}

// StdDev returns a column wrapped in the STDDEV() function
func StdDev(expression Columnar) ColumnElem {
return Function("STDDEV", expression)
}

// Sum returns a column wrapped in the SUM() function
func Sum(expression Columnar) ColumnElem {
return Function("SUM", expression)
}

// Variance returns a column wrapped in the VARIANCE() function
func Variance(expression Columnar) ColumnElem {
return Function("VARIANCE", expression)
}
2 changes: 1 addition & 1 deletion mysql/mysql.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mysql

import (
_ "github.com/go-sql-driver/mysql"
_ "github.com/go-sql-driver/mysql" // Register the MySQL driver

"github.com/aodin/sol/dialect"
)
Expand Down
1 change: 1 addition & 0 deletions names.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func camelToSnake(camel string) string {
return string(snake)
}

// Aliases track column names during camel to snake case conversion
type Aliases map[string]string

// Keys returns the keys of the map in unspecified order
Expand Down
9 changes: 8 additions & 1 deletion order.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"github.com/aodin/sol/dialect"
)

// Both ColumnElem and OrderedColumns will implement the Orderable interface
// Orderable is implemented by both ColumnElem and OrderedColumn types. It
// allows those types to be used in ORDER BY clauses.
type Orderable interface {
Orderable() OrderedColumn
}
Expand All @@ -24,6 +25,7 @@ type OrderedColumn struct {
// OrderedColumn should implement the Orderable interface
var _ Orderable = OrderedColumn{}

// String outputs the OrderedColumn in a neutral dialect.
func (ord OrderedColumn) String() string {
compiled, _ := ord.Compile(&defaultDialect{}, Params())
return compiled
Expand All @@ -45,26 +47,31 @@ func (ord OrderedColumn) Compile(d dialect.Dialect, ps *Parameters) (string, err
return compiled, nil
}

// Orderable returns the OrderedColumn itself
func (ord OrderedColumn) Orderable() OrderedColumn {
return ord
}

// Asc sets the column ordering to ascending - the default
func (ord OrderedColumn) Asc() OrderedColumn {
ord.desc = false
return ord
}

// Desc sets the column ordering to descending
func (ord OrderedColumn) Desc() OrderedColumn {
ord.desc = true
return ord
}

// NullsFirst sets the column ordering to return NULL results first
func (ord OrderedColumn) NullsFirst() OrderedColumn {
ord.nullsFirst = true
ord.nullsLast = false
return ord
}

// NullsLast sets the column ordering to return NULL results last
func (ord OrderedColumn) NullsLast() OrderedColumn {
ord.nullsFirst = false
ord.nullsLast = true
Expand Down
2 changes: 1 addition & 1 deletion parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (p *Parameter) Compile(d dialect.Dialect, ps *Parameters) (string, error) {
return d.Param(ps.Len() - 1), nil
}

// NewParam creates a new *Paramter
// NewParam creates a new *Parameter
func NewParam(value interface{}) *Parameter {
return &Parameter{value}
}
Expand Down
4 changes: 2 additions & 2 deletions postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package postgres
import (
"fmt"

_ "github.com/lib/pq"
_ "github.com/lib/pq" // Register the PostGres driver

"github.com/aodin/sol/dialect"
)
Expand All @@ -14,7 +14,7 @@ type PostGres struct{}
// The PostGres dialect must implement the dialect.Dialect interface
var _ dialect.Dialect = &PostGres{}

// Parameterize returns the postgres specific parameterization scheme.
// Param returns the postgres specific parameterization scheme.
func (d *PostGres) Param(i int) string {
return fmt.Sprintf(`$%d`, i+1)
}
Expand Down
4 changes: 2 additions & 2 deletions result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestResult_One(t *testing.T) {
values = Values{}
one = mockResult(1, "int", "str") // Reset
if err := one.One(&values); err == nil {
t.Errorf("Result.One should error when given a *Values type: %s")
t.Error("Result.One should error when given a *Values type")
}

one = mockResult(1, "int") // Reset
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestResult_All(t *testing.T) {

if err := two.All(&users); err != nil {
t.Errorf(
"Result.All should not error when scanned into a slice of structs",
"Result.All should not error when scanned into a slice of struct type: %s",
err,
)
}
Expand Down
2 changes: 1 addition & 1 deletion sqlite3/sqlite3.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sqlite3

import (
_ "github.com/mattn/go-sqlite3"
_ "github.com/mattn/go-sqlite3" // Register the SQLite3 driver

"github.com/aodin/sol/dialect"
)
Expand Down
4 changes: 2 additions & 2 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (table TableElem) Columns() []ColumnElem {
return table.columns.All()
}

// Create generates the table's CREATE statement.
// Create returns a CREATE statement for the table
func (table *TableElem) Create() CreateStmt {
return CreateStmt{table: table}
}
Expand All @@ -67,7 +67,7 @@ func (table *TableElem) Delete() DeleteStmt {
return Delete(table)
}

// Create generates the table's DROP statement.
// Drop returns a DROP statement for the table
func (table *TableElem) Drop() DropStmt {
return DropStmt{table: table}
}
Expand Down
2 changes: 1 addition & 1 deletion tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func IntegrationTest(t *testing.T, conn *DB) {
// The client should be first
if list[0].Email != "[email protected]" {
t.Errorf(
"Unexpected email: want [email protected], have %d",
"Unexpected email: want [email protected], have %s",
list[0].Email,
)
}
Expand Down
2 changes: 1 addition & 1 deletion text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestText(t *testing.T) {
2, "A",
)

// Give paramters as struct types
// Give parameters as struct types
testuser := struct {
UserID int `db:"id"`
Name string
Expand Down
4 changes: 2 additions & 2 deletions values.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ValueLoop:
return out
}

// Filters returns a Values type with key-values from the original Values
// Filter returns a Values type with key-values from the original Values
// that match the given keys
func (v Values) Filter(keys ...string) Values {
out := Values{}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (v Values) Values() []interface{} {
return values
}

// Values converts the given object to a Values{} type
// ValuesOf converts the given object to a Values type
func ValuesOf(obj interface{}) (Values, error) {
elem := reflect.Indirect(reflect.ValueOf(obj))
switch elem.Kind() {
Expand Down

0 comments on commit 4339919

Please sign in to comment.