add beginning of CLI app and some backend fixes.
This commit is contained in:
@@ -2,6 +2,7 @@ package mysql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"git.aiterp.net/lucifer/new-server/models"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
@@ -66,6 +67,8 @@ func (r *DeviceRepo) FetchByReference(ctx context.Context, kind models.Reference
|
||||
q = q.Where(sq.Eq{"id": strings.Split(value, ",")})
|
||||
case models.RKBridgeID:
|
||||
q = q.Where(sq.Eq{"bridge_id": strings.Split(value, ",")})
|
||||
case models.RKName:
|
||||
q = q.Where(sq.Like{"name": value})
|
||||
case models.RKTag:
|
||||
allTags := strings.Split(strings.ReplaceAll(strings.ReplaceAll(value, "-", ",-"), "+", ",+"), ",")
|
||||
optionalTags := make([]string, 0, len(allTags))
|
||||
@@ -91,8 +94,12 @@ func (r *DeviceRepo) FetchByReference(ctx context.Context, kind models.Reference
|
||||
return []models.Device{}, nil
|
||||
}
|
||||
|
||||
query, args, err := q.ToSql()
|
||||
query, args, err := q.OrderBy("name", "id").ToSql()
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return []models.Device{}, nil
|
||||
}
|
||||
|
||||
return nil, dbErr(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user