cassandra

package
v2.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package cassandra includes convenient functions to start the embedded server

Index

Constants

View Source
const CassandraPort = 9042

CassandraPort is the default port for talking to Cassandra

View Source
const ProductionKeyspaceName = "production"

ProductionKeyspaceName is the name of the production keyspace

Variables

View Source
var DefaultKeyspaceMapper = &UseScope{}

DefaultKeyspaceMapper is the KeyspaceMapper that is used when none is specified

Functions

func CleanupKeyspaceName

func CleanupKeyspaceName(ksn string) string

CleanupKeyspaceName "cleans up" a keyspace name by changing unacceptable characters into underscores

func CreateStmt

func CreateStmt(opts ...OptFunc) (string, error)

CreateStmt creates a create statement

func DeleteStmt

func DeleteStmt(opts ...OptFunc) (string, error)

DeleteStmt creates delete statement

func InsertStmt

func InsertStmt(opts ...OptFunc) (string, error)

InsertStmt creates insert statement

func IsRunning

func IsRunning() bool

IsRunning provides a quick check to see if Cassandra is already running

func NewConnector

func NewConnector(clusterConfig *gocql.ClusterConfig, ksMapper KeyspaceMapper, next dosa.Connector) (dosa.Connector, error)

NewConnector creates an instance of Connector

func SelectStmt

func SelectStmt(opts ...OptFunc) (string, error)

SelectStmt creates select statement

Types

type Cluster

type Cluster struct {
	// contains filtered or unexported fields
}

Cluster contains the cluster configuration and session info

func NewCluster

func NewCluster(config gocql.ClusterConfig) (*Cluster, error)

NewCluster creates a Cluster instance based on config

func (*Cluster) Close

func (c *Cluster) Close()

Close closes the session to cassandra

type ColumnCondition

type ColumnCondition struct {
	Name      string
	Condition *dosa.Condition
}

ColumnCondition represents the condition of each column

type Config

type Config struct {
	gocql.ClusterConfig `yaml:",inline"`
}

Config is a wrapper for the gocql.ClusterConfig, adding support for yaml

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshals the config into gocql cluster config

type Connector

type Connector struct {
	base.Connector

	Session  *gocql.Session
	KsMapper KeyspaceMapper
	// contains filtered or unexported fields
}

Connector implements the data access to the cassandra cluster

func (*Connector) CheckSchema

func (c *Connector) CheckSchema(ctx context.Context, scope string, namePrefix string, ed []*dosa.EntityDefinition) (int32, error)

CheckSchema verifies that the schema passed in the registered entities matches the database This implementation only returns 0 or 1, since we are not storing schema version information anywhere else

func (*Connector) CheckSchemaStatus

func (c *Connector) CheckSchemaStatus(context.Context, string, string, int32) (*dosa.SchemaStatus, error)

CheckSchemaStatus is not implemented

func (*Connector) CreateIfNotExists

func (c *Connector) CreateIfNotExists(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error

CreateIfNotExists creates an object if not exists

func (*Connector) CreateScope

func (c *Connector) CreateScope(ctx context.Context, scope string) error

CreateScope creates a keyspace

func (*Connector) DropScope

func (c *Connector) DropScope(ctx context.Context, scope string) error

DropScope is not implemented

func (*Connector) Range

func (c *Connector) Range(ctx context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition, fieldsToRead []string,
	token string, limit int) ([]map[string]dosa.FieldValue, string, error)

Range querys the data based on the cluster keys

func (*Connector) Read

func (c *Connector) Read(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue, fieldsToRead []string) (map[string]dosa.FieldValue, error)

Read reads an object based on primary key

func (*Connector) Remove

func (c *Connector) Remove(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue) error

Remove object based on primary key

func (*Connector) RemoveRange

func (c *Connector) RemoveRange(ctx context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition) error

RemoveRange removes a range of objects based on column conditions.

func (*Connector) Scan

func (c *Connector) Scan(ctx context.Context, ei *dosa.EntityInfo, fieldsToRead []string, token string,
	limit int) ([]map[string]dosa.FieldValue, string, error)

Scan returns the data from entire table

func (*Connector) ScopeExists

func (c *Connector) ScopeExists(ctx context.Context, scope string) (bool, error)

ScopeExists is not implemented

func (*Connector) Shutdown

func (c *Connector) Shutdown() error

Shutdown cleans up the connector

func (*Connector) TruncateScope

func (c *Connector) TruncateScope(ctx context.Context, scope string) error

TruncateScope is not implemented

func (*Connector) Upsert

func (c *Connector) Upsert(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error

Upsert means update an existing object or create a new object

func (*Connector) UpsertSchema

func (c *Connector) UpsertSchema(ctx context.Context, scope string, namePrefix string, ed []*dosa.EntityDefinition) (*dosa.SchemaStatus, error)

UpsertSchema checks the schema and then updates it We handle RepairableSchemaMismatchErrors, and return any other error from CheckSchema

type KeyspaceMapper

type KeyspaceMapper interface {
	Keyspace(scope, namePrefix string) (keyspace string)
}

KeyspaceMapper is an interface that maps scope/namePrefix to a keyspace

type MissingColumn

type MissingColumn struct {
	Column    dosa.ColumnDefinition
	Tablename string
}

MissingColumn describes a column that is missing

type OptFunc

type OptFunc func(Option)

OptFunc is the interface to set option

func Columns

func Columns(v []string) OptFunc

Columns sets the `columns` clause to the cql statement

func ColumnsWithType

func ColumnsWithType(cols []*dosa.ColumnDefinition) OptFunc

ColumnsWithType sets the column definitions for each column which is needed by create table

func Conditions

func Conditions(v interface{}) OptFunc

Conditions set the `where` clause to the cql statement

func IfNotExist

func IfNotExist(v interface{}) OptFunc

IfNotExist sets the `if not exist` clause to the cql statement

func Keyspace

func Keyspace(v string) OptFunc

Keyspace sets the `keyspace` to the cql statement

func Limit

func Limit(v interface{}) OptFunc

Limit sets the `limit` to the cql statement

func PrimaryKey

func PrimaryKey(pk *dosa.PrimaryKey) OptFunc

PrimaryKey sets the primary key structure for create table

func Table

func Table(v string) OptFunc

Table sets the `table` to the cql statement

func Values

func Values(v interface{}) OptFunc

Values sets the `values` clause to the cql statement

type Option

type Option map[string]interface{}

Option to compose a cql statement

type RepairableSchemaMismatchError

type RepairableSchemaMismatchError struct {
	MissingColumns []MissingColumn
	MissingTables  []string
}

RepairableSchemaMismatchError is an error describing what can be added to make this schema current. It might include a lot of tables or columns

func (*RepairableSchemaMismatchError) Error

Error prints a human-readable error message describing the first missing table or column

func (*RepairableSchemaMismatchError) HasMissing

func (m *RepairableSchemaMismatchError) HasMissing() bool

HasMissing returns true if there are missing columns

type UseNamePrefix

type UseNamePrefix struct{}

UseNamePrefix is a simple keyspace mapper that always uses the namePrefix for the schema name

func (*UseNamePrefix) Keyspace

func (*UseNamePrefix) Keyspace(_, namePrefix string) string

Keyspace returns a cleaned-up copy of the namePrefix

type UseScope

type UseScope struct{}

UseScope is a simple KeyspaceMapper that always uses the scope to determine the keyspace name

func (*UseScope) Keyspace

func (*UseScope) Keyspace(scope, _ string) string

Keyspace just returns a cleaned-up scope name

Jump to

Keyboard shortcuts

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