From 433991905551cacfd10620f164cb99e8880fc22a Mon Sep 17 00:00:00 2001 From: "Aaron O. Ellis" Date: Mon, 30 May 2016 19:35:46 -0600 Subject: [PATCH] go vet, lint, and spelling --- column.go | 14 +++++++------- columnset.go | 4 ++-- fields.go | 1 + function.go | 9 +++++++++ mysql/mysql.go | 2 +- names.go | 1 + order.go | 9 ++++++++- parameters.go | 2 +- postgres/postgres.go | 4 ++-- result_test.go | 4 ++-- sqlite3/sqlite3.go | 2 +- table.go | 4 ++-- tester.go | 2 +- text_test.go | 2 +- values.go | 4 ++-- 15 files changed, 41 insertions(+), 23 deletions(-) diff --git a/column.go b/column.go index 91ec4d5..e6c13ec 100644 --- a/column.go +++ b/column.go @@ -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 @@ -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) } @@ -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} } diff --git a/columnset.go b/columnset.go index 951b262..04fbda8 100644 --- a/columnset.go +++ b/columnset.go @@ -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 { @@ -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...)} diff --git a/fields.go b/fields.go index de6fe94..e04c053 100644 --- a/fields.go +++ b/fields.go @@ -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() { diff --git a/function.go b/function.go index 0776d51..d4a24fe 100644 --- a/function.go +++ b/function.go @@ -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) } diff --git a/mysql/mysql.go b/mysql/mysql.go index aedd353..22da10d 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -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" ) diff --git a/names.go b/names.go index c9f90bf..fcc4dd9 100644 --- a/names.go +++ b/names.go @@ -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 diff --git a/order.go b/order.go index ee38366..9536fe2 100644 --- a/order.go +++ b/order.go @@ -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 } @@ -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 @@ -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 diff --git a/parameters.go b/parameters.go index 8942f47..28e60c7 100644 --- a/parameters.go +++ b/parameters.go @@ -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} } diff --git a/postgres/postgres.go b/postgres/postgres.go index ce7d545..531bf98 100644 --- a/postgres/postgres.go +++ b/postgres/postgres.go @@ -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" ) @@ -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) } diff --git a/result_test.go b/result_test.go index 9d31834..fa17ddb 100644 --- a/result_test.go +++ b/result_test.go @@ -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 @@ -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, ) } diff --git a/sqlite3/sqlite3.go b/sqlite3/sqlite3.go index b03d70c..9757971 100644 --- a/sqlite3/sqlite3.go +++ b/sqlite3/sqlite3.go @@ -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" ) diff --git a/table.go b/table.go index 30fb2b9..38ce682 100644 --- a/table.go +++ b/table.go @@ -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} } @@ -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} } diff --git a/tester.go b/tester.go index 3b3be41..c6456ed 100644 --- a/tester.go +++ b/tester.go @@ -232,7 +232,7 @@ func IntegrationTest(t *testing.T, conn *DB) { // The client should be first if list[0].Email != "client@example.com" { t.Errorf( - "Unexpected email: want client@example.com, have %d", + "Unexpected email: want client@example.com, have %s", list[0].Email, ) } diff --git a/text_test.go b/text_test.go index ef5684a..b14ee9f 100644 --- a/text_test.go +++ b/text_test.go @@ -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 diff --git a/values.go b/values.go index 4c7aaf7..35a187d 100644 --- a/values.go +++ b/values.go @@ -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{} @@ -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() {