Update meters call

This commit is contained in:
Nise Void 2018-06-19 15:45:27 +02:00
parent ae1d9331ad
commit 831cca0e27
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3
2 changed files with 28 additions and 10 deletions

View File

@ -123,11 +123,6 @@
"name": "public.meter", "name": "public.meter",
"alias": "me", "alias": "me",
"fields": [ "fields": [
{
"name": "fortop_uid",
"data_type": "character varying",
"size": 50
},
{ {
"name": "id", "name": "id",
"data_type": "integer", "data_type": "integer",
@ -137,6 +132,16 @@
"name": "name", "name": "name",
"data_type": "character varying", "data_type": "character varying",
"size": 255 "size": 255
},
{
"name": "source",
"data_type": "smallint",
"size": 2
},
{
"name": "uid",
"data_type": "character varying",
"size": 50
} }
] ]
} }

View File

@ -1,6 +1,7 @@
package app package app
import ( import (
"fmt"
"reflect" "reflect"
"time" "time"
@ -49,18 +50,30 @@ func GetAttributes() (list []Attribute) {
return 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 // Meter represents a single meter
type Meter struct { type Meter struct {
ID int `json:"id"` ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
FortopUID string `json:"fortop_uid"` Source Source `json:"source"`
} }
// GetMeters returns a list of all known meters // GetMeters returns a list of all known meters
func GetMeters() (list []Meter) { func GetMeters() (list []Meter) {
me := model.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) rows, err := db.Query(q)
if err != nil { if err != nil {
@ -69,7 +82,7 @@ func GetMeters() (list []Meter) {
for rows.Next() { for rows.Next() {
var meter Meter var meter Meter
err = rows.Scan(&meter.ID, &meter.Name, &meter.FortopUID) err = rows.Scan(&meter.ID, &meter.Name, &meter.Source)
if err != nil { if err != nil {
panic(err) panic(err)
} }