cqlc

package
v0.0.0-...-1d8a72d Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2014 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

cqlc generates Go code from your Cassandra schema so that you can write type safe CQL statements in Go with a natural query syntax.

For a full guide visit http://relops.com/cqlc

var FOO = FooTableDef()

iter, err := ctx.Select(FOO.BAR).
                 From(FOO).
                 Where(FOO.BAZ.Eq("x")).
                 Fetch(session)

var foos []Foo = BindFoos(iter)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCASBindings = errors.New("Invalid CAS bindings")
)

Functions

func BuildStatement

func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err error)

Types

type ArrayColumn

type ArrayColumn interface {
	Column
}

type Bindable

type Bindable interface {
	Bind(cols ...ColumnBinding) UniqueFetchable
}

type BindingError

type BindingError string

func (BindingError) Error

func (m BindingError) Error() string

type BooleanColumn

type BooleanColumn interface {
	Column
	To(value *bool) ColumnBinding
}

type BytesColumn

type BytesColumn interface {
	Column
	To(value *[]byte) ColumnBinding
}

type ClusteredBooleanColumn

type ClusteredBooleanColumn interface {
	ClusteredColumn
	EqualityBooleanColumn
	Gt(value bool) Condition
	Lt(value bool) Condition
	Ge(value bool) Condition
	Le(value bool) Condition
}

type ClusteredBytesColumn

type ClusteredBytesColumn interface {
	ClusteredColumn
	EqualityBytesColumn
	Gt(value []byte) Condition
	Lt(value []byte) Condition
	Ge(value []byte) Condition
	Le(value []byte) Condition
}

type ClusteredColumn

type ClusteredColumn interface {
	// Returns the column name that a column family is clustered with.
	ClusterWith() string
	// This specifies descending ORDER BY for the column.
	// If this method is not called, it an ascending order will be assumed.
	Desc() ClusteredColumn
	// Denotes whether a descending order should be applied
	IsDescending() bool
}

ClusteredColumn is a marker interface to denote that a column is clustered.

type ClusteredDecimalColumn

type ClusteredDecimalColumn interface {
	ClusteredColumn
	EqualityDecimalColumn
	Gt(value *inf.Dec) Condition
	Lt(value *inf.Dec) Condition
	Ge(value *inf.Dec) Condition
	Le(value *inf.Dec) Condition
}

type ClusteredFloat32Column

type ClusteredFloat32Column interface {
	ClusteredColumn
	EqualityFloat32Column
	Gt(value float32) Condition
	Lt(value float32) Condition
	Ge(value float32) Condition
	Le(value float32) Condition
}

type ClusteredFloat64Column

type ClusteredFloat64Column interface {
	ClusteredColumn
	EqualityFloat64Column
	Gt(value float64) Condition
	Lt(value float64) Condition
	Ge(value float64) Condition
	Le(value float64) Condition
}

type ClusteredInt32Column

type ClusteredInt32Column interface {
	ClusteredColumn
	EqualityInt32Column
	Gt(value int32) Condition
	Lt(value int32) Condition
	Ge(value int32) Condition
	Le(value int32) Condition
}

type ClusteredInt64Column

type ClusteredInt64Column interface {
	ClusteredColumn
	EqualityInt64Column
	Gt(value int64) Condition
	Lt(value int64) Condition
	Ge(value int64) Condition
	Le(value int64) Condition
}

type ClusteredStringColumn

type ClusteredStringColumn interface {
	ClusteredColumn
	EqualityStringColumn
	Gt(value string) Condition
	Lt(value string) Condition
	Ge(value string) Condition
	Le(value string) Condition
}

type ClusteredTimeUUIDColumn

type ClusteredTimeUUIDColumn interface {
	ClusteredColumn
	EqualityTimeUUIDColumn
	Gt(value gocql.UUID) Condition
	Lt(value gocql.UUID) Condition
	Ge(value gocql.UUID) Condition
	Le(value gocql.UUID) Condition
}

