Skip to content

Commit

Permalink
More comments and fmt cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aodin committed May 8, 2016
1 parent 971e4b1 commit 054cab7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
6 changes: 0 additions & 6 deletions executable.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package sol

import ()

type destination struct {
value interface{}
}

type Executable interface {
Compiles
}
7 changes: 4 additions & 3 deletions insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

var (
// ErrNoColumns is returned when a query for one columns returns none
ErrNoColumns = errors.New(
"sol: attempt to create a statement with zero columns",
)
Expand Down Expand Up @@ -72,7 +73,7 @@ func (stmt InsertStmt) Compile(d dialect.Dialect, ps *Parameters) (string, error
if rows == 0 {
rows = 1
stmt.args = make([]interface{}, cols)
for i, _ := range stmt.args {
for i := range stmt.args {
stmt.args[i] = nil
}
}
Expand Down Expand Up @@ -357,7 +358,7 @@ func removeColumn(columns []Columnar, name string) []Columnar {
func valuesMap(stmt InsertStmt, values Values) (fields, error) {
fields := make(fields, len(values))
var i int
for column, _ := range values {
for column := range values {
if !stmt.Has(column) {
return nil, fmt.Errorf(
"sol: cannot INSERT a value with column '%s' as it has no corresponding column in the INSERT statement",
Expand All @@ -372,7 +373,7 @@ func valuesMap(stmt InsertStmt, values Values) (fields, error) {
// Insert creates an INSERT statement for the given columns. There must be at
// least one column and all columns must belong to the same table.
func Insert(selections ...Selectable) (stmt InsertStmt) {
columns := make([]Columnar, 0)
var columns []Columnar
for _, selection := range selections {
if selection == nil {
stmt.AddMeta("sol: INSERT received a nil selectable - do the columns or tables you selected exist?")
Expand Down
2 changes: 0 additions & 2 deletions modifier.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package sol

import ()

type Modifier interface {
Modify(*TableElem) error
}
6 changes: 6 additions & 0 deletions parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/aodin/sol/dialect"
)

// Parameter is a value that will be passed to the database using a
// dialect specific parameterization
type Parameter struct {
Value interface{}
}
Expand All @@ -15,16 +17,20 @@ func (p *Parameter) Compile(d dialect.Dialect, ps *Parameters) (string, error) {
return d.Param(ps.Len() - 1), nil
}

// Parameters aggregated values before parameterization
type Parameters []interface{}

// Add adds a parameter
func (ps *Parameters) Add(param interface{}) {
*ps = append(*ps, param)
}

// Len returns the length of the Parameters
func (ps *Parameters) Len() int {
return len(*ps)
}

// Params creates a new Parameters
func Params() *Parameters {
return &Parameters{}
}
4 changes: 3 additions & 1 deletion postgres/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/aodin/sol/types"
)

// serial is a postgres-specfic auto-increment type. It implies NOT NULL.
// serial is a postgres-specific auto-increment type. It implies NOT NULL.
type serial struct {
name string
isUnique bool
Expand All @@ -22,11 +22,13 @@ func (t serial) Create(d dialect.Dialect) (string, error) {
return compiled, nil
}

// Unique sets the serial type as unique
func (t serial) Unique() serial {
t.isUnique = true
return t
}

// Serial creates a new serial type
func Serial() (t serial) {
t.name = "serial"
return
Expand Down
5 changes: 3 additions & 2 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Scanner interface {
Scan(...interface{}) error
}

// Result is returned by a database query - it implements Scanner
type Result struct {
stmt string
Scanner
Expand Down Expand Up @@ -46,7 +47,7 @@ func (r *Result) One(arg interface{}) error {
// TODO scan directly into values?
addr := make([]interface{}, len(columns))
dest := make([]interface{}, len(columns))
for i, _ := range addr {
for i := range addr {
dest[i] = &addr[i]
}

Expand Down Expand Up @@ -240,7 +241,7 @@ func (r *Result) All(arg interface{}) error {
// TODO scan directly into values?
addr := make([]interface{}, len(columns))
dest := make([]interface{}, len(columns))
for i, _ := range addr {
for i := range addr {
dest[i] = &addr[i]
}

Expand Down
2 changes: 1 addition & 1 deletion select.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (stmt SelectStmt) hasTable(name string) bool {
return false
}

// All removes the DISTINCT clause from the SELECT statment.
// All removes the DISTINCT clause from the SELECT statement.
func (stmt SelectStmt) All() SelectStmt {
stmt.isDistinct = false
stmt.distincts = nil
Expand Down

0 comments on commit 054cab7

Please sign in to comment.