domino

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2017 License: MIT Imports: 10 Imported by: 0

README

Domino

Build GoDoc

Features: * Fully typesafe fluent syntax DSL * Full Condition and Filter Expression functionality * Static schema definition * Streaming results for Query, Scan and BatchGet operations


sess := session.New(config)
dynamo := dynamodb.New(sess)

//Define your table schema statically
type UserTable struct {
	DynamoTable
	emailField    domino.String
	passwordField domino.String

	registrationDate domino.Numeric
	loginCount       domino.Numeric
	lastLoginDate    domino.Numeric
	vists            domino.NumericSet
	preferences      domino.MapField
	nameField        domino.String
	lastNameField    domino.String

	registrationDateIndex domino.LocalSecondaryIndex
	nameGlobalIndex       domino.GlobalSecondaryIndex
}

type User struct {
	Email       string            `json:"email"`
	Password    string            `json:"password"`
	Visits      []int64           `json:"visits"`
	LoginCount  int               `json:"loginCount"`
	RegDate     int64             `json:"registrationDate"`
	Preferences map[string]string `json:"preferences"`
}

func NewUserTable() MyTable {
	pk := domino.StringField("email")
	rk := domino.StringField("password")
	firstName := domino.StringField("firstName")
	lastName := domino.StringField("lastName")
	reg := domino.NumericField("registrationDate")
	return MyTable{
		DynamoTable{
			Name:         "mytable",
			PartitionKey: pk,
			RangeKey:     rk,
		},
		pk,  //email
		rk,  //password
		reg, //registration
		domino.NumericField("loginCount"),
		domino.NumericField("lastLoginDate"),
		domino.NumericFieldSet("visits"),
		domino.MapField("preferences"),
		firstName,
		lastName,
		domino.LocalSecondaryIndex{"registrationDate-index", reg},
		domino.GlobalSecondaryIndex{"name-index", firstName, lastName},
	}
}

table := NewUserTable()

Use a fluent style DSL to interact with your table. All DynamoDB data operations are supported

Put Item

q := table.
	PutItem(
		User{"naveen@email.com","password"},
	).
	SetConditionExpression(
		table.PartitionKey.NotExists()
	)

out := dynamo.PutItem(q).ExecuteWith(dynamo)

GetItem

q := table.
	GetItem(
		KeyValue{"naveen@email.com", "password"},
	).
	SetConsistentRead(true)

user := &User{}
err = dynamo.GetItem(q, &User{}).ExecuteWith(dynamo).Result(user) //Pass in domain object template object

Update Item

q := table.
	UpdateItem(
		KeyValue{"naveen@email.com", "password"}
	).
	SetUpdateExpression(
		table.loginCount.Increment(1),
		table.lastLoginDate.SetField(time.Now().UnixNano(), false),
		table.registrationDate.SetField(time.Now().UnixNano(), true),
		table.vists.RemoveElemIndex(0),
		table.preferences.RemoveKey("update_email"),
	)
err = dynamo.UpdateItem(q).ExecuteWith(dynamo).Result(nil)

Batch Get Item

q := table.
	BatchGetItem(
		KeyValue{"naveen@email.com", "password"},
		KeyValue{"joe@email.com", "password"},
	).
	SetConsistentRead(true)

	users := []*User{} //Set of unprocessed items (if any), returned by dynamo
	q.ExecuteWith(db).Result(func() interface{} {
		user := User{}
		users = append(users, &user)
		return &user
	})

Fully typesafe condition expression and filter expression support.

expr := Or(
		table.lastNameField.Contains("gattu"),
		Not(table.registrationDate.Contains(12345)),
		And(
			table.visits.Size(lte, 25),
			table.nameField.Size(gte, 25),
		),
		table.lastLoginDate.LessThanOrEq(time.Now().UnixNano()),
	)
q = table.
	Query(
		table.nameField.Equals("naveen"),
		&p,
	).
	SetFilterExpression(expr)


