Documentation ¶
Overview ¶
Package gockle simplifies and mocks github.com/gocql/gocql. It provides simple interfaces to insert, query, and mutate Cassandra data, as well as get basic keyspace and table metadata.
The entry points are NewSession and NewSimpleSession. Call them to get a Session. Session interacts with the database. It executes queries and batched queries and iterates result rows. Closing the Session closes the underlying gocql.Session, including the one passed to NewSimpleSession.
Mocks are provided for testing use of Batch, Iterator, and Session.
Tx is short for transaction.
The name gockle comes from a pronunciation of gocql.
Index ¶
- Constants
- type Batch
- type BatchKind
- type BatchMock
- type Iterator
- type IteratorMock
- type Query
- type QueryMock
- type Session
- type SessionMock
- func (m SessionMock) Batch(kind BatchKind) Batch
- func (m SessionMock) Close()
- func (m SessionMock) Columns(keyspace, table string) (map[string]gocql.TypeInfo, error)
- func (m SessionMock) Exec(statement string, arguments ...interface{}) error
- func (m SessionMock) Scan(statement string, results []interface{}, arguments ...interface{}) error
- func (m SessionMock) ScanIterator(statement string, arguments ...interface{}) Iterator
- func (m SessionMock) ScanMap(statement string, results map[string]interface{}, arguments ...interface{}) error
- func (m SessionMock) ScanMapSlice(statement string, arguments ...interface{}) ([]map[string]interface{}, error)
- func (m SessionMock) ScanMapTx(statement string, results map[string]interface{}, arguments ...interface{}) (bool, error)
- func (m SessionMock) Tables(keyspace string) ([]string, error)
Constants ¶
const ColumnApplied = "[applied]"
ColumnApplied is the name of a special column that has a bool that indicates whether a conditional statement was applied.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch interface { // Add adds the query for statement and arguments. Add(statement string, arguments ...interface{}) // Exec executes the queries in the order they were added. Exec() error // ExecTx executes the queries in the order they were added. It returns a slice // of maps from columns to values, the maps corresponding to all the conditional // queries, and ordered in the same relative order. The special column // ColumnApplied has a bool that indicates whether the conditional statement was // applied. If a conditional statement was not applied, the current values for // the columns are put into the map. ExecTx() ([]map[string]interface{}, error) }
Batch is an ordered collection of CQL queries.
type BatchKind ¶
type BatchKind byte
BatchKind is the kind of Batch. The choice of kind mostly affects performance.
const ( // BatchLogged queries are atomic. Queries are only isolated within a single // partition. BatchLogged BatchKind = 0 // BatchUnlogged queries are not atomic. Atomic queries spanning multiple partitions cost performance. BatchUnlogged BatchKind = 1 // BatchCounter queries update counters and are not idempotent. BatchCounter BatchKind = 2 )
Kinds of batches.
type BatchMock ¶
type BatchMock struct {
mock.Mock
}
BatchMock is a mock Batch. See github.com/maraino/go-mock.
type Iterator ¶
type Iterator interface { // Close closes the Iterator. Close() error // Scan puts the current result row in results and returns whether there are // more result rows. Scan(results ...interface{}) bool // ScanMap puts the current result row in results and returns whether there are // more result rows. ScanMap(results map[string]interface{}) bool }
Iterator iterates CQL query result rows.
type IteratorMock ¶
type IteratorMock struct {
mock.Mock
}
IteratorMock is a mock Iterator. See github.com/maraino/go-mock.
func (IteratorMock) Scan ¶
func (m IteratorMock) Scan(results ...interface{}) bool
Scan implements Iterator.
func (IteratorMock) ScanMap ¶
func (m IteratorMock) ScanMap(results map[string]interface{}) bool
ScanMap implements Iterator.
type Query ¶
type Query interface { Bind(...interface{}) Query Exec() error Iter() IterAPI Scan(...interface{}) error ScanCAS(...interface{}) (bool, error) }
QueryAPI allows gomock mock of gocql.Query
type QueryMock ¶
type QueryMock struct {
mock.Mock
}
func (QueryMock) Iter ¶
func (m QueryMock) Iter() IteratorMock
type Session ¶
type Session interface { // Batch returns a new Batch for the Session. Batch(kind BatchKind) Batch // Close closes the Session. Close() // Query generates a new query object for interacting witht the database. Query(string, ...interface{}) Query // Columns returns a map from column names to types for keyspace and table. // Schema changes during a session are not reflected; you must open a new // Session to observe them. Columns(keyspace, table string) (map[string]gocql.TypeInfo, error) // Exec executes the query for statement and arguments. Exec(statement string, arguments ...interface{}) error // Scan executes the query for statement and arguments and puts the first // result row in results. Scan(statement string, results []interface{}, arguments ...interface{}) error // ScanIterator executes the query for statement and arguments and returns an // Iterator for the results. ScanIterator(statement string, arguments ...interface{}) Iterator // ScanMap executes the query for statement and arguments and puts the first // result row in results. ScanMap(statement string, results map[string]interface{}, arguments ...interface{}) error // ScanMapSlice executes the query for statement and arguments and returns all // the result rows. ScanMapSlice(statement string, arguments ...interface{}) ([]map[string]interface{}, error) // ScanMapTx executes the query for statement and arguments as a lightweight // transaction. If the query is not applied, it puts the current values for the // conditional columns in results. It returns whether the query is applied. ScanMapTx(statement string, results map[string]interface{}, arguments ...interface{}) (bool, error) // Tables returns the table names for keyspace. Schema changes during a session // are not reflected; you must open a new Session to observe them. Tables(keyspace string) ([]string, error) }
Session is a Cassandra connection. The Query methods run CQL queries. The Columns and Tables methods provide simple metadata.
func NewSimpleSession ¶
NewSimpleSession returns a new Session for hosts. It uses native protocol version 4.
type SessionMock ¶
type SessionMock struct {
mock.Mock
}
SessionMock is a mock Session. See github.com/maraino/go-mock.
func (SessionMock) Batch ¶
func (m SessionMock) Batch(kind BatchKind) Batch
Batch implements Session.
func (SessionMock) Exec ¶
func (m SessionMock) Exec(statement string, arguments ...interface{}) error
Exec implements Session.
func (SessionMock) Scan ¶
func (m SessionMock) Scan(statement string, results []interface{}, arguments ...interface{}) error
Scan implements Session.
func (SessionMock) ScanIterator ¶
func (m SessionMock) ScanIterator(statement string, arguments ...interface{}) Iterator
ScanIterator implements Session.
func (SessionMock) ScanMap ¶
func (m SessionMock) ScanMap(statement string, results map[string]interface{}, arguments ...interface{}) error
ScanMap implements Session.
func (SessionMock) ScanMapSlice ¶
func (m SessionMock) ScanMapSlice(statement string, arguments ...interface{}) ([]map[string]interface{}, error)
ScanMapSlice implements Session.