idb

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2019 License: MIT Imports: 8 Imported by: 0

README

Overview

  • Interface is built having Cassandra functionality in mind
  • It is not possible to alter table, so all fields must be known in advance
  • But it is possible to add index in the furture
  • Ref. interface.go

TableDef Builder

MyTableDef := idb.NewTable("table_name").
	PartitionKeyField(field1).
	PartitionKeyField(field2).
	ClusterKeyField(field3).
	ClusterKeyField(field4).
	Field(field5).
	Field(field6).
	Build()

Put Request Builder

putRequest := NewPutRequest(MyTableDef).
	Key(field1, 42).
	Key(field2, "test").
	Val(field3, 1.).
	IfNotExists().
	Build()

Other Builders

  • GetRequestBuilder, RangeRequestBuilder, ref builders.go

Documentation

Index

Constants

View Source
const ConnectionParametersKey = ContextKeyType("ConnectionParameters")

ConnectionParametersKey s.e.

Variables

View Source
var (
	ErrNonCompleteKey            = errors.New("All key fields must be specified")
	ErrEmptyPartitionKey         = errors.New("Partition key is not specified")
	ErrNothingToSelect           = errors.New("Nothing to select")
	ErrIfNotExistsWithConditions = errors.New("IfNotExists has no sence with Where conditions")
	ErrNothingToSet              = errors.New("No values to set specified")
	ErrNoTableDef                = errors.New("Table is not specified")
)

Err

View Source
var Finit func(ctx context.Context)

Finit closes connection (if any) and associated data structures

View Source
var Get func(ctx context.Context, gr *GetRequest) bool

Get s.e. returns if value exists for the key

View Source
var Init func(ctx context.Context) (newCtx context.Context, err error)

