server: implement scylladb
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
)
|
||||
|
||||
var Session *gocql.Session
|
||||
|
||||
func InitScyllaDB() {
|
||||
cluster := gocql.NewCluster(os.Getenv("SCYLLA_CLUSTER"))
|
||||
cluster.Keyspace = os.Getenv("SCYLLA_KEYSPACE")
|
||||
|
||||
cluster.Consistency = gocql.Quorum
|
||||
|
||||
session, err := cluster.CreateSession()
|
||||
if err != nil {
|
||||
slog.Error("Failed to connect to ScyllaDB", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
Session = session
|
||||
slog.Info("Connected to ScyllaDB")
|
||||
}
|
||||
|
||||
func CloseScyllaDB() {
|
||||
if Session != nil {
|
||||
Session.Close()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user