Streaming Results - Allows for lazy data fetching and consuming


	/*Query*/

	p := table.passwordField.BeginsWith("password")
	q := table.
		Query(
			table.emailField.Equals("naveen@email.com"),
			&p,
		).
		SetLimit(100).
		SetScanForward(true)

	channel := make(chan *User)
	errChan := q.ExecuteWith(ctx, db).StreamWithChannel(channel)
	users := []*User{}
  
	for {
		select {
		case u, ok := <-channel:
			if ok {
				users = append(users, u)
			}
		case err = <-errChan:

		}
	}


	/*Scan*/

	p := table.passwordField.BeginsWith("password")
	q := table.Scan().SetLimit(100).

	channel := make(chan *User)
	errChan := q.ExecuteWith(db).StreamWithChannel(channel)

	for {
		select {
		case u, ok := <-channel:
			if ok {
				fmt.Println(u)
			}
		case err = <-errChan:

		}
	}

Documentation

Index

Constants

View Source
const (
	ProjectionTypeALL       = "ALL"
	ProjectionTypeINCLUDE   = "INCLUDE"
	ProjectionTypeKEYS_ONLY = "KEYS_ONLY"
)

Variables

This section is empty.

Functions

func Not

func Not(c Expression) negation

Not represents the dynamo NOT operator

Types

type Binary

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

Binary - A binary dynamo field

func BinaryField

func BinaryField(name string) Binary

BinaryField ... A constructor for a binary dynamo field

type BinarySet

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

BinarySet - A binary dynamo field

func BinarySetField

func BinarySetField(name string) BinarySet

BinarySetField ... A constructor for a binary set dynamo field

func (*BinarySet) Append

func (Field *BinarySet) Append(a interface{}) *UpdateExpression

Append appends an element to a list Field

func (*BinarySet) RemoveElemIndex

func (Field *BinarySet) RemoveElemIndex(idx uint) *UpdateExpression

RemoveElemIndex removes an element from collection Field index

type Bool

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

Bool - A boolean dynamo field

func BoolField

func BoolField(name string) Bool

StringField ... A constructor for a string dynamo field

type Condition

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

func (Condition) String

func (c Condition) String() string

type DynamoDBIFace

DynamoDBIFace is the interface to the underlying aws dynamo db api

type DynamoDBValue

type DynamoDBValue map[string]*dynamodb.AttributeValue

type DynamoField

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

func (*DynamoField) BeginsWith

func (p *DynamoField) BeginsWith(a interface{}) KeyCondition

func (*DynamoField) Between

func (p *DynamoField) Between(a interface{}, b interface{}) KeyCondition

func (*DynamoField) Contains

func (p *DynamoField) Contains(a interface{}) Condition

Contains represents the dynamo contains operator

func (*DynamoField) Equals

func (p *DynamoField) Equals(a interface{}) KeyCondition

func (*DynamoField) Exists

func (p *DynamoField) Exists() Condition

Exists represents the dynamo attribute_exists operator

func (*DynamoField) GreaterThan

func (p *DynamoField) GreaterThan(a interface{}) KeyCondition

func (*DynamoField) GreaterThanOrEq

func (p *DynamoField) GreaterThanOrEq(a interface{}) KeyCondition

func (*DynamoField) In

func (p *DynamoField) In(elems ...interface{}) Condition

In represents the dynamo 'in' operator

func (DynamoField) IsEmpty

func (d DynamoField) IsEmpty() bool

func (*DynamoField) LessThan

func (p *DynamoField) LessThan(a interface{}) KeyCondition

func (*DynamoField) LessThanOrEq

func (p *DynamoField) LessThanOrEq(a interface{}) KeyCondition

func (DynamoField) Name

func (d DynamoField) Name() string

func (*DynamoField) NotEquals

func (p *DynamoField) NotEquals(a interface{}) KeyCondition

func (*DynamoField) NotExists

func (p *DynamoField) NotExists() Condition

NotExists represents the dynamo attribute_not_exists operator

func (*DynamoField) RemoveField

func (Field *DynamoField) RemoveField() *UpdateExpression

RemoveField removes a dynamo Field.

func (*DynamoField) SetField

func (Field *DynamoField) SetField(a interface{}, onlyIfEmpty bool) *UpdateExpression

SetField sets a dynamo Field. Set onlyIfEmpty to true if you want to prevent overwrites

func (*DynamoField) Size

func (p *DynamoField) Size(op string, a interface{}) Condition

Contains represents the dynamo contains size

func (DynamoField) Type

func (d DynamoField) Type() string

type DynamoFieldIFace

