2021-11-26 01:58:47 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
// 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(device *Device) error
|
|
|
|
GetSID(sname string) (string, error)
|
|
|
|
GetServiceForDevice(did string) (string, error)
|
2021-12-13 05:16:05 +00:00
|
|
|
GetDeviceID(dname string) (*Device, error)
|
|
|
|
StatusCheck(did string, new map[string]interface{}) bool
|
2021-11-26 01:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var db DBHandler
|
|
|
|
|
|
|
|
func GetDBHandler(dbtype, path string) (DBHandler, error) {
|
|
|
|
if db == nil {
|
2021-12-13 05:16:05 +00:00
|
|
|
db, _ = newSqliteHandler(path)
|
|
|
|
return db, nil
|
2021-11-26 01:58:47 +00:00
|
|
|
}
|
|
|
|
return db, nil
|
|
|
|
}
|