2021-11-26 01:58:47 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gorm.io/driver/sqlite"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type dbHandler struct {
|
2021-12-13 05:16:05 +00:00
|
|
|
db *gorm.DB
|
|
|
|
cache map[string]string
|
|
|
|
states map[string]map[string]interface{}
|
|
|
|
|
2021-11-26 01:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newSqliteHandler(path string) (DBHandler, error) {
|
|
|
|
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
db.AutoMigrate(&Device{})
|
|
|
|
|
2021-12-13 05:16:05 +00:00
|
|
|
return &dbHandler{
|
|
|
|
db: db,
|
|
|
|
cache: map[string]string{},
|
|
|
|
states: map[string]map[string]interface{}{},
|
|
|
|
}, nil
|
2021-11-26 01:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// func newPostgresqlHandler(path string) (DBHandler, error) {
|
|
|
|
// dsn := "host=localhost user=user password=user_password dbname=godopudb port=5432 sslmode=disable TimeZone=Asia/Seoul"
|
|
|
|
// db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
|
|
|
// if err != nil {
|
|
|
|
// return nil, err
|
|
|
|
// }
|
|
|
|
|
|
|
|
// db.AutoMigrate(&Device{})
|
|
|
|
|
|
|
|
// return &dbHandler{db: db, cache: map[string]string{}}, nil
|
|
|
|
// }
|
|
|
|
|
|
|
|
// func (s *dbHandler) GetDevice() *Device {
|
|
|
|
// device := &Device{}
|
|
|
|
// }
|