dt1t and counter and refactoring using embedded interfaces
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
//"time"
|
||||
"fmt"
|
||||
"udi/counter"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@ -24,7 +25,7 @@ func NewDatabaseHandle() *DatabaseHandle {
|
||||
} else {
|
||||
db.dbh = conn
|
||||
db.initialized = true
|
||||
log.Println("Database connection opened")
|
||||
//log.Println("Database connection opened")
|
||||
}
|
||||
return &db
|
||||
}
|
||||
@ -32,16 +33,19 @@ func NewDatabaseHandle() *DatabaseHandle {
|
||||
func (self *DatabaseHandle) StoreMeasurement(measurement *Measurement) {
|
||||
if ! self.initialized {
|
||||
log.Printf("Database connection not initialized, can not store, measurement %s lost", measurement)
|
||||
counter.F("Stored")
|
||||
return
|
||||
}
|
||||
|
||||
result := self.dbh.Create(measurement)
|
||||
if result.Error != nil {
|
||||
log.Printf("Unable to insert, measurement %s lost, error: %s", measurement, result.Error)
|
||||
counter.F("Stored")
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("Successfully stored measurement")
|
||||
//log.Println("Successfully stored measurement")
|
||||
counter.S("Stored")
|
||||
}
|
||||
|
||||
func (self *DatabaseHandle) GetDeviceByLabelAndApplication(applicationLabel string, deviceLabel string) (*Device, error) {
|
||||
|
Reference in New Issue
Block a user