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
- type Config
- type Session
- func (s *Session) AwaitSchemaAgreement(ctx context.Context) error
- func (s *Session) Close()
- func (s *Session) ContextQuery(ctx context.Context, stmt string, names []string) gocqlx.Queryx
- func (s *Session) ExecStmt(stmt string) error
- func (s *Session) ExecuteBatch(batch *gocql.Batch) error
- func (s *Session) NewBatch(ctx context.Context, batchType gocql.BatchType) *gocql.Batch
- func (s *Session) Query(stmt string, names []string) gocqlx.Queryx
- type SessionxInterface
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 (*Session) ContextQuery ¶
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. |
Click to show internal directories.
Click to hide internal directories.