Skip to content

Commit

Permalink
use sqlx.NameMapper instead of strings.ToLower to map struct names to…
Browse files Browse the repository at this point in the history
… column names
  • Loading branch information
jmoiron committed Oct 15, 2013
1 parent 377aa9c commit 525c492
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions dbmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/jmoiron/sqlx"
"log"
"reflect"
"strings"
)

// DbMap is the root modl mapping object. Create one of these for each
Expand Down Expand Up @@ -75,7 +74,7 @@ func (m *DbMap) AddTable(i interface{}, name ...string) *TableMap {

t := reflect.TypeOf(i)
if len(Name) == 0 {
Name = strings.ToLower(t.Name())
Name = sqlx.NameMapper(t.Name())
}

// check if we have a table for this type already
Expand All @@ -97,7 +96,7 @@ func (m *DbMap) AddTable(i interface{}, name ...string) *TableMap {
f := t.Field(i)
columnName := f.Tag.Get("db")
if columnName == "" {
columnName = strings.ToLower(f.Name)
columnName = sqlx.NameMapper(f.Name)
}

cm := &ColumnMap{
Expand Down
3 changes: 2 additions & 1 deletion dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package modl
import (
"errors"
"fmt"
"github.com/jmoiron/sqlx"
"reflect"
"strings"
)
Expand Down Expand Up @@ -233,7 +234,7 @@ func (d PostgresDialect) InsertAutoIncr(exec SqlExecutor, insertSql string, para
}

func (d PostgresDialect) QuoteField(f string) string {
return `"` + strings.ToLower(f) + `"`
return `"` + sqlx.NameMapper(f) + `"`
}

func (d PostgresDialect) TruncateClause() string {
Expand Down
3 changes: 1 addition & 2 deletions modl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"fmt"
"github.com/jmoiron/sqlx"
"reflect"
"strings"
)

type NoKeysErr struct {
Expand Down Expand Up @@ -100,7 +99,7 @@ func (t *TableMap) ResetSql() {
func (t *TableMap) SetKeys(isAutoIncr bool, fieldNames ...string) *TableMap {
t.keys = make([]*ColumnMap, 0)
for _, name := range fieldNames {
colmap := t.ColMap(strings.ToLower(name))
colmap := t.ColMap(sqlx.NameMapper(name))
colmap.isPK = true
colmap.isAutoIncr = isAutoIncr
t.keys = append(t.keys, colmap)
Expand Down

0 comments on commit 525c492

Please sign in to comment.