type ClusteredTimestampColumn

type ClusteredTimestampColumn interface {
	ClusteredColumn
	EqualityTimestampColumn
	Gt(value time.Time) Condition
	Lt(value time.Time) Condition
	Ge(value time.Time) Condition
	Le(value time.Time) Condition
}

type Column

type Column interface {
	ColumnName() string
}

type ColumnBinding

type ColumnBinding struct {
	Column Column
	Value  interface{}
}

type CompareAndSwap

type CompareAndSwap interface {
	Swap(*gocql.Session) (bool, error)
}

type Condition

type Condition struct {
	Binding   ColumnBinding
	Predicate PredicateType
}

type Context

type Context struct {
	Operation      OperationType
	Table          Table
	Columns        []Column
	Bindings       []ColumnBinding
	CASBindings    []ColumnBinding
	Conditions     []Condition
	ResultBindings map[string]ColumnBinding
	Debug          bool
	ReadOptions    *ReadOptions
}

Context represents the state of the CQL statement that is being built by the application.

func NewContext

func NewContext() *Context

NewContext creates a fresh Context instance. If you want statement debugging, set the Debug property to true

func (*Context) Add

func (c *Context) Add(b TableBinding) Executable

Convenience method to generate CQL counter updates. This generates CQL SET clauses for each of the counter columns and CQL WHERE clauses for each of the key columns.

func (*Context) Apply

func (c *Context) Apply(cols ...ColumnBinding) SetValueStep

Adds each column binding as a `SET col = ?` fragment in the resulting CQL

func (*Context) Batch

func (c *Context) Batch(b *gocql.Batch) error

func (*Context) Bind

func (c *Context) Bind(cols ...ColumnBinding) UniqueFetchable

func (*Context) Delete

func (c *Context) Delete(cols ...Column) SelectFromStep

func (*Context) Dispose

func (c *Context) Dispose()

func (*Context) Exec

func (c *Context) Exec(s *gocql.Session) error

func (*Context) Fetch

func (c *Context) Fetch(s *gocql.Session) (*gocql.Iter, error)

func (*Context) FetchOne

func (c *Context) FetchOne(s *gocql.Session) (bool, error)

func (*Context) From

func (c *Context) From(t Table) SelectWhereStep

func (*Context) Having

func (c *Context) Having(cond ...Condition) Executable

func (*Context) IfExists

func (c *Context) IfExists(cols ...ColumnBinding) CompareAndSwap

Adds column bindings whose values will nbe populated if a CAS operation is applied.

func (*Context) Increment

func (c *Context) Increment(col CounterColumn, value int64) IncrementCounterStep

func (*Context) Limit

func (c *Context) Limit(lim int) Fetchable

func (*Context) OrderBy

func (c *Context) OrderBy(col ClusteredColumn) Fetchable

func (*Context) Prepare

func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error)

func (*Context) RenderCQL

func (c *Context) RenderCQL() (string, error)

TODO Make this private, since we should be able to test against BuildStatement()

func (*Context) Select

func (c *Context) Select(cols ...Column) SelectFromStep

func (*Context) SelectDistinct

func (c *Context) SelectDistinct(col PartitionedColumn) SelectFromStep

func (*Context) SetArray

func (c *Context) SetArray(col ArrayColumn, value []string) SetValueStep

func (*Context) SetBoolean

func (c *Context) SetBoolean(col BooleanColumn, value bool) SetValueStep

func (*Context) SetBytes

func (c *Context) SetBytes(col BytesColumn, value []byte) SetValueStep

func (*Context) SetDecimal

func (c *Context) SetDecimal(col DecimalColumn, value *inf.Dec) SetValueStep

func (*Context) SetFloat32

func (c *Context) SetFloat32(col Float32Column, value float32) SetValueStep

func (*Context) SetFloat64

func (c *Context) SetFloat64(col Float64Column, value float64) SetValueStep

func (*Context) SetInt32

func (c *Context) SetInt32(col Int32Column, value int32) SetValueStep