type DynamoFieldIFace interface {
	Name() string
	Type() string
	IsEmpty() bool
}

type DynamoTable

type DynamoTable struct {
	Name                   string
	PartitionKey           DynamoFieldIFace
	RangeKey               DynamoFieldIFace //Optional param. If no range key set to EmptyDynamoField()
	GlobalSecondaryIndexes []GlobalSecondaryIndex
	LocalSecondaryIndexes  []LocalSecondaryIndex
}

DynamoTable is a static table definition representing a dynamo table

func (DynamoTable) BatchGetItem

func (table DynamoTable) BatchGetItem(items ...KeyValue) *batchGetInput

BatchGetItem represents dynamo batch get item call

func (DynamoTable) BatchWriteItem

func (table DynamoTable) BatchWriteItem() *batchWriteInput

BatchWriteItem represents dynamo batch write item call

func (DynamoTable) CreateTable

func (table DynamoTable) CreateTable() *createTable

func (DynamoTable) DeleteItem

func (table DynamoTable) DeleteItem(key KeyValue) *deleteItemInput

DeleteItemInput represents dynamo delete item call

func (DynamoTable) DeleteTable

func (table DynamoTable) DeleteTable() *deleteTable

func (DynamoTable) GetItem

func (table DynamoTable) GetItem(key KeyValue) *getInput

GetItem Primary constructor for creating a get item query

func (DynamoTable) PutItem

func (table DynamoTable) PutItem(i interface{}) *putInput

PutItem represents dynamo put item call

func (DynamoTable) Query

func (table DynamoTable) Query(partitionKeyCondition KeyCondition, rangeKeyCondition *KeyCondition) *QueryInput

QueryInput represents dynamo batch get item call

func (DynamoTable) Scan

func (table DynamoTable) Scan() (q *ScanInput)

ScanOutput represents dynamo scan item call

func (DynamoTable) UpdateItem

func (table DynamoTable) UpdateItem(key KeyValue) *UpdateInput

UpdateInputItem represents dynamo batch get item call

type Empty

type Empty struct {
	DynamoField
}

Empty - An empty dynamo field

func EmptyField

func EmptyField() Empty

EmptyField ... A constructor for an empty dynamo field

type Expression

type Expression interface {
	// contains filtered or unexported methods
}

Expression represents a dynamo Condition expression, i.e. And(if_empty(...), size(path) >0)

type ExpressionGroup

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

func And

func And(c ...Expression) ExpressionGroup

And represents a dynamo AND expression. All expressions are and'd together

func Or

func Or(c ...Expression) ExpressionGroup

Or represents a dynamo OR expression. All expressions are or'd together

func (ExpressionGroup) String

func (c ExpressionGroup) String() string

String stringifies expressions for easy debugging

type GlobalSecondaryIndex

type GlobalSecondaryIndex struct {
	Name             string
	PartitionKey     DynamoFieldIFace
	RangeKey         DynamoFieldIFace //Optional param. If no range key set to EmptyField
	ProjectionType   string
	NonKeyAttributes []DynamoFieldIFace
	ReadUnits        int64
	WriteUnits       int64
}

GlobalSecondaryIndex ... Represents a dynamo global secondary index

type KeyCondition

type KeyCondition struct {
	Condition
}

type KeyValue

type KeyValue struct {
	PartitionKey interface{}
	RangeKey     interface{}
}

KeyValue ... A Key Value struct for use in GetItem and BatchWriteItem queries

type Keys

type List

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

List - A list dynamo field

func ListField

func ListField(name string) List

ListField ... A constructor for a list dynamo field

func (*List) Append

func (Field *List) Append(a interface{}) *UpdateExpression

Append appends an element to a list Field

func (*List) RemoveElemIndex

func (Field *List) RemoveElemIndex(idx uint) *UpdateExpression

RemoveElemIndex removes an element from collection Field index

type Loader

type Loader interface {
	LoadDynamoDBValue(av DynamoDBValue) (err error)
}

Loader is the interface that specifies the ability to deserialize and load data from dynamodb attrbiute value map

type LocalSecondaryIndex

type LocalSecondaryIndex struct {
	Name             string
	PartitionKey     DynamoFieldIFace
	SortKey          DynamoFieldIFace
	ProjectionType   string
	NonKeyAttributes []DynamoFieldIFace
}

