1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-02 22:17:10 +08:00
Dejan Mijic bcc0bfdc3d
Integrate message writer service
Moved main method to top-level cmd directory. Extracted its dockerfile
as well.

Signed-off-by: Dejan Mijic <dejan@mainflux.com>
2017-09-23 01:22:21 +02:00

29 lines
962 B
Go

package cassandra
import (
"github.com/gocql/gocql"
"github.com/mainflux/mainflux/writer"
)
var _ writer.MessageRepository = (*msgRepository)(nil)
type msgRepository struct {
session *gocql.Session
}
// NewMessageRepository instantiates Cassandra message repository.
func NewMessageRepository(session *gocql.Session) writer.MessageRepository {
return &msgRepository{session}
}
func (repo *msgRepository) Save(msg writer.Message) error {
cql := `INSERT INTO messages_by_channel
(channel, id, publisher, protocol, bn, bt, bu, bv, bs, bver, n, u, v, vs, vb, vd, s, t, ut, l)
VALUES (?, now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
return repo.session.Query(cql, msg.Channel, msg.Publisher, msg.Protocol,
msg.BaseName, msg.BaseTime, msg.BaseUnit, msg.BaseValue, msg.BaseSum,
msg.Version, msg.Name, msg.Unit, msg.Value, msg.StringValue, msg.BoolValue,
msg.DataValue, msg.ValueSum, msg.Time, msg.UpdateTime, msg.Link).Exec()
}