func (*Context) SetInt64

func (c *Context) SetInt64(col Int64Column, value int64) SetValueStep

func (*Context) SetMap

func (c *Context) SetMap(col MapColumn, value map[string]string) SetValueStep

func (*Context) SetString

func (c *Context) SetString(col StringColumn, value string) SetValueStep

func (*Context) SetTimeUUID

func (c *Context) SetTimeUUID(col TimeUUIDColumn, value gocql.UUID) SetValueStep

func (*Context) SetTimestamp

func (c *Context) SetTimestamp(col TimestampColumn, value time.Time) SetValueStep

func (*Context) Store

func (c *Context) Store(b TableBinding) Executable

func (*Context) Swap

func (c *Context) Swap(s *gocql.Session) (bool, error)

Returns true if the CAS operation was applied, false otherwise. If the operation was applied, then the result bindings will not be popluated.

func (*Context) UpdateCounter

func (c *Context) UpdateCounter(t CounterTable) IncrementCounterStep

func (*Context) Upsert

func (c *Context) Upsert(u Upsertable) SetValueStep

func (*Context) Where

func (c *Context) Where(cond ...Condition) Query

type CounterColumn

type CounterColumn interface {
	Column
	CanIncrement() bool
	To(value *int64) ColumnBinding
}

type CounterTable

type CounterTable interface {
	Table
	IsCounterTable() bool
}

type DecimalColumn

type DecimalColumn interface {
	Column
	To(value **inf.Dec) ColumnBinding
}

type EqualityBooleanColumn

type EqualityBooleanColumn interface {
	BooleanColumn
	Eq(value bool) Condition
}

type EqualityBytesColumn

type EqualityBytesColumn interface {
	BytesColumn
	Eq(value []byte) Condition
}

type EqualityDecimalColumn

type EqualityDecimalColumn interface {
	DecimalColumn
	Eq(value *inf.Dec) Condition
}

type EqualityFloat32Column

type EqualityFloat32Column interface {
	Float32Column
	Eq(value float32) Condition
}

type EqualityFloat64Column

type EqualityFloat64Column interface {
	Float64Column
	Eq(value float64) Condition
}

type EqualityInt32Column

type EqualityInt32Column interface {
	Int32Column
	Eq(value int32) Condition
}

type EqualityInt64Column

type EqualityInt64Column interface {
	Int64Column
	Eq(value int64) Condition
}

type EqualityStringColumn

type EqualityStringColumn interface {
	StringColumn
	Eq(value string) Condition
}

type EqualityTimeUUIDColumn

type EqualityTimeUUIDColumn interface {
	TimeUUIDColumn
	Eq(value gocql.UUID) Condition
}

type EqualityTimestampColumn

type EqualityTimestampColumn interface {
	TimestampColumn
	Eq(value time.Time) Condition
}

type Executable

type Executable interface {
	Exec(*gocql.Session) error
	Batch(*gocql.Batch) error
}

type Fetchable

type Fetchable interface {
	Bindable
	// Limit constrains the number of rows returned by a query
	Limit(limit int) Fetchable
	Prepare(session *gocql.Session) (*gocql.Query, error)
	Fetch(*gocql.Session) (*gocql.Iter, error)
}

type Float32Column

type Float32Column interface {
	Column
	To(value *float32) ColumnBinding
}

type Float64Column

type Float64Column interface {
	Column
	To(value *float64) ColumnBinding
}

type IncrementCounterStep

type IncrementCounterStep interface {
	IncrementWhereStep
	Increment(col CounterColumn, value int64) IncrementCounterStep
}

type IncrementWhereStep

type IncrementWhereStep interface {
	Having(conditions ...Condition) Executable
}

type Int32Column

type Int32Column interface {
	Column
	To(value *int32) ColumnBinding
}

type Int64Column

type Int64Column interface {
	Column
	To(value *int64) ColumnBinding
}

type LastClusteredBooleanColumn

