ETRI_SMARTFARM_POC/model/interface.go

34 lines
973 B
Go
Raw Normal View History

2021-11-16 12:28:52 +00:00
package model
import (
"io"
)
// func newDBHandler(dbtype, path string) (*gorm.DB, error) {
// if dbtype == "sqlite" {
// return gorm.Open(sqlite.Open("./test.db"), &gorm.Config{})
// } else {
// dsn := "host=localhost user=user password=user_password dbname=godopudb port=5432 sslmode=disable TimeZone=Asia/Seoul"
// return gorm.Open(postgres.Open(dsn), &gorm.Config{})
// }
// }
type DBHandler interface {
GetDevices() ([]*Device, int, error)
AddDevice(d *Device) error
AddController(r io.Reader) (*Controller, error)
GetControllers() ([]*Controller, error)
IsExistController(cid string) bool
GetServices() ([]*Service, error)
AddService(name string) error
UpdateService(name, addr string) (*Service, error)
GetAddr(sid string) (string, error)
2021-11-25 01:11:47 +00:00
GetSID(name string) (string, error)
IsExistService(name string) bool
2021-11-16 12:28:52 +00:00
}
func NewDBHandler(dbtype, path string) (DBHandler, error) {
2021-11-17 15:11:54 +00:00
return newSqliteHandler(path)
// return newPostgresqlHandler(path)
2021-11-16 12:28:52 +00:00
}