Remove datapoint from trigger
This commit is contained in:
parent
ac7ffcda23
commit
7990f1f419
5 changed files with 52 additions and 11 deletions
15
datapoint.go
15
datapoint.go
|
|
@ -27,6 +27,7 @@ type Datapoint struct {
|
|||
LastValue time.Time `db:"last_value"`
|
||||
DatapointValueJSON []byte `db:"datapoint_value_json"`
|
||||
LastDatapointValue DatapointValue
|
||||
Found bool
|
||||
}
|
||||
|
||||
type DatapointValue struct {
|
||||
|
|
@ -177,6 +178,7 @@ func DatapointsRetrieve() (dps []Datapoint, err error) { // {{{
|
|||
dp.Name = res.Name
|
||||
dp.Datatype = res.Datatype
|
||||
dp.LastValue = res.LastValue
|
||||
dp.Found = true
|
||||
|
||||
if res.VID.Valid {
|
||||
dpv.ID = int(res.VID.Int64)
|
||||
|
|
@ -196,16 +198,25 @@ func DatapointRetrieve(id int, name string) (dp Datapoint, err error) { // {{{
|
|||
var query string
|
||||
var param any
|
||||
if id > 0 {
|
||||
query = `SELECT * FROM datapoint WHERE id = $1`
|
||||
query = `SELECT *, true AS found FROM datapoint WHERE id = $1`
|
||||
param = id
|
||||
dp.ID = id
|
||||
} else {
|
||||
query = `SELECT * FROM datapoint WHERE name = $1`
|
||||
query = `SELECT *, true AS found FROM datapoint WHERE name = $1`
|
||||
param = name
|
||||
}
|
||||
|
||||
row := service.Db.Conn.QueryRowx(query, param)
|
||||
err = row.StructScan(&dp)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
dp = Datapoint{
|
||||
Name: name,
|
||||
}
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
err = we.Wrap(err).WithData(name)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue