Documentation ¶
Index ¶
- Variables
- func Bind(i interface{}) []interface{}
- func Dec(v int64) decreaseType
- func DeleteRegistry()
- func Inc(v int64) increaseType
- func Map(i interface{}) map[string]interface{}
- func MustUUID(input string) gocql.UUID
- func Now() time.Time
- func Register(i interface{})
- type Batch
- type BatchImpl
- type Column
- type Command
- type Condition
- func And(lhs Condition, list ...Condition) Condition
- func Contains(col string, v interface{}) Condition
- func ContainsKey(col string, v interface{}) Condition
- func Eq(col string, v interface{}) Condition
- func EqInt(i interface{}) Condition
- func Ge(col string, v interface{}) Condition
- func Gt(col string, v interface{}) Condition
- func In(col string, v ...interface{}) Condition
- func Le(col string, v interface{}) Condition
- func Lt(col string, v interface{}) Condition
- func Raw(fragment string, v ...interface{}) Condition
- func True() Condition
- type Iter
- type IterImpl
- type OrderBy
- type OrderType
- type PredicateType
- type Session
- type SessionImpl
- func (s *SessionImpl) Batch() Batch
- func (s *SessionImpl) Count(i interface{}) Statement
- func (s *SessionImpl) Del(i interface{}) error
- func (s *SessionImpl) Delete(i interface{}) Statement
- func (s *SessionImpl) Exists(i interface{}) (bool, error)
- func (s *SessionImpl) Get(i interface{}, keys ...interface{}) error
- func (s *SessionImpl) Insert(i interface{}) Statement
- func (s *SessionImpl) Select(i interface{}) Statement
- func (s *SessionImpl) Set(i interface{}) error
- func (s *SessionImpl) Update(i interface{}) Statement
- type Statement
- type StatementImpl
- func (s *StatementImpl) AllowFiltering() Statement
- func (s *StatementImpl) Bind(i interface{}) Statement
- func (s *StatementImpl) BuildQuery() (string, []interface{})
- func (s *StatementImpl) Columns(columns ...string) Statement
- func (s *StatementImpl) Do(cmd Command) Statement
- func (s *StatementImpl) Exec() error
- func (s *StatementImpl) From(table string) Statement
- func (s *StatementImpl) FromType(i interface{}) Statement
- func (s *StatementImpl) IfExists() Statement
- func (s *StatementImpl) IfNotExists() Statement
- func (s *StatementImpl) Iter() Iter
- func (s *StatementImpl) Limit(n int) Statement
- func (s *StatementImpl) Map(i interface{}) Statement
- func (s *StatementImpl) OrderBy(order ...OrderBy) Statement
- func (s *StatementImpl) Scan(i ...interface{}) error
- func (s *StatementImpl) Set(column string, value interface{}) Statement
- func (s *StatementImpl) TTL(seconds int) Statement
- func (s *StatementImpl) Timestamp(microseconds int64) Statement
- func (s *StatementImpl) TypeScan() error
- func (s *StatementImpl) Where(cond ...Condition) Statement
- type Table
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidQueryType = errors.New("invalid query type") ErrInvalidCommand = errors.New("invalid cql command") )
var ( // TAG_COLUMNS is the tag used in the structs to set the column name for a field. // If a name is not set, the name would be the lowercase version of the field. // If you want to skip a field you can use `cql:"-"` TAG_COLUMN = "cql" // TAG_TABLE is the tag used in the structs to define the table for a type. // If the table is not set it defaults to the type name in lowercase. TAG_TABLE = "cqltable" // TAG_KEY defines the primary key for the table. // If the table uses a composite key you just need to define multiple columns // separated by a comma: `cqlkey:"id"` or `cqlkey:"partkey,id"` TAG_KEY = "cqlkey" )
var EcqlDebug = (os.Getenv("ECQL_DEBUG") == "true")
var ErrNotFound = gocql.ErrNotFound
Functions ¶
func Bind ¶
func Bind(i interface{}) []interface{}
Bind returns the values of i to bind in insert queries.
func DeleteRegistry ¶
func DeleteRegistry()
Delete registry cleans the registry. This would be mainly used in unit testing.
func Map ¶
func Map(i interface{}) map[string]interface{}
Map creates a new map[string]interface{} where each member in the map is a reference to a field in the struct. This allows to assign values to a struct using gocql MapScan.
Given a gocql session, the following code will populate the struct 't' with the values in the datastore.
var t MyStruct query := session.Query("select * from mytable where id = ?", "my-id") m := cql.Map(&t) err := query.MapScan(m)
Types ¶
type Column ¶
Column contains the information of a column in a table required to create a map for it.
type Condition ¶
type Condition struct { CQLFragment string Values []interface{} }
func Contains ¶
Contains creates the condition 'col CONTAINS value' used to filter elements in a collection set, list, or map. Supported on CQL versions >= 3.2.0.
func ContainsKey ¶
Contains creates the condition 'col CONTAINS KEY value' used to filter elements by key in a map. Supported on CQL versions >= 3.2.0.
func EqInt ¶
func EqInt(i interface{}) Condition
EqInt takes is interested in the CQL indexes of the provided struct as a condition For convenience, that struct is assumed to follow the same rules as other mappings
func Raw ¶
Raw allows to set the CQLFrament and Values of a condition. It allows to add any not yet supported condition in a easy way.
Raw("token(partition_key) > token(?)", v.ID) Raw("token(partition_key) > token('value')") Raw("time > maxTimeuuid('2013-01-01 00:05+0000')") Raw("time > maxTimeuuid(?) AND time < minTimeuuid(?)", maxTime, minTime)
type PredicateType ¶
type PredicateType int
type Session ¶
type Session interface { Get(i interface{}, keys ...interface{}) error Set(i interface{}) error Del(i interface{}) error Exists(i interface{}) (bool, error) Select(i interface{}) Statement Insert(i interface{}) Statement Delete(i interface{}) Statement Update(i interface{}) Statement Count(i interface{}) Statement Batch() Batch Query(stmt string, args ...interface{}) *gocql.Query }
Session is the interface used by users to interact with the database.
func NewSession ¶
func NewSession(cfg gocql.ClusterConfig) (Session, error)
NewSession initializes a new ecql.Session with gocql.ConsterConfig.
type SessionImpl ¶
func (*SessionImpl) Batch ¶
func (s *SessionImpl) Batch() Batch
Batch initializes a new LOGGED BATCH to combine multiple data modification statements (INSERT, UPDATE, DELETE)
func (*SessionImpl) Count ¶
func (s *SessionImpl) Count(i interface{}) Statement
Count initializes a SELECT COUNT(1) statement from the table defined by i.
func (*SessionImpl) Del ¶
func (s *SessionImpl) Del(i interface{}) error
Del extecutes a delete statement on the table defined in i to remove the object i from the database.
func (*SessionImpl) Delete ¶
func (s *SessionImpl) Delete(i interface{}) Statement
Select initializes an DELETE statement.
func (*SessionImpl) Exists ¶
func (s *SessionImpl) Exists(i interface{}) (bool, error)
Exists executes a count statement on the table defined in i and returns if the object i exists in the database.
func (*SessionImpl) Get ¶
func (s *SessionImpl) Get(i interface{}, keys ...interface{}) error
Get executes a SELECT statements on the table defined in i and sets the fields on i with the information present in the database.
func (*SessionImpl) Insert ¶
func (s *SessionImpl) Insert(i interface{}) Statement
Select initializes an INSERT statement.
func (*SessionImpl) Select ¶
func (s *SessionImpl) Select(i interface{}) Statement
Select initializes a SELECT statement.
func (*SessionImpl) Set ¶
func (s *SessionImpl) Set(i interface{}) error
Set executes an INSERT statement on the the table defined in i and saves the information of i in the dtabase.
func (*SessionImpl) Update ¶
func (s *SessionImpl) Update(i interface{}) Statement
Update initializes an UPDATE statement.
type Statement ¶
type Statement interface { TypeScan() error Scan(i ...interface{}) error Exec() error Iter() Iter BuildQuery() (string, []interface{}) Do(cmd Command) Statement From(table string) Statement FromType(i interface{}) Statement Columns(columns ...string) Statement Set(column string, value interface{}) Statement Where(cond ...Condition) Statement OrderBy(order ...OrderBy) Statement AllowFiltering() Statement IfExists() Statement IfNotExists() Statement Bind(i interface{}) Statement Map(i interface{}) Statement Limit(n int) Statement TTL(seconds int) Statement Timestamp(microseconds int64) Statement }
func NewStatement ¶
func NewStatement(sess *SessionImpl) Statement
type StatementImpl ¶
type StatementImpl struct { Command Command Table Table ColumnNames []string Conditions *Condition Orders []OrderBy Assignments map[string]interface{} LimitValue int TTLValue int TimestampValue int64 AllowFilteringValue bool IfExistsValue bool IfNotExistsValue bool // contains filtered or unexported fields }
func (*StatementImpl) AllowFiltering ¶
func (s *StatementImpl) AllowFiltering() Statement
func (*StatementImpl) Bind ¶
func (s *StatementImpl) Bind(i interface{}) Statement
func (*StatementImpl) BuildQuery ¶
func (s *StatementImpl) BuildQuery() (string, []interface{})
BuildQuery returns the statement query and arguments that will be executed.
func (*StatementImpl) Columns ¶
func (s *StatementImpl) Columns(columns ...string) Statement
Columns define a list of columns to get on SELECT statements, to set on UPDATE or INSERT statemets or to remove on DELETE statements.
func (*StatementImpl) Do ¶
func (s *StatementImpl) Do(cmd Command) Statement
func (*StatementImpl) Exec ¶
func (s *StatementImpl) Exec() error
Exec builds the query statement and executes it returning nil or the gocql error. On DELETE and UPDATE statements, the behavior of Exec differs from gocql if IfExists() is used, in this case, ecql will perform a ScanCAS and return ErrNotFound if the query was not applied.
func (*StatementImpl) From ¶
func (s *StatementImpl) From(table string) Statement
func (*StatementImpl) FromType ¶
func (s *StatementImpl) FromType(i interface{}) Statement
func (*StatementImpl) IfExists ¶
func (s *StatementImpl) IfExists() Statement
func (*StatementImpl) IfNotExists ¶
func (s *StatementImpl) IfNotExists() Statement
func (*StatementImpl) Iter ¶
func (s *StatementImpl) Iter() Iter
func (*StatementImpl) Limit ¶
func (s *StatementImpl) Limit(n int) Statement
func (*StatementImpl) Map ¶
func (s *StatementImpl) Map(i interface{}) Statement
func (*StatementImpl) OrderBy ¶
func (s *StatementImpl) OrderBy(order ...OrderBy) Statement
func (*StatementImpl) Scan ¶
func (s *StatementImpl) Scan(i ...interface{}) error
func (*StatementImpl) Set ¶
func (s *StatementImpl) Set(column string, value interface{}) Statement
Set allows to add a new Set to an UPDATE statement.
func (*StatementImpl) TTL ¶
func (s *StatementImpl) TTL(seconds int) Statement
func (*StatementImpl) Timestamp ¶
func (s *StatementImpl) Timestamp(microseconds int64) Statement
func (*StatementImpl) TypeScan ¶
func (s *StatementImpl) TypeScan() error
func (*StatementImpl) Where ¶
func (s *StatementImpl) Where(cond ...Condition) Statement
Where Conditionss are implicitly And with each other
type Table ¶
Table contains the information of a table in cassandra.
func BindTable ¶
BindTables returns the values of i to bind in insert queries and the Table with the information about the type.
func GetTable ¶
func GetTable(i interface{}) Table
GetTable returns the Table with the information about the type of i.
func MapTable ¶
MapTable creates a new map[string]interface{} where each member in the map is a reference to a field in the struct. This allows to assign values to a struct using gocql MapScan. MapTable also returns the Table with the information about the type.
Given a gocql session, the following code will populate the struct 't' with the values in the datastore.
var t MyStruct query := session.Query("select * from mytable where id = ?", "my-id") m, _ := cql.MapTable(&t) err := query.MapScan(m)