diff options
Diffstat (limited to 'src/hub/src/spreadspace.org/sfive/s5store.go')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store.go | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go index 85a9a1f..5fbd7f7 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store.go +++ b/src/hub/src/spreadspace.org/sfive/s5store.go @@ -5,10 +5,11 @@ import ( "fmt" "time" - _ "github.com/mattn/go-sqlite3" - "code.google.com/p/go-uuid/uuid" "github.com/coopernurse/gorp" + _ "github.com/go-sql-driver/mysql" + _ "github.com/mattn/go-sqlite3" + _ "github.com/ziutek/mymysql/godrv" ) type sqliteStore struct { @@ -67,14 +68,27 @@ func updateFromStatisticsData(value StatisticsData) (dataUpdateDb, []clientDataD return du, cd, src, tags } -func initDb(path string) (res *gorp.DbMap, hubId string, err error) { +func initDb(mysql bool, path string) (res *gorp.DbMap, hubId string, err error) { // connect to db using standard Go database/sql API - db, err := sql.Open("sqlite3", path) - if err != nil { - return + var db *DB + var err error + var dialect gorp.Dialect + + if mysql { + db, err = sql.Open("mysql", path) + if err != nil { + return + } + dialect = gorp.MySqlDialect{} + } else { + db, err = sql.Open("sqlite3", path) + if err != nil { + return + } + dialect = gorp.SqliteDialect{} } - dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}} + dbmap := &gorp.DbMap{Db: db, Dialect: dialect} // dbmap.TraceOn("[gorp]", log.New(os.Stdout, "myapp:", log.Lmicroseconds)) dbmap.AddTableWithName(tagDb{}, tagsTn).SetKeys(true, "Id").ColMap("Name").SetUnique(true) @@ -554,8 +568,8 @@ func (s sqliteStore) GetStoreId() (uuid string, err error) { return } -func NewStore(path string) (store sqliteStore, err error) { - db, hubid, err := initDb(path) +func NewStore(mysql bool, path string) (store sqliteStore, err error) { + db, hubid, err := initDb(mysql, path) if err != nil { return } |