2017-04-10 18:54:12 +02:00
|
|
|
package all
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/database"
|
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Connection struct {
|
|
|
|
database.Connection
|
|
|
|
list []database.Connection
|
|
|
|
}
|
|
|
|
|
|
|
|
func Connect(configuration interface{}) (database.Connection, error) {
|
|
|
|
var list []database.Connection
|
|
|
|
allConnection := configuration.(map[string][]interface{})
|
|
|
|
for dbType, conn := range database.Adapters {
|
|
|
|
dbConfigs := allConnection[dbType]
|
|
|
|
for _, config := range dbConfigs {
|
|
|
|
connected, err := conn(config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if connected == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
list = append(list, connected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &Connection{list: list}, nil
|
|
|
|
}
|
2017-04-18 01:48:38 +02:00
|
|
|
|
|
|
|
func (conn *Connection) InsertNode(node *runtime.Node) {
|
2017-04-10 18:54:12 +02:00
|
|
|
for _, item := range conn.list {
|
2017-04-18 01:48:38 +02:00
|
|
|
item.InsertNode(node)
|
2017-04-10 18:54:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 13:55:02 +02:00
|
|
|
func (conn *Connection) InsertLink(link *runtime.Link, time time.Time) {
|
|
|
|
for _, item := range conn.list {
|
|
|
|
item.InsertLink(link, time)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 01:48:38 +02:00
|
|
|
func (conn *Connection) InsertGlobals(stats *runtime.GlobalStats, time time.Time) {
|
2017-04-10 18:54:12 +02:00
|
|
|
for _, item := range conn.list {
|
2017-04-18 01:48:38 +02:00
|
|
|
item.InsertGlobals(stats, time)
|
2017-04-10 18:54:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 20:42:06 +02:00
|
|
|
func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
|
2017-04-10 18:54:12 +02:00
|
|
|
for _, item := range conn.list {
|
2017-04-17 20:42:06 +02:00
|
|
|
item.PruneNodes(deleteAfter)
|
2017-04-10 18:54:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *Connection) Close() {
|
|
|
|
for _, item := range conn.list {
|
|
|
|
item.Close()
|
|
|
|
}
|
|
|
|
}
|