Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnectionClosed = errors.New("connection closed") ErrIsReadOnly = errors.New("trying to write but read-only mode is enabled") )
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection wraps a Cassandra connection (wrapper around gocql.ClusterConfig) and allow to acquire a (cached) gocql.Session. The session is returned to every call to Session() unless Connection think the session is no longer valid. In this case a new session is created on used for subsequent Session() call.
func New ¶
func New(ctx context.Context, options config.Cassandra, readOnly bool, logger zerolog.Logger, ) (*Connection, bool, error)
New creates a new Cassandra session and return if the keyspace was create by this instance.
func (*Connection) Close ¶
func (c *Connection) Close()
Close closes all Session still open. All Session acquired by Session() should be closed before this call.
func (*Connection) Session ¶
func (c *Connection) Session() (*SessionWrapper, error)
Session return a *gocql.Session, possibly using a cached one. The returned session should be short-lived. The returned session could be used for writing. If read-only mode is enabled, this function will fail with ErrIsReadOnly. Prefer SessionReadOnly for read-only access.
func (*Connection) SessionReadOnly ¶
func (c *Connection) SessionReadOnly() (*SessionWrapper, error)
SessionReadOnly return a *gocql.Session, possibly using a cached one. The returned session should be short-lived. The returned session should only be used for reading, not writing.
type SessionWrapper ¶
SessionWrapper contains a Cassandra gocql session that could be used exactly like a normal gocql.Session. Like a normal gocql.Session is should be closed when no longer used. Unlike a gocql.Session when closed, the true gocql.Session might be really closed or not. Unlike gocql.Session, this session should be short-lived. A new SessionWrapper should be acquired from Connection regularly. Especially if a query is retried, every retry should use a new SessionWrapper.
func (*SessionWrapper) Close ¶
func (s *SessionWrapper) Close()