Documentation ¶
Overview ¶
Package cassandra includes convenient functions to start the embedded server
Index ¶
- Constants
- Variables
- func CleanupKeyspaceName(ksn string) string
- func CreateStmt(opts ...OptFunc) (string, error)
- func DeleteStmt(opts ...OptFunc) (string, error)
- func InsertStmt(opts ...OptFunc) (string, error)
- func IsRunning() bool
- func NewConnector(clusterConfig *gocql.ClusterConfig, ksMapper KeyspaceMapper, ...) (dosa.Connector, error)
- func SelectStmt(opts ...OptFunc) (string, error)
- type Cluster
- type ColumnCondition
- type Config
- type Connector
- func (c *Connector) CheckSchema(ctx context.Context, scope string, namePrefix string, ...) (int32, error)
- func (c *Connector) CheckSchemaStatus(context.Context, string, string, int32) (*dosa.SchemaStatus, error)
- func (c *Connector) CreateIfNotExists(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error
- func (c *Connector) CreateScope(ctx context.Context, scope string) error
- func (c *Connector) DropScope(ctx context.Context, scope string) error
- func (c *Connector) Range(ctx context.Context, ei *dosa.EntityInfo, ...) ([]map[string]dosa.FieldValue, string, error)
- func (c *Connector) Read(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue, ...) (map[string]dosa.FieldValue, error)
- func (c *Connector) Remove(ctx context.Context, ei *dosa.EntityInfo, keys map[string]dosa.FieldValue) error
- func (c *Connector) RemoveRange(ctx context.Context, ei *dosa.EntityInfo, ...) error
- func (c *Connector) Scan(ctx context.Context, ei *dosa.EntityInfo, fieldsToRead []string, token string, ...) ([]map[string]dosa.FieldValue, string, error)
- func (c *Connector) ScopeExists(ctx context.Context, scope string) (bool, error)
- func (c *Connector) Shutdown() error
- func (c *Connector) TruncateScope(ctx context.Context, scope string) error
- func (c *Connector) Upsert(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error
- func (c *Connector) UpsertSchema(ctx context.Context, scope string, namePrefix string, ...) (*dosa.SchemaStatus, error)
- type KeyspaceMapper
- type MissingColumn
- type OptFunc
- func Columns(v []string) OptFunc
- func ColumnsWithType(cols []*dosa.ColumnDefinition) OptFunc
- func Conditions(v interface{}) OptFunc
- func IfNotExist(v interface{}) OptFunc
- func Keyspace(v string) OptFunc
- func Limit(v interface{}) OptFunc
- func PrimaryKey(pk *dosa.PrimaryKey) OptFunc
- func Table(v string) OptFunc
- func Values(v interface{}) OptFunc
- type Option
- type RepairableSchemaMismatchError
- type UseNamePrefix
- type UseScope
Constants ¶
const CassandraPort = 9042
CassandraPort is the default port for talking to Cassandra
const ProductionKeyspaceName = "production"
ProductionKeyspaceName is the name of the production keyspace
Variables ¶
var DefaultKeyspaceMapper = &UseScope{}
DefaultKeyspaceMapper is the KeyspaceMapper that is used when none is specified
Functions ¶
func CleanupKeyspaceName ¶
CleanupKeyspaceName "cleans up" a keyspace name by changing unacceptable characters into underscores
func CreateStmt ¶
CreateStmt creates a create statement
func DeleteStmt ¶
DeleteStmt creates delete statement
func InsertStmt ¶
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 ¶
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
type ColumnCondition ¶
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 ¶
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 ¶
CreateScope creates a keyspace
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 ¶
ScopeExists is not implemented
func (*Connector) TruncateScope ¶
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 ¶
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 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 PrimaryKey ¶
func PrimaryKey(pk *dosa.PrimaryKey) OptFunc
PrimaryKey sets the primary key structure for create table
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 ¶
func (m *RepairableSchemaMismatchError) Error() string
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