Migrate code from Go branch to new repo

This commit is contained in:
Maddie Zhan
2020-06-02 17:47:39 +08:00
commit fad1302a73
40 changed files with 14952 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
package database
import (
"github.com/librespeed/speedtest/config"
"github.com/librespeed/speedtest/database/bolt"
"github.com/librespeed/speedtest/database/mysql"
"github.com/librespeed/speedtest/database/postgresql"
"github.com/librespeed/speedtest/database/schema"
)
var (
DB DataAccess
)
type DataAccess interface {
Insert(*schema.TelemetryData) error
FetchByUUID(string) (*schema.TelemetryData, error)
FetchLast100() ([]schema.TelemetryData, error)
}
func SetDBInfo(conf *config.Config) {
switch conf.DatabaseType {
case "postgresql":
DB = postgresql.Open(conf.DatabaseHostname, conf.DatabaseUsername, conf.DatabasePassword, conf.DatabaseName)
case "mysql":
DB = mysql.Open(conf.DatabaseHostname, conf.DatabaseUsername, conf.DatabasePassword, conf.DatabaseName)
case "bolt":
DB = bolt.Open(conf.DatabaseFile)
}
}