gockle

package module
v0.0.0-...-5486f26 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: MIT Imports: 4 Imported by: 0

README

gockle

Documentation Build Report Test Coverage

forked from https://github.com/willfaught/gockle

commit 40e207 is referenced by rtfb@25a7eea thanks!

Note: Test coverage is low because there is no Cassandra database for the tests to use. Providing one yields 97.37% test coverage. Some code is uncovered because gocql cannot be mocked. This is one difficulty your code avoids by using gockle.

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

View Source
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 an autogenerated mock type for the Batch type

func (*BatchMock) Add

func (_m *BatchMock) Add(statement string, arguments ...interface{})

Add provides a mock function with given fields: statement, arguments

func (*BatchMock) Exec

func (_m *BatchMock) Exec() error

Exec provides a mock function with given fields:

func (*BatchMock) ExecTx

func (_m *BatchMock) ExecTx() ([]map[string]interface{}, error)

ExecTx provides a mock function with given fields:

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 an autogenerated mock type for the Iterator type

func (*IteratorMock) Close

func (_m *IteratorMock) Close() error

Close provides a mock function with given fields:

func (*IteratorMock) PageState

func (_m *IteratorMock) PageState() []byte

PageState provides a mock function with given fields:

func (*IteratorMock) Scan

func (_m *IteratorMock) Scan(results ...interface{}) bool

Scan provides a mock function with given fields: results

func (*IteratorMock) ScanMap

func (_m *IteratorMock) ScanMap(results map[string]interface{}) bool

ScanMap provides a mock function with given fields: results

func (*IteratorMock) WillSwitchPage

func (_m *IteratorMock) WillSwitchPage() bool

WillSwitchPage provides a mock function with given fields:

type Query

type Query interface {
	// Consistency sets the consistency level for this query. If no consistency
	// level have been set, the default consistency level of the cluster
	// is used.
	Consistency(c gocql.Consistency) Query
	// PageSize will tell the iterator to fetch the result in pages of size n.
	// This is useful for iterating over large result sets, but setting the
	// page size too low might decrease the performance. This feature is only
	// available in Cassandra 2 and onwards.
	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.
	//
	// Example:
	//              qry := session.Query("SELECT * FROM my_table")
	//              qry.Exec()
	//              qry.Release()
	Release()
}

Query represents a CQL query.

type QueryMock

type QueryMock struct {
	mock.Mock
}

Query is an autogenerated mock type for the Query type

func (*QueryMock) Consistency

func (_m *QueryMock) Consistency(c gocql.Consistency) Query

Consistency provides a mock function with given fields: c

func (*QueryMock) Exec

func (_m *QueryMock) Exec() error

Exec provides a mock function with given fields:

func (*QueryMock) Iter

func (_m *QueryMock) Iter() Iterator

Iter provides a mock function with given fields:

func (*QueryMock) MapScan

func (_m *QueryMock) MapScan(m map[string]interface{}) error

MapScan provides a mock function with given fields: m

func (*QueryMock) PageSize

func (_m *QueryMock) PageSize(n int) Query

PageSize provides a mock function with given fields: n

func (*QueryMock) PageState

func (_m *QueryMock) PageState(state []byte) Query

PageState provides a mock function with given fields: state

func (*QueryMock) Release

func (_m *QueryMock) Release()

Release provides a mock function with given fields:

func (*QueryMock) Scan

func (_m *QueryMock) Scan(dest ...interface{}) error

Scan provides a mock function with given fields: dest

func (*QueryMock) WithContext

func (_m *QueryMock) WithContext(ctx context.Context) Query

WithContext provides a mock function with given fields: ctx

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 NewSession

func NewSession(s *gocql.Session) Session

NewSession returns a new Session for s.

func NewSimpleSession

func NewSimpleSession(hosts ...string) (Session, error)

NewSimpleSession returns a new Session for hosts. It uses native protocol version 4.

type SessionMock

type SessionMock struct {
	mock.Mock
}

SessionMock is an autogenerated mock type for the Session type

func (*SessionMock) Batch

func (_m *SessionMock) Batch(kind BatchKind) Batch

BatchMock provides a mock function with given fields: kind

func (*SessionMock) Close

func (_m *SessionMock) Close()

Close provides a mock function with given fields:

func (*SessionMock) Columns

func (_m *SessionMock) Columns(keyspace string, table string) (map[string]gocql.TypeInfo, error)

Columns provides a mock function with given fields: keyspace, table

func (*SessionMock) Exec

func (_m *SessionMock) Exec(statement string, arguments ...interface{}) error

Exec provides a mock function with given fields: statement, arguments

func (*SessionMock) Query

func (_m *SessionMock) Query(statement string, arguments ...interface{}) Query

Query provides a mock function with given fields: statement, arguments

func (*SessionMock) Scan

func (_m *SessionMock) Scan(statement string, results []interface{}, arguments ...interface{}) error

Scan provides a mock function with given fields: statement, results, arguments

func (*SessionMock) ScanIterator

func (_m *SessionMock) ScanIterator(statement string, arguments ...interface{}) Iterator

ScanIterator provides a mock function with given fields: statement, arguments

func (*SessionMock) ScanMap

func (_m *SessionMock) ScanMap(statement string, results map[string]interface{}, arguments ...interface{}) error

ScanMap provides a mock function with given fields: statement, results, arguments

func (*SessionMock) ScanMapSlice

func (_m *SessionMock) ScanMapSlice(statement string, arguments ...interface{}) ([]map[string]interface{}, error)

ScanMapSlice provides a mock function with given fields: statement, arguments

func (*SessionMock) ScanMapTx

func (_m *SessionMock) ScanMapTx(statement string, results map[string]interface{}, arguments ...interface{}) (bool, error)

ScanMapTx provides a mock function with given fields: statement, results, arguments

func (*SessionMock) Tables

func (_m *SessionMock) Tables(keyspace string) ([]string, error)

Tables provides a mock function with given fields: keyspace

Jump to

Keyboard shortcuts

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