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
- func (m QueryMock) Exec() error
- func (m QueryMock) Iter() Iterator
- func (m QueryMock) MapScan(mm map[string]interface{}) error
- func (m QueryMock) PageSize(n int) Query
- func (m QueryMock) PageState(state []byte) Query
- func (m QueryMock) Release()
- func (m QueryMock) Scan(dest ...interface{}) error
- func (m QueryMock) WithContext(ctx context.Context) Query
- 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) Query(statement string, arguments ...interface{}) Query
- 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 // WillSwitchPage detects if iterator reached end of current page and the // next page is available. WillSwitchPage() bool // PageState return the current paging state for a query which can be used // for subsequent quries to resume paging this point. PageState() []byte }
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) PageState ¶
func (m IteratorMock) PageState() []byte
PageState implements Iterator.
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.
func (IteratorMock) WillSwitchPage ¶
func (m IteratorMock) WillSwitchPage() bool
WillSwitchPage implements Iterator.
type Query ¶
type Query interface { // PageSize will tell the iterator to fetch the result in pages of size n. PageSize(n int) Query // WithContext will set the context to use during a query, it will be used // to timeout when waiting for responses from Cassandra. WithContext(ctx context.Context) Query // PageState sets the paging state for the query to resume paging from a // specific point in time. Setting this will disable to query paging for // this query, and must be used for all subsequent pages. PageState(state []byte) Query // Exec executes the query without returning any rows. Exec() error // Iter executes the query and returns an iterator capable of iterating // over all results. Iter() Iterator // MapScan executes the query, copies the columns of the first selected row // into the map pointed at by m and discards the rest. If no rows // were selected, ErrNotFound is returned. MapScan(m map[string]interface{}) error // Scan executes the query, copies the columns of the first selected row // into the values pointed at by dest and discards the rest. If no rows // were selected, ErrNotFound is returned. Scan(dest ...interface{}) error // Release releases a query back into a pool of queries. Released Queries // cannot be reused. Release() }
Query represents a CQL query.
type QueryMock ¶
type QueryMock struct {
mock.Mock
}
QueryMock is a mock Query. See github.com/maraino/go-mock.
type Session ¶
type Session interface { // Batch returns a new Batch for the Session. Batch(kind BatchKind) Batch // Close closes the Session. Close() // 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) // Query generates a new query object for interacting with the database. // Further details of the query may be tweaked using the resulting query // value before the query is executed. Query is automatically prepared if // it has not previously been executed. Query(statement string, arguments ...interface{}) Query }
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) Query ¶
func (m SessionMock) Query(statement string, arguments ...interface{}) Query
Query 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.