mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-27 13:48:49 +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>
46 lines
919 B
Go
46 lines
919 B
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
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
|
|
}
|