2016-10-03 17:55:37 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2017-04-10 16:54:12 +00:00
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
2016-10-03 17:55:37 +00:00
|
|
|
)
|
|
|
|
|
2017-04-10 16:54:12 +00:00
|
|
|
// Connection interface to use for implementation in e.g. influxdb
|
|
|
|
type Connection interface {
|
2017-04-17 23:48:38 +00:00
|
|
|
// InsertNode stores statistics per node
|
|
|
|
InsertNode(node *runtime.Node)
|
2017-04-17 18:42:06 +00:00
|
|
|
|
2017-09-27 11:55:02 +00:00
|
|
|
// InsertLink stores statistics per link
|
|
|
|
InsertLink(*runtime.Link, time.Time)
|
|
|
|
|
2017-04-17 23:48:38 +00:00
|
|
|
// InsertGlobals stores global statistics
|
2017-11-21 14:12:06 +00:00
|
|
|
InsertGlobals(*runtime.GlobalStats, time.Time, string)
|
2016-12-15 10:10:09 +00:00
|
|
|
|
2017-04-17 18:42:06 +00:00
|
|
|
// PruneNodes prunes historical per-node data
|
|
|
|
PruneNodes(deleteAfter time.Duration)
|
2016-10-03 17:55:37 +00:00
|
|
|
|
2017-04-17 18:42:06 +00:00
|
|
|
// Close closes the database connection
|
2017-04-10 16:54:12 +00:00
|
|
|
Close()
|
2016-10-03 17:55:37 +00:00
|
|
|
}
|
2016-12-15 08:52:12 +00:00
|
|
|
|
2017-04-10 16:54:12 +00:00
|
|
|
// Connect function with config to get DB connection interface
|
2017-12-31 04:26:17 +00:00
|
|
|
type Connect func(config map[string]interface{}) (Connection, error)
|
2016-10-03 17:55:37 +00:00
|
|
|
|
2017-04-17 18:42:06 +00:00
|
|
|
// Adapters is the list of registered database adapters
|
2017-04-10 16:54:12 +00:00
|
|
|
var Adapters = map[string]Connect{}
|
2016-10-03 17:55:37 +00:00
|
|
|
|
2017-04-17 18:42:06 +00:00
|
|
|
func RegisterAdapter(name string, n Connect) {
|
2017-04-10 16:54:12 +00:00
|
|
|
Adapters[name] = n
|
2016-10-03 17:55:37 +00:00
|
|
|
}
|