Init database connection and create all tables registered in `TableDefs“ Must work in multi-process environment (another processes may also trying to create same tables) Connection parameters must be passed through `ctx` using `ConnectionParametersKey`

View Source
var Insert func(ctx context.Context, ir *InsertRequest) bool

Insert saves values for a given key into database only if no value exists for the provided key Values to be saved and the key are described by InsertRequest Function returns true if value has been added and false if table already has value for the provided key Panics if something goes wrong

View Source
var Put func(ctx context.Context, ir *InsertRequest)

Put in Cassandra terms does INSERT, LWT is not involved (no "if not exist" etc.)

View Source
var Range func(ctx context.Context, rr *RangeRequest) Scan

Range s.e. If something goes wrong function panics

View Source
var TableDefs map[string]*TableDef

TableDefs keeps table definitions

View Source
var Update func(ctx context.Context, ur *UpdateRequest) bool

Update updates values for a given key and conditions Values to be saved, the key and conditions are described by UpdateRequest Function returns true if value has been updated and false if no value for the provided key and\or conditions Panics if something goes wrong

Functions

func RunIDBTests added in v0.4.0

func RunIDBTests(t *testing.T, connParams1 interface{}, connParams2 interface{}) context.Context

RunIDBTests s.e.

Types

type ConditionType added in v0.4.0

type ConditionType int

ConditionType s.e.

const (
	// ConditionTypeNone represents no condition
	ConditionTypeNone ConditionType = iota
	// ConditionTypeIn represents "in" condition
	ConditionTypeIn
	// ConditionTypeEq represents "==" condition
	ConditionTypeEq
	// ConditionTypeGt represents ">" condition
	ConditionTypeGt
)

type ContextKeyType added in v0.2.0

type ContextKeyType string

ContextKeyType s.e.

type ErrUnacceptableConditionOnKeyField added in v0.4.0

type ErrUnacceptableConditionOnKeyField struct {
	TableName string
	FieldName string
	Condition int
}

ErrUnacceptableConditionOnKeyField s.e.

func (*ErrUnacceptableConditionOnKeyField) Error added in v0.4.0

type FieldCondition added in v0.4.0

type FieldCondition struct {
	FieldDef      *FieldDef
	ConditionType ConditionType
	Operands      []interface{}
}

FieldCondition represents FieldDef and condition on it

type FieldDef

type FieldDef struct {
	Name      string
	FieldType FieldType
}

FieldDef represents table field definition

type FieldType added in v0.4.0

type FieldType int

FieldType s.e.

const (
	FieldTypeASCII FieldType = iota
	FieldTypeBIGINT
	FieldTypeBLOB
	FieldTypeBOOLEAN
	FieldTypeDATE
	FieldTypeDECIMAL
	FieldTypeDOUBLE
	FieldTypeDURATION
	FieldTypeFLOAT
	FieldTypeINT
	FieldTypeSMALLINT
	FieldTypeTEXT
	FieldTypeTIME
	FieldTypeTIMESTAMP
	FieldTypeTIMEUUID
	FieldTypeTINYINT
	FieldTypeUUID
	FieldTypeVARINT
)

Field types, ref.

type FieldValue added in v0.4.0

type FieldValue struct {
	FieldDef *FieldDef
	Value    interface{}
}

FieldValue is FieldDef with its value used to build condition or to receive result

type GetRequest

type GetRequest struct {
	KeyFields []*FieldValue
	TableDef  *TableDef
	Results   []*FieldValue
}

GetRequest represents select command

func (*GetRequest) Exec added in v0.4.0

func (gr *GetRequest) Exec(ctx context.Context) bool

Exec executes Get request returns if value exists for the key

type GetRequestBuilder

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

GetRequestBuilder s.e.

func NewGetRequest

func NewGetRequest(td *TableDef) *GetRequestBuilder

NewGetRequest s.e.

func (*GetRequestBuilder) Build

func (grb *GetRequestBuilder) Build() *GetRequest

Build returns GetRequest if not all key fields are specified Panics with ErrNonCompleteKey if not all key fields are specified Panics with ErrNothingToSelect if Get() was never called

func (*GetRequestBuilder) Get added in v0.4.0

func (grb *GetRequestBuilder) Get(field *FieldDef, ptrToResultVar interface{}) *GetRequestBuilder

Get adds field to be selected

func (*GetRequestBuilder) Key

func (grb *GetRequestBuilder) Key(field *FieldDef, value interface{}) *GetRequestBuilder

Key adds field+value to be used as key to select operation

type InsertRequest added in v0.4.0

type InsertRequest struct {
	*KeyValue
	TableDef *TableDef
	TTL      int
}

InsertRequest s.e.

func (*InsertRequest) Exec added in v0.4.0

func (ir *InsertRequest) Exec(ctx context.Context) bool

Exec executes Insert operation returns if the inserted value is new for the key

func (*InsertRequest) Put added in v0.4.0

func (ir *InsertRequest) Put(ctx context.Context)

Put executes insert or update operation with no "if exists"

type InsertRequestBuilder added in v0.4.0

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

InsertRequestBuilder s.e.

func NewInsertRequest added in v0.4.0

func NewInsertRequest(td *TableDef) *InsertRequestBuilder

NewInsertRequest s.e.

func (*InsertRequestBuilder) Build added in v0.4.0

func (irb *InsertRequestBuilder) Build() *InsertRequest

Build returns InsertRequest Panics with ErrNonCompleteKey if not all key fields are specified Panics with ErrNothingToSet if not all key fields are specified

func (*InsertRequestBuilder) Key added in v0.4.0

func (irb *InsertRequestBuilder) Key(field *FieldDef, value interface{}) *InsertRequestBuilder

Key adds key field+value definition to be used on insert operation

func (*InsertRequestBuilder) TTL added in v0.4.0

func (irb *InsertRequestBuilder) TTL(ttlValue int) *InsertRequestBuilder

TTL 0 -> uncpecified

func (*InsertRequestBuilder) Val added in v0.4.0

func (irb *InsertRequestBuilder) Val(field *FieldDef, value interface{}) *InsertRequestBuilder

Val adds value field+value to be set on insert operation

type KeyValue added in v0.4.0

type KeyValue struct {
	KeyFields   []*FieldValue
	ValueFields []*FieldValue
}

KeyValue represents basic storage for key and value fields

func (*KeyValue) Key added in v0.4.0

func (kv *KeyValue) Key(field *FieldDef, value interface{})

Key sets key field value

func (*KeyValue) Val added in v0.4.0

func (kv *KeyValue) Val(field *FieldDef, value interface{})

Val sets value field value

type RRBWhereStep added in v0.4.0

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

RRBWhereStep represents where step for Range Request Builder

func (*RRBWhereStep) Eq added in v0.4.0

func (rrbws *RRBWhereStep) Eq(value interface{}) *RangeRequestBuilder

Eq s.e.

func (*RRBWhereStep) Gt added in v0.4.0

func (rrbws *RRBWhereStep) Gt(value interface{}) *RangeRequestBuilder

Gt s.e.

func (*RRBWhereStep) In added in v0.4.0

func (rrbws *RRBWhereStep) In(values ...interface{}) *RangeRequestBuilder

In s.e.

type RangeRequest

type RangeRequest struct {
	TableDef   *TableDef
	Conditions []*FieldCondition
	Results    []*FieldDef
}

RangeRequest represents select with "from" to "to" range instead of exact conditions

func (*RangeRequest) Exec added in v0.4.0

func (rr *RangeRequest) Exec(ctx context.Context) Scan

Exec executes Range request and returns row scanner

type RangeRequestBuilder

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

RangeRequestBuilder s.e.

func NewRangeRequest

func NewRangeRequest(td *TableDef) *RangeRequestBuilder

NewRangeRequest creates new empty RangeRequest

func (*RangeRequestBuilder) Build

func (rrb *RangeRequestBuilder) Build() *RangeRequest

Build returns Range Request Panics with ErrNonCompleteKey if not all key fields are specified Panics with ErrUnacceptableConditionOnKeyField if > condition on partition key field is met (> is acceptable for cluster fields only) Panics with ErrNothingToSelect if Get() was never called

func (*RangeRequestBuilder) Get added in v0.4.0

Get adds field to be selected

func (*RangeRequestBuilder) Where added in v0.4.0

func (rrb *RangeRequestBuilder) Where(field *FieldDef) *RRBWhereStep

Where s.e.

type Scan added in v0.4.0

type Scan func(...interface{}) bool

Scan fills provided dests with values of fields of next row returns if next row existed

type TableBuilder

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

TableBuilder represents table builder instance which holds data to be used to create a table

func NewTable

func NewTable(name string) *TableBuilder

NewTable s.e.

func (*TableBuilder) Build

func (tb *TableBuilder) Build() *TableDef

Build returns TableDef panics with EEmptyPartitionKey if no fields for Partition Key were set

func (*TableBuilder) BuildTemplate added in v0.4.0

func (tb *TableBuilder) BuildTemplate() *TableTemplate

BuildTemplate BuildAbstract returns TableDef with no checks. Used for derive this TableDef

func (*TableBuilder) ClusterKeyField

func (tb *TableBuilder) ClusterKeyField(field *FieldDef) *TableBuilder

ClusterKeyField adds field as cluster key field to a table definition

func (*TableBuilder) DeriveFrom added in v0.4.0

func (tb *TableBuilder) DeriveFrom(tableTemplate *TableTemplate) *TableBuilder

DeriveFrom s.e.

func (*TableBuilder) Field

func (tb *TableBuilder) Field(field *FieldDef) *TableBuilder

Field adds field to a table definition

func (*TableBuilder) PartitionKeyField

func (tb *TableBuilder) PartitionKeyField(field *FieldDef) *TableBuilder

PartitionKeyField adds field as partition key field to a table definition

type TableDef

type TableDef struct {
	UniqueName         string
	PartitionKeyFields []*FieldDef // must not be empty
	ClusterKeyFields   []*FieldDef // may be empty
	Fields             []*FieldDef // may be empty
}

TableDef defines cassandra-like table All fields are non-nil

type TableTemplate added in v0.4.0

type TableTemplate struct {
	*TableDef
}

TableTemplate is used to build template tables to derive from

type URBWhereStep added in v0.4.0

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

URBWhereStep represents where step for Update Request Builder

func (*URBWhereStep) Eq added in v0.4.0

func (urbws *URBWhereStep) Eq(value interface{}) *UpdateRequestBuilder

Eq s.e.

func (*URBWhereStep) Gt added in v0.4.0

func (urbws *URBWhereStep) Gt(value interface{}) *UpdateRequestBuilder

Gt s.e.

func (*URBWhereStep) In added in v0.4.0

func (urbws *URBWhereStep) In(values ...interface{}) *UpdateRequestBuilder

In s.e.

type UpdateRequest added in v0.4.0

type UpdateRequest struct {
	*KeyValue
	TableDef   *TableDef
	Conditions []*FieldCondition
	TTL        int
}

UpdateRequest s.e.

func (*UpdateRequest) Exec added in v0.4.0

func (ur *UpdateRequest) Exec(ctx context.Context) bool

Exec executes Update operation returns if previous value existed for the key and conditions

type UpdateRequestBuilder added in v0.4.0

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

UpdateRequestBuilder s.e.

func NewUpdateRequest added in v0.4.0

func NewUpdateRequest(td *TableDef) *UpdateRequestBuilder

NewUpdateRequest s.e.

func (*UpdateRequestBuilder) Build added in v0.4.0

func (urb *UpdateRequestBuilder) Build() *UpdateRequest

Build returns UpdateRequest Panics with ErrNonCompleteKey if not all key fields are specified

func (*UpdateRequestBuilder) Key added in v0.4.0

func (urb *UpdateRequestBuilder) Key(field *FieldDef, value interface{}) *UpdateRequestBuilder

Key adds key field+value definition to be used on update operation

func (*UpdateRequestBuilder) TTL added in v0.4.0

func (urb *UpdateRequestBuilder) TTL(ttlValue int) *UpdateRequestBuilder

TTL 0 -> unspecified

func (*UpdateRequestBuilder) Val added in v0.4.0

func (urb *UpdateRequestBuilder) Val(field *FieldDef, value interface{}) *UpdateRequestBuilder

Val adds value field+value to be set on update operation

func (*UpdateRequestBuilder) Where added in v0.4.0

func (urb *UpdateRequestBuilder) Where(field *FieldDef) *URBWhereStep

Where s.e.

Jump to

Keyboard shortcuts

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