Return empty array when there're no rows
This commit is contained in:
parent
3d37331fce
commit
79c7bf3851
|
|
@ -1,5 +1,7 @@
|
|||
package services
|
||||
|
||||
import "database/sql"
|
||||
|
||||
type DashboardsService struct {
|
||||
ctx *Context
|
||||
}
|
||||
|
|
@ -16,6 +18,10 @@ func (s *DashboardsService) GetList() ([]DashboardItem, error) {
|
|||
rows, err := s.ctx.DB.Query("SELECT id, name, contents FROM dashboards")
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package services
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SensorValuesService struct {
|
||||
ctx *Context
|
||||
|
|
@ -29,6 +32,10 @@ func (s *SensorValuesService) GetList(sensorId int64, from int64, to int64) ([]s
|
|||
rows, err := s.ctx.DB.Query("SELECT timestamp, value FROM sensor_values WHERE sensor_id = ? AND timestamp > ? AND timestamp < ? ORDER BY timestamp ASC", sensorId, from, to)
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return values, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package services
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"database/sql"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
|
|
@ -21,6 +22,10 @@ func (s *SensorsService) GetList() ([]SensorItem, error) {
|
|||
rows, err := s.ctx.DB.Query("SELECT id, name, auth_key FROM sensors")
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return sensors, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue