diff --git a/dbmap.go b/dbmap.go index 1e88c8e..b380730 100644 --- a/dbmap.go +++ b/dbmap.go @@ -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 diff --git a/dialect.go b/dialect.go index de9c704..fcc63c6 100644 --- a/dialect.go +++ b/dialect.go @@ -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) { @@ -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: @@ -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() { @@ -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: