Skip to content

Commit

Permalink
gofmt changes
Browse files Browse the repository at this point in the history
  • Loading branch information
coopernurse committed Jan 6, 2012
1 parent 878727d commit 4d99813
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Dialect interface {
type MySQLDialect struct {

// Engine is the storage engine to use "InnoDB" vs "MyISAM" for example
Engine string
Engine string

// Encoding is the character encoding to use for created tables
Encoding string
Expand Down
44 changes: 23 additions & 21 deletions gorp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ var zeroVal reflect.Value
//
type DbMap struct {
// Db handle to use with this map
Db *sql.DB
Db *sql.DB

// Dialect implementation to use with this map
Dialect Dialect
Dialect Dialect

tables []*TableMap
logger *log.Logger
Expand All @@ -48,9 +48,9 @@ type DbMap struct {
type TableMap struct {
// Name of database table.
TableName string
gotype reflect.Type
columns []*ColumnMap
keys []*ColumnMap
gotype reflect.Type
columns []*ColumnMap
keys []*ColumnMap
}

// SetKeys lets you specify the fields on a struct that map to primary
Expand All @@ -75,7 +75,7 @@ func (t *TableMap) ColMap(field string) *ColumnMap {
for _, col := range t.columns {
if col.fieldName == field {
return col
}
}
}

e := fmt.Sprintf("No ColumnMap in table %s type %s with field %s",
Expand All @@ -89,7 +89,7 @@ func (t *TableMap) ColMap(field string) *ColumnMap {
// CreateTables() function and are not used by Insert/Update/Delete/Get.
type ColumnMap struct {
// Column name in db table
ColumnName string
ColumnName string

// If true, this column is skipped in generated SQL statements
Transient bool
Expand All @@ -107,7 +107,7 @@ type ColumnMap struct {
// Not used elsewhere
MaxSize int

fieldName string
fieldName string
gotype reflect.Type
isPK bool
isAutoIncr bool
Expand All @@ -117,36 +117,36 @@ type ColumnMap struct {
//
// Example: table.ColMap("Updated").Rename("date_updated")
//
func (c *ColumnMap) Rename(colname string) *ColumnMap {
func (c *ColumnMap) Rename(colname string) *ColumnMap {
c.ColumnName = colname
return c
}

// SetTransient allows you to mark the column as transient. If true
// this column will be skipped when SQL statements are generated
func (c *ColumnMap) SetTransient(b bool) *ColumnMap {
func (c *ColumnMap) SetTransient(b bool) *ColumnMap {
c.Transient = b
return c
}

// If true " not null" will be added to create table statements for this
// column
func (c *ColumnMap) SetNullable(b bool) *ColumnMap {
func (c *ColumnMap) SetNullable(b bool) *ColumnMap {
c.Nullable = b
return c
}

// If true " unique" will be added to create table statements for this
// column
func (c *ColumnMap) SetUnique(b bool) *ColumnMap {
func (c *ColumnMap) SetUnique(b bool) *ColumnMap {
c.Unique = b
return c
}

// SetMaxSize specifies the max length of values of this column. This is
// passed to the dialect.ToSqlType() function, which can use the value
// to alter the generated type for "create table" statements
func (c *ColumnMap) SetMaxSize(size int) *ColumnMap {
func (c *ColumnMap) SetMaxSize(size int) *ColumnMap {
c.MaxSize = size
return c
}
Expand All @@ -172,7 +172,7 @@ type SqlExecutor interface {
Update(list ...interface{}) error
Delete(list ...interface{}) (int64, error)
Exec(query string, args ...interface{}) (sql.Result, error)
Select(i interface{}, query string,
Select(i interface{}, query string,
args ...interface{}) ([]interface{}, error)
query(query string, args ...interface{}) (*sql.Rows, error)
queryRow(query string, args ...interface{}) *sql.Row
Expand Down Expand Up @@ -222,10 +222,10 @@ func (m *DbMap) AddTableWithName(i interface{}, name string) *TableMap {
for i := 0; i < n; i++ {
f := t.Field(i)
tmap.columns[i] = &ColumnMap{
ColumnName: f.Name,
Nullable: true,
fieldName : f.Name,
gotype: f.Type,
ColumnName: f.Name,
Nullable: true,
fieldName: f.Name,
gotype: f.Type,
}
}

Expand Down Expand Up @@ -381,7 +381,8 @@ func (m *DbMap) Select(i interface{}, query string, args ...interface{}) ([]inte
// This is equivalent to running: Prepare(), Exec() using exp/sql
func (m *DbMap) Exec(query string, args ...interface{}) (sql.Result, error) {
m.trace(query, args)
stmt, err := m.Db.Prepare(query); if err != nil {
stmt, err := m.Db.Prepare(query)
if err != nil {
return nil, err
}
return stmt.Exec(args...)
Expand Down Expand Up @@ -474,7 +475,8 @@ func (t *Transaction) Select(i interface{}, query string, args ...interface{}) (
// Same behavior as DbMap.Exec(), but runs in a transaction
func (t *Transaction) Exec(query string, args ...interface{}) (sql.Result, error) {
t.dbmap.trace(query, args)
stmt, err := t.tx.Prepare(query); if err != nil {
stmt, err := t.tx.Prepare(query)
if err != nil {
return nil, err
}
return stmt.Exec(args...)
Expand Down Expand Up @@ -579,7 +581,7 @@ func get(m *DbMap, exec SqlExecutor, i interface{},
s.WriteString(",")
}
s.WriteString(col.ColumnName)

f := v.Elem().FieldByName(col.fieldName)
dest = append(dest, f.Addr().Interface())
x++
Expand Down
11 changes: 6 additions & 5 deletions gorp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type InvoicePersonView struct {
}

type TableWithNull struct {
Id int64
Memo sql.NullableString
Id int64
Memo sql.NullableString
}

func (p *Person) PreInsert(s SqlExecutor) error {
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestNullValues(t *testing.T) {
t1.Memo = sql.NullableString{"hi", true}
expected.Memo = t1.Memo
update(dbmap, t1)
obj = get(dbmap, TableWithNull{}, 10)
obj = get(dbmap, TableWithNull{}, 10)
t1 = obj.(*TableWithNull)
if !reflect.DeepEqual(expected, t1) {
t.Errorf("%v != %v", expected, t1)
Expand All @@ -120,7 +120,7 @@ func TestColumnProps(t *testing.T) {
t1.ColMap("Updated").SetTransient(true)
t1.ColMap("Memo").SetMaxSize(10)
t1.ColMap("PersonId").SetUnique(true)

dbmap.CreateTables()
defer dbmap.DropTables()

Expand Down Expand Up @@ -359,7 +359,8 @@ func get(dbmap *DbMap, i interface{}, keys ...interface{}) interface{} {
}

func rawexec(dbmap *DbMap, query string, args ...interface{}) sql.Result {
res, err := dbmap.Exec(query, args...); if err != nil {
res, err := dbmap.Exec(query, args...)
if err != nil {
panic(err)
}
return res
Expand Down

0 comments on commit 4d99813

Please sign in to comment.