fix(cli/db): remove obsolete db subcommand
This commit is contained in:
@ -31,6 +31,13 @@ func Compression(measuredValues []*types.MeasuredValue) []*types.MeasuredValue {
|
||||
now := format.FormatedTime()
|
||||
|
||||
for _, measuredValue := range measuredValues {
|
||||
|
||||
// If the sensor id does not exist in the map, a new map is initialized,
|
||||
// which can assume measured value types as the key. Behind this key there
|
||||
// is a pointer which refers to a measured value in the memory. This new map
|
||||
// is added to the map "lastMeasuredValuesBySensors" under the sensor ID.
|
||||
// This makes it possible to store one measured value per measured value
|
||||
// type per sensor.
|
||||
if _, ok := lastMeasuredValuesBySensors[measuredValue.SensorID]; !ok {
|
||||
lastMeasuredValuesBySensors[measuredValue.SensorID] = make(map[types.MeasuredValueType]*types.MeasuredValue, 0)
|
||||
}
|
||||
@ -93,21 +100,27 @@ func Round(measuredValues []*types.MeasuredValue, round float64) {
|
||||
}
|
||||
}
|
||||
|
||||
// Write measured values to the given storage endpoint url. The scheme must be
|
||||
// matched to a provider, if the scheme is not implemented, the function
|
||||
// returns an error
|
||||
// Write measured values to the given storage endpoint url. If the storage
|
||||
// provider defined to a file, the data will be overwritten. If a database
|
||||
// provider is used, the data is simply added without deleting the existing
|
||||
// data. The scheme must be matched to a storage provider, if the scheme is not
|
||||
// implemented, the function returns an error
|
||||
func Write(ctx context.Context, measuredValues []*types.MeasuredValue, storageEndpoint *url.URL) error {
|
||||
switch storageEndpoint.Scheme {
|
||||
case "file":
|
||||
measuredValueLogfile := logfile.New(storageEndpoint.Path)
|
||||
return measuredValueLogfile.Write(measuredValues)
|
||||
storedMeasuredValues, err := measuredValueLogfile.Read()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
storedMeasuredValues = append(storedMeasuredValues, measuredValues...)
|
||||
return measuredValueLogfile.Write(storedMeasuredValues)
|
||||
case "postgres":
|
||||
database, err := db.New(storageEndpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer database.Close()
|
||||
|
||||
if err := database.InsertMeasuredValues(ctx, measuredValues); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user