Documentation ¶
Overview ¶
Package api provides data access management to structured storage backend
a very simple usage example is:
err := storage.Initialize(Option{}) defer storage.Close()
store, err := storage.OpenDataStore("test_schema_name") queryBuilder := store.NewQuery() statement := queryBuilder.Insert("user").Columns("name", "count").Values("json", 1234) result := store.Execute(statement) allResults, err := result.All()
Index ¶
- Constants
- Variables
- func ContextWithQueryOverrides(ctx context.Context, queryOverrides *QueryOverrides) context.Context
- func ContextWithTags(ctx context.Context, t map[string]string) context.Context
- type ConsistencyOverride
- type DataStore
- type Decorator
- type EntityKey
- type FuncType
- type MultiTable
- type QueryBuilder
- type QueryOverrides
- type RangeFilter
- type ResultSet
- type Statement
- type Table
Constants ¶
const ( // ConsistencyAny maps to cassandra consistency "ANY" ConsistencyAny = gocql.Any // ConsistencyOne maps to cassandra consistency "ONE" ConsistencyOne = gocql.One // ConsistencyTwo maps to cassandra consistency "TWO" ConsistencyTwo = gocql.Two // ConsistencyThree maps to cassandra consistency "THREE" ConsistencyThree = gocql.Three // ConsistencyQuorum maps to cassandra consistency "QUORUM" ConsistencyQuorum = gocql.Quorum // ConsistencyAll maps to cassandra consistency "ALL" ConsistencyAll = gocql.All // ConsistencyAll maps to cassandra consistency "LOCAL_QUORUM" ConsistencyLocalQuorum = gocql.LocalQuorum // ConsistencyEachQuorum maps to cassandra consistency "EACH_QUORUM" ConsistencyEachQuorum = gocql.EachQuorum // ConsistencyLocalOne maps to cassandra consistency "LOCAL_ONE" ConsistencyLocalOne = gocql.LocalOne )
Public consistency levels for use in ConsistencyOverride Semantics of each level are available here https://docs.datastax.com/en/cassandra/3.0/cassandra/dml/dmlConfigConsistency.html
const QueryOverridesKey = contextKey("stapi.query.overrides")
QueryOverridesKey is used to reference query level config overrides in the context
const TagKey = contextKey("stapi.tags")
TagKey is used to reference tags in the context
Variables ¶
var ( // ErrUninitialized means storage system was not initialized ErrUninitialized = errors.New("Storage system not initialized") // ErrUnsupported indicates errors for unsupported features ErrUnsupported = errors.New("Feature not supported") // ErrConnection indicates errors for connection problems ErrConnection = errors.New("Fail to connect to backend nodes") // ErrClosed means back end data store is closed ErrClosed = errors.New("Data store closed") // ErrInvalidUsage is thrown when user makes an invalid call ErrInvalidUsage = errors.New("Usage is not supported") // ErrOverCapacity means the client is handling too many concurrent go routines. ErrOverCapacity = errors.New("Over capacity") ErrUnauthorized = errors.New("Unauthorized") )
Public error values
Functions ¶
func ContextWithQueryOverrides ¶
func ContextWithQueryOverrides(ctx context.Context, queryOverrides *QueryOverrides) context.Context
ContextWithQueryOverrides returns a context with query overrides
Types ¶
type ConsistencyOverride ¶
type ConsistencyOverride struct {
Value gocql.Consistency
}
ConsistencyOverride represents a query level override to the default consistency
type DataStore ¶
type DataStore interface { // Execute a query and return a ResultSet Execute(ctx context.Context, stmt Statement) (ResultSet, error) // ExecuteBatch make a single RPC call for multiple statement execution. ExecuteBatch(ctx context.Context, stmts []Statement) error // NewQuery creates a QueryBuilder object NewQuery() QueryBuilder // Returns the name of this DataStore Name() string }
DataStore represents a connection with the backend data store DataStore is safe for concurrent use by multiple goroutines
type EntityKey ¶
type EntityKey interface { // TableName returns the name of the table TableName() string // Filter returns a filtering condition that is applied to key columns. // This is typically what is in the "Where" clause of a query Filter() (cql string, args []interface{}, err error) }
EntityKey is used by a Table object to run retrieve or delete operations.
type MultiTable ¶
type MultiTable interface { // NewKey creates a EntityKey object with the given values NewKey(obj interface{}, value ...[]interface{}) []EntityKey // NewRangeKey creates a EntityKey object representing a range query on key // columns NewRangeKey(obj interface{}, filters []RangeFilter) []EntityKey Get(ctx context.Context, keys []EntityKey, objs *[]interface{}, fields []string) error // Delete removes all the objects represented by the keys Delete(ctx context.Context, keys []EntityKey) error // UpSert adds the object to the store regardless of its prior existence. UpSert(ctx context.Context, objs *[]interface{}) error // CompareAndSet persists the object only when the record dose not already // exist. CompareAndSet(ctx context.Context, objs *[]interface{}) error }
MultiTable allows CRUD operations against a collection of tables.
type QueryBuilder ¶
type QueryBuilder interface { // Select returns a select query Select(columns ...string) qb.SelectBuilder // Insert returns an insert query. Insert(into string) qb.InsertBuilder // Update returns a update query. Update(table string) qb.UpdateBuilder // Delete returns a delete query Delete(from string) qb.DeleteBuilder }
QueryBuilder is responsible for constructing queries
type QueryOverrides ¶
type QueryOverrides struct {
Consistency *ConsistencyOverride
}
QueryOverrides represent query level overrides to the default configuration
type RangeFilter ¶
type RangeFilter struct {
// contains filtered or unexported fields
}
RangeFilter represents a ranged entity key.
type ResultSet ¶
type ResultSet interface { // All returns all results in a SliceMap and cleans up itself. All(ctx context.Context) ([]map[string]interface{}, error) // One is deprecated One(ctx context.Context, dest ...interface{}) bool // Close closes the underlying iterator and returns any errors // that happened during the query or the iteration. Close() error // Applied shows whether a set was done in a compare-and-set operation Applied() bool // Next returns the next row out of the ResultSet. Empty map indicates // the end of ResultSet Next(ctx context.Context) (map[string]interface{}, error) // PagingState returns the paging state for the query PagingState() []byte }
ResultSet contains the result of a executed query
type Statement ¶
type Statement interface { ToSQL() (string, []interface{}, error) ToUql() (string, []interface{}, map[string]interface{}, error) StmtType() qb.StmtType IsCAS() bool GetData() qb.StatementAccessor }
Statement represents a query against the backend data store. There are 4 kinds of statements: qb.SelectBuilder, qb.InsertBuilder, qb.UpdateBuilder, and qb.DeleteBuilder
type Table ¶
type Table interface { // NewKey creates a EntityKey object with the given values NewKey(obj interface{}, value ...interface{}) EntityKey // NewRangeKey creates a EntityKey object representing a range query on key // columns NewRangeKey(obj interface{}, filter RangeFilter) EntityKey // Get retrieves the object by its key. fields parameter allows users to // specify a subset of columns that they want to retrieve. all fields // are retrieved if fields is nil Get(ctx context.Context, key EntityKey, obj *interface{}, fields []string) error // Delete removes the object represented by the key Delete(ctx context.Context, key EntityKey) error // UpSert adds the object to the store regardless of its prior existence. UpSert(ctx context.Context, obj *interface{}) error // CompareAndSet persists the object only when the record dose not already // exist. CompareAndSet(ctx context.Context, obj *interface{}) error }
Table allows CRUD operations against a single table.