From ac4b2e2a42f66981f31e1175cb7e1c111dbc9435 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 14 Nov 2013 17:35:17 +0800 Subject: [PATCH] Initalize dialects --- dialect/dialect.go | 23 +++++++++++++++++++++++ dialect/mysql.go | 1 + dialect/postgres.go | 1 + dialect/sqlite3.go | 1 + main.go | 5 +++-- 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 dialect/dialect.go create mode 100644 dialect/mysql.go create mode 100644 dialect/postgres.go create mode 100644 dialect/sqlite3.go 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 }