init
This commit is contained in:
33
internal/adapter/storages/scylla/db.go
Normal file
33
internal/adapter/storages/scylla/db.go
Normal file
@ -0,0 +1,33 @@
|
||||
package scylla
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/aykhans/oh-my-chat/internal/adapter/config"
|
||||
"github.com/gocql/gocql"
|
||||
)
|
||||
|
||||
func NewDB(config *config.ScyllaConfig) (*gocql.Session, error) {
|
||||
cluster := gocql.NewCluster(config.Hosts...)
|
||||
cluster.Keyspace = config.Keyspace
|
||||
cluster.Consistency = gocql.LocalQuorum
|
||||
cluster.Authenticator = gocql.PasswordAuthenticator{
|
||||
Username: config.User,
|
||||
Password: config.Password,
|
||||
}
|
||||
cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(
|
||||
gocql.DCAwareRoundRobinPolicy(config.DataCenter),
|
||||
)
|
||||
|
||||
var session *gocql.Session
|
||||
var err error
|
||||
for range 20 {
|
||||
session, err = cluster.CreateSession()
|
||||
if err == nil {
|
||||
return session, nil
|
||||
}
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS messages;
|
@ -0,0 +1,8 @@
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
chat_id UUID, -- Partition key
|
||||
user_id UUID,
|
||||
content text, -- Clustering column
|
||||
type text, -- Clustering column
|
||||
created_at timestamp, -- Clustering column
|
||||
PRIMARY KEY (chat_id, created_at, content, type)
|
||||
) WITH CLUSTERING ORDER BY (created_at DESC);
|
@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS user_chats;
|
@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS user_chats (
|
||||
user_id UUID, -- Partition key
|
||||
chat_id UUID, -- Clustering column
|
||||
blocked boolean,
|
||||
created_at timestamp,
|
||||
PRIMARY KEY (user_id, created_at, chat_id, blocked)
|
||||
);
|
23
internal/adapter/storages/scylla/repository/message.go
Normal file
23
internal/adapter/storages/scylla/repository/message.go
Normal file
@ -0,0 +1,23 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aykhans/oh-my-chat/internal/core/domain"
|
||||
"github.com/gocql/gocql"
|
||||
)
|
||||
|
||||
type MessageRepository struct {
|
||||
db *gocql.Session
|
||||
}
|
||||
|
||||
func NewMessageRepository(db *gocql.Session) *MessageRepository {
|
||||
return &MessageRepository{db}
|
||||
}
|
||||
|
||||
func (messageRepository *MessageRepository) CreateMessage(
|
||||
ctx context.Context,
|
||||
message *domain.Message,
|
||||
) (*domain.Message, error) {
|
||||
return nil, nil
|
||||
}
|
Reference in New Issue
Block a user