LocalSecondaryIndex ... Represents a dynamo local secondary index

type Map

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

Map - A map dynamo field

func MapField

func MapField(name string) Map

MapField ... A constructor for a map dynamo field

func (*Map) Append

func (Field *Map) Append(a interface{}) *UpdateExpression

Append appends an element to a list Field

func (*Map) RemoveElemIndex

func (Field *Map) RemoveElemIndex(idx uint) *UpdateExpression

RemoveElemIndex removes an element from collection Field index

func (*Map) RemoveKey

func (Field *Map) RemoveKey(s string) *UpdateExpression

RemoveKey removes an element from a map Field

type Numeric

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

Numeric - A numeric dynamo field

func NumericField

func NumericField(name string) Numeric

NumericField ... A constructor for a numeric dynamo field

func (*Numeric) Add

func (Field *Numeric) Add(amount float64) *UpdateExpression

Add adds an amount to dynamo numeric Field

func (*Numeric) Decrement

func (Field *Numeric) Decrement(by uint) *UpdateExpression

Decrement a numeric counter Field

func (*Numeric) Increment

func (Field *Numeric) Increment(by uint) *UpdateExpression

Increment a numeric counter Field

type NumericSet

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

NumericSet - A numeric set dynamo field

func NumericSetField

func NumericSetField(name string) NumericSet

NumericSetField ... A constructor for a numeric set dynamo field

func (*NumericSet) Append

func (Field *NumericSet) Append(a interface{}) *UpdateExpression

Append appends an element to a list Field

func (*NumericSet) RemoveElemIndex

func (Field *NumericSet) RemoveElemIndex(idx uint) *UpdateExpression

RemoveElemIndex removes an element from collection Field index

type QueryInput

type QueryInput struct {
	*dynamodb.QueryInput
	// contains filtered or unexported fields
}

************************************************************************************* ********************************************* Query ********************************* *************************************************************************************

func (*QueryInput) Build

func (d *QueryInput) Build() *dynamodb.QueryInput

func (*QueryInput) ExecuteWith

func (d *QueryInput) ExecuteWith(ctx context.Context, db DynamoDBIFace, opts ...request.Option) (out *QueryOutput)

func (*QueryInput) SetAttributesToGet

func (d *QueryInput) SetAttributesToGet(fields []DynamoField) *QueryInput

func (*QueryInput) SetConsistentRead

func (d *QueryInput) SetConsistentRead(c bool) *QueryInput

func (*QueryInput) SetFilterExpression

func (d *QueryInput) SetFilterExpression(c Expression) *QueryInput

func (*QueryInput) SetGlobalIndex

func (d *QueryInput) SetGlobalIndex(idx GlobalSecondaryIndex) *QueryInput

func (*QueryInput) SetLimit

func (d *QueryInput) SetLimit(limit int) *QueryInput

func (*QueryInput) SetLocalIndex

func (d *QueryInput) SetLocalIndex(idx LocalSecondaryIndex) *QueryInput

func (*QueryInput) SetPageSize

func (d *QueryInput) SetPageSize(pageSize int) *QueryInput

func (*QueryInput) SetScanForward

func (d *QueryInput) SetScanForward(forward bool) *QueryInput

func (*QueryInput) WithConsumedCapacityHandler

func (d *QueryInput) WithConsumedCapacityHandler(f func(*dynamodb.ConsumedCapacity)) *QueryInput

type QueryOutput

type QueryOutput struct {
	Error error
	// contains filtered or unexported fields
}

func (*QueryOutput) Results

func (o *QueryOutput) Results(next func() interface{}) (err error)

func (*QueryOutput) StreamWithChannel

func (o *QueryOutput) StreamWithChannel(channel interface{}) (errChan chan error)

type ScanInput

type ScanInput struct {
	*dynamodb.ScanInput
	// contains filtered or unexported fields
}

************************************************************************************* ********************************************* Scan ********************************* *************************************************************************************

func (*ScanInput) Build

func (d *ScanInput) Build() *dynamodb.ScanInput

func (*ScanInput) ExecuteWith

func (d *ScanInput) ExecuteWith(ctx context.Context, db DynamoDBIFace, opts ...request.Option) (out *ScanOutput)

*