type LastClusteredBooleanColumn interface {
	ClusteredBooleanColumn
	In(value ...bool) Condition
}

type LastClusteredBytesColumn

type LastClusteredBytesColumn interface {
	ClusteredBytesColumn
	In(value ...[]byte) Condition
}

type LastClusteredDecimalColumn

type LastClusteredDecimalColumn interface {
	ClusteredDecimalColumn
	In(value ...*inf.Dec) Condition
}

type LastClusteredFloat32Column

type LastClusteredFloat32Column interface {
	ClusteredFloat32Column
	In(value ...float32) Condition
}

type LastClusteredFloat64Column

type LastClusteredFloat64Column interface {
	ClusteredFloat64Column
	In(value ...float64) Condition
}

type LastClusteredInt32Column

type LastClusteredInt32Column interface {
	ClusteredInt32Column
	In(value ...int32) Condition
}

type LastClusteredInt64Column

type LastClusteredInt64Column interface {
	ClusteredInt64Column
	In(value ...int64) Condition
}

type LastClusteredStringColumn

type LastClusteredStringColumn interface {
	ClusteredStringColumn
	In(value ...string) Condition
}

type LastClusteredTimeUUIDColumn

type LastClusteredTimeUUIDColumn interface {
	ClusteredTimeUUIDColumn
	In(value ...gocql.UUID) Condition
}

type LastClusteredTimestampColumn

type LastClusteredTimestampColumn interface {
	ClusteredTimestampColumn
	In(value ...time.Time) Condition
}

type LastPartitionedBooleanColumn

type LastPartitionedBooleanColumn interface {
	PartitionedBooleanColumn
	In(value ...bool) Condition
}

type LastPartitionedBytesColumn

type LastPartitionedBytesColumn interface {
	PartitionedBytesColumn
	In(value ...[]byte) Condition
}

type LastPartitionedDecimalColumn

type LastPartitionedDecimalColumn interface {
	PartitionedDecimalColumn
	In(value ...*inf.Dec) Condition
}

type LastPartitionedFloat32Column

type LastPartitionedFloat32Column interface {
	PartitionedFloat32Column
	In(value ...float32) Condition
}

type LastPartitionedFloat64Column

type LastPartitionedFloat64Column interface {
	PartitionedFloat64Column
	In(value ...float64) Condition
}

type LastPartitionedInt32Column

type LastPartitionedInt32Column interface {
	PartitionedInt32Column
	In(value ...int32) Condition
}

type LastPartitionedInt64Column

type LastPartitionedInt64Column interface {
	PartitionedInt64Column
	In(value ...int64) Condition
}

type LastPartitionedStringColumn

type LastPartitionedStringColumn interface {
	PartitionedStringColumn
	In(value ...string) Condition
}

type LastPartitionedTimeUUIDColumn

type LastPartitionedTimeUUIDColumn interface {
	PartitionedTimeUUIDColumn
	In(value ...gocql.UUID) Condition
}

type LastPartitionedTimestampColumn

type LastPartitionedTimestampColumn interface {
	PartitionedTimestampColumn
	In(value ...time.Time) Condition
}

type MapColumn

type MapColumn interface {
	Column
}

type OperationType

type OperationType int
const (
	None             OperationType = 0
	ReadOperation    OperationType = 1
	WriteOperation   OperationType = 2
	DeleteOperation  OperationType = 3
	CounterOperation OperationType = 4
)

type PartitionedBooleanColumn

type PartitionedBooleanColumn interface {
	PartitionedColumn
	EqualityBooleanColumn
}

type PartitionedBytesColumn

type PartitionedBytesColumn interface {
	PartitionedColumn
	EqualityBytesColumn
}

type PartitionedColumn

type PartitionedColumn interface {
	// Returns the column definition that a column family is partitioned by.
	PartitionBy() Column
}

PartitionedColumn is a marker interface to denote that a column is partitioned.

type PartitionedDecimalColumn

type PartitionedDecimalColumn interface {
	PartitionedColumn
	EqualityDecimalColumn
}

