summaryrefslogtreecommitdiff
path: root/src/hub/src/spreadspace.org/sfive
diff options
context:
space:
mode:
authorMarkus Grüneis <gimpf@gimpf.org>2014-10-25 00:26:00 +0200
committerMarkus Grüneis <gimpf@gimpf.org>2014-10-25 00:26:23 +0200
commit32f461f288d177a1db25236299ab2f440af2a583 (patch)
tree4374cb109c6b080efc06e3e5cfdaa69c85018f06 /src/hub/src/spreadspace.org/sfive
parentstart with last 10 minutes (diff)
hub: add hacky untested MySql support
Diffstat (limited to 'src/hub/src/spreadspace.org/sfive')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srv.go4
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go32
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store_test.go6
3 files changed, 28 insertions, 14 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srv.go b/src/hub/src/spreadspace.org/sfive/s5srv.go
index 6647518..0bd220a 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srv.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srv.go
@@ -56,10 +56,10 @@ func (self StatsSinkServer) Close() {
self.store.Close()
}
-func NewServer(dbPath string) (server *StatsSinkServer, err error) {
+func NewServer(mysql bool, dbPath string) (server *StatsSinkServer, err error) {
// TODO read configuration and create instance with correct settings
server = new(StatsSinkServer)
- server.store, err = NewStore(dbPath)
+ server.store, err = NewStore(mysql, dbPath)
if err != nil {
return
}
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
}
diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go
index 49ca35e..927d84a 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store_test.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go
@@ -6,7 +6,7 @@ import (
)
func TestAppend(t *testing.T) {
- store, err := NewStore("file:memdb1?mode=memory&cache=shared")
+ store, err := NewStore(false, "file:memdb1?mode=memory&cache=shared")
if err != nil {
t.Errorf("Failed to initialize: %v", err)
return
@@ -53,7 +53,7 @@ func TestAppend(t *testing.T) {
}
func TestCount(t *testing.T) {
- store, err := NewStore("file:memdb1?mode=memory&cache=shared")
+ store, err := NewStore(false, "file:memdb1?mode=memory&cache=shared")
if err != nil {
t.Errorf("Failed to initialize: %v", err)
}
@@ -67,7 +67,7 @@ func TestCount(t *testing.T) {
}
func TestGetUpdatesAfter(t *testing.T) {
- store, err := NewStore("file:memdb1?mode=memory&cache=shared")
+ store, err := NewStore(false, "file:memdb1?mode=memory&cache=shared")
if err != nil {
t.Errorf("Failed to initialize: %v", err)
return