** ExecuteWith ... Execute a dynamo Scan call with a passed in dynamodb instance and next item pointer
** dynamo - The underlying dynamodb api
** nextItem - The item pointer function, which is called on each new object returned from dynamodb. The function SHOULD NOT
** 		   store each item. It should simply return an empty struct pointer. Each of which is hydrated and pushed on
** 		   the returned channel.
**

func (*ScanInput) SetAttributesToGet

func (d *ScanInput) SetAttributesToGet(fields []DynamoField) *ScanInput

func (*ScanInput) SetConsistentRead

func (d *ScanInput) SetConsistentRead(c bool) *ScanInput

func (*ScanInput) SetFilterExpression

func (d *ScanInput) SetFilterExpression(c Expression) *ScanInput

func (*ScanInput) SetGlobalIndex

func (d *ScanInput) SetGlobalIndex(idx GlobalSecondaryIndex) *ScanInput

func (*ScanInput) SetLimit

func (d *ScanInput) SetLimit(limit int) *ScanInput

func (*ScanInput) SetLocalIndex

func (d *ScanInput) SetLocalIndex(idx LocalSecondaryIndex) *ScanInput

func (*ScanInput) SetPageSize

func (d *ScanInput) SetPageSize(pageSize int) *ScanInput

type ScanOutput

type ScanOutput struct {
	Error error
	// contains filtered or unexported fields
}

func (*ScanOutput) Results

func (o *ScanOutput) Results(next func() interface{}) (err error)

func (*ScanOutput) StreamWithChannel

func (o *ScanOutput) StreamWithChannel(channel interface{}) (errChan chan error)

type String

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

String - A string dynamo field

func StringField

func StringField(name string) String

StringField ... A constructor for a string dynamo field

type StringSet

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

StringSet - A string set dynamo field

func StringSetField

func StringSetField(name string) StringSet

StringSetField ... A constructor for a string set dynamo field

func (*StringSet) Append

func (Field *StringSet) Append(a interface{}) *UpdateExpression

Append appends an element to a list Field

func (*StringSet) RemoveElemIndex

func (Field *StringSet) RemoveElemIndex(idx uint) *UpdateExpression

RemoveElemIndex removes an element from collection Field index

type TableName

type TableName string

type ToValue

type ToValue interface {
	ToDynamoDBValue() (bm interface{})
}

ToValue is the interface that specifies the ability to serialize data to a value that can be persisted in dynamodb

type UpdateExpression

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

******************************************************************************* ******************************* Update Expressions **************************** *******************************************************************************

type UpdateInput

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

************************************************************************************* ********************************** UpdateItem *************************************** *************************************************************************************

func (*UpdateInput) Build

func (d *UpdateInput) Build() *dynamodb.UpdateItemInput

func (*UpdateInput) ExecuteWith

func (d *UpdateInput) ExecuteWith(ctx context.Context, dynamo DynamoDBIFace, opts ...request.Option) (out *UpdateOutput)

*

** ExecuteWith ... Execute a dynamo BatchGetItem call with a passed in dynamodb instance
** ctx - an instance of context
** dynamo - The underlying dynamodb api
**

func (*UpdateInput) ReturnAllNew

func (d *UpdateInput) ReturnAllNew() *UpdateInput

func (*UpdateInput) ReturnAllOld

func (d *UpdateInput) ReturnAllOld() *UpdateInput

func (*UpdateInput) ReturnNone

func (d *UpdateInput) ReturnNone() *UpdateInput

func (*UpdateInput) ReturnUpdatedNew

func (d *UpdateInput) ReturnUpdatedNew() *UpdateInput

func (*UpdateInput) ReturnUpdatedOld

func (d *UpdateInput) ReturnUpdatedOld() *UpdateInput

func (*UpdateInput) SetConditionExpression

func (d *UpdateInput) SetConditionExpression(c Expression) *UpdateInput

func (*UpdateInput) SetUpdateExpression

func (d *UpdateInput) SetUpdateExpression(exprs ...*UpdateExpression) *UpdateInput

type UpdateOutput

type UpdateOutput struct {
	*dynamodb.UpdateItemOutput
	Error error
}

func (*UpdateOutput) Result

func (o *UpdateOutput) Result(item interface{}) (err error)

Jump to

Keyboard shortcuts

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