scylladb

package
v0.0.0-...-a019193 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package scylladb provides functionality for initializing a connection to ScyllaDB database using to gocql library.

Note: Make sure to handle errors appropriately when using this package.

Package scylladb provides an interface and implementation for a ScyllaDB session wrapper to simplify database interactions using gocql and gocqlx libraries.

Index

Constants

View Source
const (
	TimeoutCluster = 5 * time.Second

	// NumRetries represents the number of retries in the ExponentialBackoffRetryPolicy.
	NumRetries = 5

	// MinRetryDelay represents the minimum delay duration in the ExponentialBackoffRetryPolicy.
	MinRetryDelay = time.Second

	// MaxRetryDelay represents the maximum delay duration in the ExponentialBackoffRetryPolicy.
	MaxRetryDelay = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Hosts          []string          `koanf:"hosts"`
	Consistency    gocql.Consistency `koanf:"consistency"`
	Keyspace       string            `koanf:"keyspace"`
	TimeoutCluster time.Duration     `koanf:"timeout_cluster"`
	NumRetries     int               `koanf:"num_retries"`
	MinRetryDelay  time.Duration     `koanf:"min_retry_delay"`
	MaxRetryDelay  time.Duration     `koanf:"max_retry_delay"`
}

type Session

type Session struct {
	S *gocqlx.Session
}

func (*Session) AwaitSchemaAgreement

func (s *Session) AwaitSchemaAgreement(ctx context.Context) error

func (*Session) Close

func (s *Session) Close()

func (*Session) ContextQuery

func (s *Session) ContextQuery(ctx context.Context, stmt string, names []string) gocqlx.Queryx

func (*Session) ExecStmt

func (s *Session) ExecStmt(stmt string) error

func (*Session) ExecuteBatch

func (s *Session) ExecuteBatch(batch *gocql.Batch) error

func (*Session) NewBatch

func (s *Session) NewBatch(ctx context.Context, batchType gocql.BatchType) *gocql.Batch

func (*Session) Query

func (s *Session) Query(stmt string, names []string) gocqlx.Queryx

type SessionxInterface

type SessionxInterface interface {
	ContextQuery(ctx context.Context, stmt string, names []string) gocqlx.Queryx
	Query(stmt string, names []string) gocqlx.Queryx
	ExecStmt(stmt string) error
	AwaitSchemaAgreement(ctx context.Context) error
	Close()
	NewBatch(ctx context.Context, batchType gocql.BatchType) *gocql.Batch
	ExecuteBatch(batch *gocql.Batch) error
}

func New

func New(config Config) (SessionxInterface, error)

New The package defines a configuration structure (Config) and a function (New) to create and return a session interface for interacting with ScyllaDB. The New function takes a Config parameter to customize the behavior of the ScyllaDB connection.

	func main() {
		// Set up ScyllaDB configuration
		config := scylladb.Config{
			Hosts:          []string{"127.0.0.1:9042"},
			Consistency:    gocql.One,
			Keyspace:       "your_keyspace",
			TimeoutCluster: 5 * time.Second,
			NumRetries:     5,
			MinRetryDelay:  time.Second,
			MaxRetryDelay:  10 * time.Second,
		}

		// Create a new ScyllaDB session
		session, err := scylladb.New(config)
		if err != nil {
			log.Fatal("Error creating ScyllaDB session:", err)
		}
     defer session.Close()

		// Use the session to interact with ScyllaDB

	}

/**.

func NewSession

func NewSession(session *gocql.Session) SessionxInterface

func WrapSession

func WrapSession(session *gocql.Session, err error) (SessionxInterface, error)

Directories

Path Synopsis
Package scyllainitialize provides functionality for initializing a connection to ScyllaDB database using to gocql library.
Package scyllainitialize provides functionality for initializing a connection to ScyllaDB database using to gocql library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL