server: use postgres instead of scylla, easier to host
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
var Pool *pgxpool.Pool
|
||||
|
||||
func InitPostgres(ctx context.Context) {
|
||||
pool, err := pgxpool.New(ctx, os.Getenv("DATABASE_URL"))
|
||||
if err != nil {
|
||||
slog.Error("Failed to connect to Postgres", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
Pool = pool
|
||||
slog.Info("Connected to Postgres")
|
||||
}
|
||||
|
||||
func ClosePostgres() {
|
||||
if Pool != nil {
|
||||
Pool.Close()
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
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