Skip to content

Commit

Permalink
Merge pull request jmoiron#11 from silasdavis/TableNameMapper
Browse files Browse the repository at this point in the history
Added TableNameMapper to modl
  • Loading branch information
jmoiron committed Feb 19, 2014
2 parents 992aacd + aefb317 commit 9d7184e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dbmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ import (
"fmt"
"log"
"reflect"

"strings"
"github.com/jmoiron/sqlx"
)

// TableNameMapper is the function used by AddTable to map struct names to database table names, in analogy
// to sqlx.NameMapper which does the same for struct field name to database column names.
var TableNameMapper = strings.ToLower

// DbMap is the root modl mapping object. Create one of these for each
// database schema you wish to map. Each DbMap contains a list of
// mapped tables.
Expand Down Expand Up @@ -83,7 +87,7 @@ func (m *DbMap) AddTable(i interface{}, name ...string) *TableMap {
t := reflect.TypeOf(i)
// Use sqlx's NameMapper function if no name is supplied
if len(Name) == 0 {
Name = sqlx.NameMapper(t.Name())
Name = TableNameMapper(t.Name())
}

// check if we have a table for this type already
Expand Down

0 comments on commit 9d7184e

Please sign in to comment.