diff --git a/dialect/dialect.go b/dialect/dialect.go new file mode 100644 index 00000000..50773aa4 --- /dev/null +++ b/dialect/dialect.go @@ -0,0 +1,23 @@ +package dialect + +type Dialect interface { +} + +func NewDialect(driver string) *Dialect { + var d Dialect + switch driver { + case "postgres": + d = postgres{} + case "mysql": + d = mysql{} + case "sqlite3": + d = sqlite3{} + } + return &d +} + +type mysql struct{} + +type postgres struct{} + +type sqlite3 struct{} diff --git a/dialect/mysql.go b/dialect/mysql.go new file mode 100644 index 00000000..2ac98ecf --- /dev/null +++ b/dialect/mysql.go @@ -0,0 +1 @@ +package dialect diff --git a/dialect/postgres.go b/dialect/postgres.go new file mode 100644 index 00000000..2ac98ecf --- /dev/null +++ b/dialect/postgres.go @@ -0,0 +1 @@ +package dialect diff --git a/dialect/sqlite3.go b/dialect/sqlite3.go new file mode 100644 index 00000000..2ac98ecf --- /dev/null +++ b/dialect/sqlite3.go @@ -0,0 +1 @@ +package dialect diff --git a/main.go b/main.go index ff85ddd8..c0f97864 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package gorm import "database/sql" +import "github.com/jinzhu/gorm/dialect" var singularTableName bool var tagIdentifier string @@ -11,14 +12,14 @@ func init() { type DB struct { db sql_common - driver string + dialect *dialect.Dialect logger Logger log_mode bool } func Open(driver, source string) (db DB, err error) { db.db, err = sql.Open(driver, source) - db.driver = driver + db.dialect = dialect.NewDialect(driver) return }