mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Change mainflux version from 0.4.0 to 0.5.0 Signed-off-by: Ivan Milošević <iva@blokovi.com>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package cassandra
|
|
|
|
import (
|
|
"github.com/gocql/gocql"
|
|
"github.com/mainflux/mainflux"
|
|
"github.com/mainflux/mainflux/writers"
|
|
)
|
|
|
|
var _ writers.MessageRepository = (*cassandraRepository)(nil)
|
|
|
|
type cassandraRepository struct {
|
|
session *gocql.Session
|
|
}
|
|
|
|
// New instantiates Cassandra message repository.
|
|
func New(session *gocql.Session) writers.MessageRepository {
|
|
return &cassandraRepository{session}
|
|
}
|
|
|
|
func (cr *cassandraRepository) Save(msg mainflux.Message) error {
|
|
cql := `INSERT INTO messages (id, channel, publisher, protocol, name, unit,
|
|
value, string_value, bool_value, data_value, value_sum, time,
|
|
update_time, link)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
id := gocql.TimeUUID()
|
|
|
|
return cr.session.Query(cql, id, msg.GetChannel(), msg.GetPublisher(),
|
|
msg.GetProtocol(), msg.GetName(), msg.GetUnit(), msg.GetValue(),
|
|
msg.GetStringValue(), msg.GetBoolValue(), msg.GetDataValue(),
|
|
msg.GetValueSum(), msg.GetTime(), msg.GetUpdateTime(), msg.GetLink()).Exec()
|
|
}
|