Update meters call
This commit is contained in:
parent
ae1d9331ad
commit
831cca0e27
@ -123,11 +123,6 @@
|
||||
"name": "public.meter",
|
||||
"alias": "me",
|
||||
"fields": [
|
||||
{
|
||||
"name": "fortop_uid",
|
||||
"data_type": "character varying",
|
||||
"size": 50
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"data_type": "integer",
|
||||
@ -137,6 +132,16 @@
|
||||
"name": "name",
|
||||
"data_type": "character varying",
|
||||
"size": 255
|
||||
},
|
||||
{
|
||||
"name": "source",
|
||||
"data_type": "smallint",
|
||||
"size": 2
|
||||
},
|
||||
{
|
||||
"name": "uid",
|
||||
"data_type": "character varying",
|
||||
"size": 50
|
||||
}
|
||||
]
|
||||
}
|
||||
|
23
app/pq.go
23
app/pq.go
@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
@ -49,18 +50,30 @@ func GetAttributes() (list []Attribute) {
|
||||
return
|
||||
}
|
||||
|
||||
type Source string
|
||||
|
||||
func (s *Source) Scan(v interface{}) error {
|
||||
i, ok := v.(int64)
|
||||
if !ok {
|
||||
return fmt.Errorf(`Unsupported scan, storing driver.Value type %T into type %T`, v, s)
|
||||
}
|
||||
|
||||
*s = Source([]string{``, `Fortop`, `Envitron`}[i])
|
||||
return nil
|
||||
}
|
||||
|
||||
// Meter represents a single meter
|
||||
type Meter struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
FortopUID string `json:"fortop_uid"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Source Source `json:"source"`
|
||||
}
|
||||
|
||||
// GetMeters returns a list of all known meters
|
||||
func GetMeters() (list []Meter) {
|
||||
me := model.Meter()
|
||||
|
||||
q := me.Select(me.ID, me.Name, me.FortopUID)
|
||||
q := me.Select(me.ID, me.Name, me.Source)
|
||||
|
||||
rows, err := db.Query(q)
|
||||
if err != nil {
|
||||
@ -69,7 +82,7 @@ func GetMeters() (list []Meter) {
|
||||
|
||||
for rows.Next() {
|
||||
var meter Meter
|
||||
err = rows.Scan(&meter.ID, &meter.Name, &meter.FortopUID)
|
||||
err = rows.Scan(&meter.ID, &meter.Name, &meter.Source)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user