Skip to content

Commit

Permalink
add DriverName to the dialect interface (required for interfacing wit…
Browse files Browse the repository at this point in the history
…h newer sqlx) and change NewDbMap to work with newer sqlx
  • Loading branch information
jmoiron committed Jun 30, 2013
1 parent 794a78b commit e164a79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dbmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type DbMap struct {

// Return a new DbMap using the db connection and dialect
func NewDbMap(db *sql.DB, dialect Dialect) *DbMap {
return &DbMap{Db: db, Dialect: dialect, Dbx: &sqlx.DB{*db}}
return &DbMap{Db: db, Dialect: dialect, Dbx: sqlx.NewDb(db, dialect.DriverName())}
}

// TraceOn turns on SQL statement logging for this DbMap. After this is
Expand Down
15 changes: 15 additions & 0 deletions dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Dialect interface {
// Handles quoting of a field name to ensure that it doesn't raise any
// SQL parsing exceptions by using a reserved word as a field name.
QuoteField(field string) string

// Get the driver name from a dialect
DriverName() string
}

func standardInsertAutoIncr(exec SqlExecutor, insertSql string, params ...interface{}) (int64, error) {
Expand All @@ -59,6 +62,10 @@ type SqliteDialect struct {
suffix string
}

func (d SqliteDialect) DriverName() string {
return "sqlite"
}

func (d SqliteDialect) ToSqlType(col *ColumnMap) string {
switch col.gotype.Kind() {
case reflect.Bool:
Expand Down Expand Up @@ -130,6 +137,10 @@ type PostgresDialect struct {
suffix string
}

func (d PostgresDialect) DriverName() string {
return "postgres"
}

func (d PostgresDialect) ToSqlType(col *ColumnMap) string {

switch col.gotype.Kind() {
Expand Down Expand Up @@ -228,6 +239,10 @@ type MySQLDialect struct {
Encoding string
}

func (d MySQLDialect) DriverName() string {
return "mysql"
}

func (m MySQLDialect) ToSqlType(col *ColumnMap) string {
switch col.gotype.Kind() {
case reflect.Bool:
Expand Down

0 comments on commit e164a79

Please sign in to comment.