type PartitionedFloat32Column

type PartitionedFloat32Column interface {
	PartitionedColumn
	EqualityFloat32Column
}

type PartitionedFloat64Column

type PartitionedFloat64Column interface {
	PartitionedColumn
	EqualityFloat64Column
}

type PartitionedInt32Column

type PartitionedInt32Column interface {
	PartitionedColumn
	EqualityInt32Column
}

type PartitionedInt64Column

type PartitionedInt64Column interface {
	PartitionedColumn
	EqualityInt64Column
}

type PartitionedStringColumn

type PartitionedStringColumn interface {
	PartitionedColumn
	EqualityStringColumn
}

type PartitionedTimeUUIDColumn

type PartitionedTimeUUIDColumn interface {
	PartitionedColumn
	EqualityTimeUUIDColumn
}

type PartitionedTimestampColumn

type PartitionedTimestampColumn interface {
	PartitionedColumn
	EqualityTimestampColumn
}

type PredicateType

type PredicateType int
const (
	EqPredicate PredicateType = 1
	GtPredicate PredicateType = 2
	GePredicate PredicateType = 3
	LtPredicate PredicateType = 4
	LePredicate PredicateType = 5
	InPredicate PredicateType = 6
)

type Query

type Query interface {
	Executable
	Fetchable
	// OrderBy sets the ordering of the returned query
	OrderBy(col ClusteredColumn) Fetchable
}

type ReadOptions

type ReadOptions struct {
	Distinct bool
	Limit    int
	OrderBy  string
	Desc     bool
}

type SelectFromStep

type SelectFromStep interface {
	From(table Table) SelectWhereStep
}

type SelectSelectStep

type SelectSelectStep interface {
	Select(cols ...Column) SelectFromStep
	// Builds a SELECT DISTINCT statement in CQL - this operation can only be used
	// with a partitioned column.
	SelectDistinct(col PartitionedColumn) SelectFromStep
}

type SelectWhereStep

type SelectWhereStep interface {
	Fetchable
	Where(conditions ...Condition) Query
}

type SetValueStep

type SetValueStep interface {
	Executable
	SelectWhereStep
	Apply(cols ...ColumnBinding) SetValueStep
	IfExists(cols ...ColumnBinding) CompareAndSwap
	SetString(col StringColumn, value string) SetValueStep
	SetInt32(col Int32Column, value int32) SetValueStep
	SetInt64(col Int64Column, value int64) SetValueStep
	SetFloat32(col Float32Column, value float32) SetValueStep
	SetFloat64(col Float64Column, value float64) SetValueStep
	SetTimestamp(col TimestampColumn, value time.Time) SetValueStep
	SetTimeUUID(col TimeUUIDColumn, value gocql.UUID) SetValueStep
	SetBoolean(col BooleanColumn, value bool) SetValueStep
	SetMap(col MapColumn, value map[string]string) SetValueStep
	SetArray(col ArrayColumn, value []string) SetValueStep
	SetBytes(col BytesColumn, value []byte) SetValueStep
	SetDecimal(col DecimalColumn, value *inf.Dec) SetValueStep
}

type StringColumn

type StringColumn interface {
	Column
	To(value *string) ColumnBinding
}

type Table

type Table interface {
	TableName() string
	ColumnDefinitions() []Column
}

type TableBinding

type TableBinding struct {
	Table   Table
	Columns []ColumnBinding
}

type TimeUUIDColumn

type TimeUUIDColumn interface {
	Column
	To(value *gocql.UUID) ColumnBinding
}

type TimestampColumn

type TimestampColumn interface {
	Column
	To(value *time.Time) ColumnBinding
}

type UniqueFetchable

type UniqueFetchable interface {
	// Returns true if the statement did return a result, false if it did not.
	FetchOne(*gocql.Session) (bool, error)
}

type Upsertable

type Upsertable interface {
	Table
	SupportsUpsert() bool
}

Jump to

Keyboard shortcuts

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