mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-09 19:29:29 +08:00

* Fix logger message in http service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Inline query and error handling in cassandra writer Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix comments and import statement in writer interface Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add reader common interface and shared HTTP API Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add Cassandra reader implementation Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for cassandra reader Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add swagger doc and readme for readers Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update make file Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add docker-compose configuration for cassandra reader Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add readme file to cassandra reader Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
39 lines
836 B
Go
39 lines
836 B
Go
package cassandra
|
|
|
|
import "github.com/gocql/gocql"
|
|
|
|
const table = `CREATE TABLE IF NOT EXISTS messages (
|
|
id uuid PRIMARY KEY,
|
|
channel bigint,
|
|
publisher bigint,
|
|
protocol text,
|
|
name text,
|
|
unit text,
|
|
value double,
|
|
string_value text,
|
|
bool_value boolean,
|
|
data_value text,
|
|
value_sum double,
|
|
time double,
|
|
update_time double,
|
|
link text
|
|
)`
|
|
|
|
// Connect establishes connection to the Cassandra cluster.
|
|
func Connect(hosts []string, keyspace string) (*gocql.Session, error) {
|
|
cluster := gocql.NewCluster(hosts...)
|
|
cluster.Keyspace = keyspace
|
|
cluster.Consistency = gocql.Quorum
|
|
|
|
session, err := cluster.CreateSession()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := session.Query(table).Exec(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return session, nil
|
|
}
|