database.go 842 B

123456789101112131415161718192021222324252627282930
  1. package database
  2. import (
  3. "github.com/librespeed/speedtest/config"
  4. "github.com/librespeed/speedtest/database/bolt"
  5. "github.com/librespeed/speedtest/database/mysql"
  6. "github.com/librespeed/speedtest/database/postgresql"
  7. "github.com/librespeed/speedtest/database/schema"
  8. )
  9. var (
  10. DB DataAccess
  11. )
  12. type DataAccess interface {
  13. Insert(*schema.TelemetryData) error
  14. FetchByUUID(string) (*schema.TelemetryData, error)
  15. FetchLast100() ([]schema.TelemetryData, error)
  16. }
  17. func SetDBInfo(conf *config.Config) {
  18. switch conf.DatabaseType {
  19. case "postgresql":
  20. DB = postgresql.Open(conf.DatabaseHostname, conf.DatabaseUsername, conf.DatabasePassword, conf.DatabaseName)
  21. case "mysql":
  22. DB = mysql.Open(conf.DatabaseHostname, conf.DatabaseUsername, conf.DatabasePassword, conf.DatabaseName)
  23. case "bolt":
  24. DB = bolt.Open(conf.DatabaseFile)
  25. }
  26. }