summaryrefslogtreecommitdiff
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
parentstart with last 10 minutes (diff)
hub: add hacky untested MySql support
-rw-r--r--src/hub/Makefile2
-rw-r--r--src/hub/src/spreadspace.org/sfive-hub/s5hub.go3
-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
5 files changed, 32 insertions, 15 deletions
diff --git a/src/hub/Makefile b/src/hub/Makefile
index 758e3d4..d2b6f12 100644
--- a/src/hub/Makefile
+++ b/src/hub/Makefile
@@ -41,6 +41,8 @@ getlibs:
$(GOCMD) get "github.com/mattn/go-sqlite3"
$(GOCMD) get "github.com/zenazn/goji"
$(GOCMD) get "code.google.com/p/go-uuid/uuid"
+ $(GOCMD) get "github.com/go-sql-driver/mysql"
+ $(GOCMD) get "github.com/ziutek/mymysql/godrv"
build: export GOPATH=$(curdir)
build: getlibs
diff --git a/src/hub/src/spreadspace.org/sfive-hub/s5hub.go b/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
index e64c665..4b45b15 100644
--- a/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
+++ b/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
@@ -13,6 +13,7 @@ var s5hl = log.New(os.Stderr, "[s5hub]\t", log.LstdFlags)
func main() {
db := flag.String("db", "/var/lib/sfive/db.sqlite", "path to the sqlite3 database file")
+ dbMysql = flag.Bool("db-mysql", false, "use MySQL connector")
pipe := flag.String("pipe", "/var/run/sfive/pipe", "path to the unix pipe for the pipeserver")
ppipe := flag.String("pipegram", "/var/run/sfive/pipegram", "path to the unix datagram pipe for the pipeserver")
startPipe := flag.Bool("start-pipe-server", true, "start a connection oriented pipe server; see option pipe")
@@ -30,7 +31,7 @@ func main() {
return
}
- server, err := sfive.NewServer(*db)
+ server, err := sfive.NewServer(*dbMysql, *db)
if err != nil {
s5hl.Fatalf("failed to initialize: %v", err)
}
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