From e164a790bb0916d7198423e3bb9da208059659a8 Mon Sep 17 00:00:00 2001 From: Jason Moiron Date: Sun, 30 Jun 2013 00:56:25 -0400 Subject: [PATCH] add DriverName to the dialect interface (required for interfacing with newer sqlx) and change NewDbMap to work with newer sqlx --- dbmap.go | 2 +- dialect.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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: