Documentation ¶
Overview ¶
Package goriak is a Golang driver for Riak KV. Goriak offers simple ways of binding your Go datatypes and values to Riak.
Goriaks specially is dealing with Riak KV Data Types (http://docs.basho.com/riak/kv/2.1.4/developing/data-types/) and allowing Marshal/Unmarshal of Go structs into Riak Maps.
Index ¶
- func NewMapOperation() riak.MapOperation
- type AllKeysCommand
- type Command
- func (c *Command) AllKeys(callback func([]string) error) *AllKeysCommand
- func (c *Command) Delete(key string) *DeleteCommand
- func (c *Command) Get(key string, output interface{}) *MapGetCommand
- func (c *Command) GetJSON(key string, output interface{}) *GetRawCommand
- func (c *Command) GetRaw(key string, output *[]byte) *GetRawCommand
- func (c *Command) KeysInIndex(indexName, indexValue string, callback func(SecondaryIndexQueryResult)) *CommandKeysInIndex
- func (c *Command) MapOperation(op riak.MapOperation) *MapOperationCommand
- func (cmd *Command) Set(val interface{}) *MapSetCommand
- func (c *Command) SetJSON(value interface{}) *SetRawCommand
- func (c *Command) SetRaw(value []byte) *SetRawCommand
- type CommandKeysInIndex
- type ConflictObject
- type ConflictResolver
- type ConnectOpts
- type Counter
- type DeleteCommand
- func (c *DeleteCommand) Run(session *Session) (*Result, error)
- func (c *DeleteCommand) WithDw(dw uint32) *DeleteCommand
- func (c *DeleteCommand) WithPr(pr uint32) *DeleteCommand
- func (c *DeleteCommand) WithPw(pw uint32) *DeleteCommand
- func (c *DeleteCommand) WithR(r uint32) *DeleteCommand
- func (c *DeleteCommand) WithW(w uint32) *DeleteCommand
- type Flag
- type GetRawCommand
- type KeysInIndexResult
- type MapGetCommand
- type MapOperationCommand
- type MapSetCommand
- func (c *MapSetCommand) FilterExclude(path ...string) *MapSetCommand
- func (c *MapSetCommand) FilterInclude(path ...string) *MapSetCommand
- func (c *MapSetCommand) Key(key string) *MapSetCommand
- func (c *MapSetCommand) Run(session *Session) (*Result, error)
- func (c *MapSetCommand) WithDw(dw uint32) *MapSetCommand
- func (c *MapSetCommand) WithPw(pw uint32) *MapSetCommand
- func (c *MapSetCommand) WithW(w uint32) *MapSetCommand
- type Register
- func (r *Register) Exec(client *Session) error
- func (r Register) MarshalJSON() ([]byte, error)
- func (r *Register) Set(val []byte) *Register
- func (r *Register) SetString(val string) *Register
- func (r *Register) String() string
- func (r *Register) UnmarshalJSON(data []byte) error
- func (r *Register) Value() []byte
- type ResolvedConflict
- type Result
- type SecondaryIndexQueryResult
- type Session
- type Set
- func (s *Set) Add(add []byte) *Set
- func (s *Set) AddString(add string) *Set
- func (s *Set) Exec(client *Session) error
- func (s *Set) Has(search []byte) bool
- func (s *Set) HasString(search string) bool
- func (s Set) MarshalJSON() ([]byte, error)
- func (s *Set) Remove(remove []byte) *Set
- func (s *Set) RemoveString(remove string) *Set
- func (s *Set) Strings() []string
- func (s *Set) UnmarshalJSON(data []byte) error
- func (s *Set) Value() [][]byte
- type SetRawCommand
- func (c *SetRawCommand) AddToIndex(key, value string) *SetRawCommand
- func (c *SetRawCommand) Key(key string) *SetRawCommand
- func (c *SetRawCommand) Run(session *Session) (*Result, error)
- func (c *SetRawCommand) WithContext(val []byte) *SetRawCommand
- func (c *SetRawCommand) WithDw(val uint32) *SetRawCommand
- func (c *SetRawCommand) WithPw(val uint32) *SetRawCommand
- func (c *SetRawCommand) WithW(val uint32) *SetRawCommand
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMapOperation ¶
func NewMapOperation() riak.MapOperation
NewMapOperation returns a new riak.MapOperation that you can for advanced Riak operations
Types ¶
type AllKeysCommand ¶
type AllKeysCommand struct {
// contains filtered or unexported fields
}
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command is the main query builder object
func Bucket ¶
Bucket specifies the bucket and bucket type that your following command will be performed on.
func (*Command) AllKeys ¶
func (c *Command) AllKeys(callback func([]string) error) *AllKeysCommand
AllKeys returns all keys in the set bucket. The response will be sent in multiple batches to callback
func (*Command) Delete ¶
func (c *Command) Delete(key string) *DeleteCommand
Delete deletes the value stored as key
func (*Command) Get ¶
func (c *Command) Get(key string, output interface{}) *MapGetCommand
Get retreives a Map from Riak. Get performs automatic conversion from Riak Maps to your Go datatype. See Set() for more information.
func (*Command) GetJSON ¶
func (c *Command) GetJSON(key string, output interface{}) *GetRawCommand
GetJSON is the same as GetRaw, but with automatic JSON unmarshalling
func (*Command) GetRaw ¶
func (c *Command) GetRaw(key string, output *[]byte) *GetRawCommand
GetRaw retreives key as a []byte. The output will be written to output by Run().
func (*Command) KeysInIndex ¶
func (c *Command) KeysInIndex(indexName, indexValue string, callback func(SecondaryIndexQueryResult)) *CommandKeysInIndex
KeysInIndex returns all keys in the index indexName that has the value indexValue The values will be returned to the callbak function When all keys have been returned SecondaryIndexQueryResult.IsComplete will be true
func (*Command) MapOperation ¶
func (c *Command) MapOperation(op riak.MapOperation) *MapOperationCommand
MapOperation takes a riak.MapOperation so that you can run custom commands on your Riak Maps
func (*Command) Set ¶
func (cmd *Command) Set(val interface{}) *MapSetCommand
Set automatically converts your Go datatype to the equivalent type in Riak
| Go Type | Riak Type | |------------|-----------| | struct | map | | string | register | | [n]byte | register | | []byte | register | | []slice | set | | []slice | set | | [][]byte | set | | map | map | | time.Time | register |
func (*Command) SetJSON ¶
func (c *Command) SetJSON(value interface{}) *SetRawCommand
SetJSON saves value as key in the bucket bucket/bucketType Values can automatically be added to indexes with the struct tag goriakindex
func (*Command) SetRaw ¶
func (c *Command) SetRaw(value []byte) *SetRawCommand
SetRaw allows you to set a []byte directly to Riak. SetRaw gives you full control of the data stored, compared to SetJSON and Set.
type CommandKeysInIndex ¶
type CommandKeysInIndex struct {
// contains filtered or unexported fields
}
func (*CommandKeysInIndex) IndexContinuation ¶
func (c *CommandKeysInIndex) IndexContinuation(continuation []byte) *CommandKeysInIndex
func (*CommandKeysInIndex) Limit ¶
func (c *CommandKeysInIndex) Limit(limit uint32) *CommandKeysInIndex
Limit sets the limit returned in KeysInIndex A limit of 0 means unlimited
func (*CommandKeysInIndex) Run ¶
func (c *CommandKeysInIndex) Run(session *Session) (*KeysInIndexResult, error)
type ConflictObject ¶
func (ConflictObject) GetResolved ¶
func (r ConflictObject) GetResolved() ResolvedConflict
GetResolved creates a ResolvedConflict object
type ConflictResolver ¶
type ConflictResolver interface {
ConflictResolver([]ConflictObject) ResolvedConflict
}
The ConflictResolver interface is used to solve conflicts when using Get() and GetJSON(). All versions will be sent to your ConflictResolver method. Return the (merged) version that you want to keep.
Example ¶
// For this to work you need to activate allow_mult on your bucket type // http://docs.basho.com/riak/kv/2.2.0/developing/usage/conflict-resolution/ session, _ := Connect(ConnectOpts{ Address: "127.0.0.1", }) key := "object-1" // Save the same object without using .VClock() causing a conflict _, err := Bucket("bucket", "tests").SetJSON("hello").Key(key).Run(session) if err != nil { log.Println(err) } _, err = Bucket("bucket", "tests").SetJSON("worlds of conflicts!").Key(key).Run(session) if err != nil { log.Println(err) } // Our conflict resolver object resolver := func(objs []ConflictObject) ResolvedConflict { // Decide how to pick the result. We'll use len() to pick the longest value var maxObject ConflictObject var maxValue int for _, o := range objs { if len(o.Value) > maxValue { maxObject = o maxValue = len(o.Value) } } // Convert directly to a ResolvedConflict object return maxObject.GetResolved() } // Get your object var res string _, err = Bucket("bucket", "tests"). GetJSON(key, &res). ConflictResolver(resolver). Run(session) if err != nil { log.Println(err) } // res will now contain the longest value log.Println(res)
Output:
type ConnectOpts ¶
type ConnectOpts struct { // Both Address and Addresses should be on the form HOST|IP[:PORT] Address string // Address to a single Riak host. Will be used in case Addresses is empty Addresses []string // Addresses to all Riak hosts. }
ConnectOpts are the available options for connecting to your Riak instance
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a wapper to handle Riak Counters Counter needs to be initialized by GetMap() to fully function
func NewCounter ¶
func NewCounter() *Counter
NewCounter returns a partial Counter Counters returned by NewCounter() can only be updated with SetMap(). Counter.Exec() will not work on counters returned by NewCounter()
func (*Counter) Exec ¶
Exec saves changes made to the Counter to Riak Exec only works on Counters initialized by GetMap() If the commad succeeds the counter will be updated with the value in the response from Riak
func (*Counter) Increase ¶
Increase the value in the Counter by i The value in Counter.Value() will be updated directly Increase() will not save the changes to Riak directly
func (Counter) MarshalJSON ¶
MarshalJSON satisfies the JSON interface
func (*Counter) UnmarshalJSON ¶
UnmarshalJSON satisfies the JSON interface
type DeleteCommand ¶
type DeleteCommand struct {
// contains filtered or unexported fields
}
func (*DeleteCommand) WithDw ¶
func (c *DeleteCommand) WithDw(dw uint32) *DeleteCommand
func (*DeleteCommand) WithPr ¶
func (c *DeleteCommand) WithPr(pr uint32) *DeleteCommand
func (*DeleteCommand) WithPw ¶
func (c *DeleteCommand) WithPw(pw uint32) *DeleteCommand
func (*DeleteCommand) WithR ¶
func (c *DeleteCommand) WithR(r uint32) *DeleteCommand
func (*DeleteCommand) WithW ¶
func (c *DeleteCommand) WithW(w uint32) *DeleteCommand
type Flag ¶
type Flag struct {
// contains filtered or unexported fields
}
func (Flag) MarshalJSON ¶
MarshalJSON satisfies the JSON interface
func (*Flag) UnmarshalJSON ¶
UnmarshalJSON satisfies the JSON interface
type GetRawCommand ¶
type GetRawCommand struct {
// contains filtered or unexported fields
}
func (*GetRawCommand) ConflictResolver ¶
func (c *GetRawCommand) ConflictResolver(fn func([]ConflictObject) ResolvedConflict) *GetRawCommand
func (*GetRawCommand) WithPr ¶
func (c *GetRawCommand) WithPr(pr uint32) *GetRawCommand
func (*GetRawCommand) WithR ¶
func (c *GetRawCommand) WithR(r uint32) *GetRawCommand
type KeysInIndexResult ¶
type KeysInIndexResult struct {
Continuation []byte
}
type MapGetCommand ¶
type MapGetCommand struct {
// contains filtered or unexported fields
}
type MapOperationCommand ¶
type MapOperationCommand struct {
// contains filtered or unexported fields
}
func (*MapOperationCommand) Context ¶
func (c *MapOperationCommand) Context(ctx []byte) *MapOperationCommand
func (*MapOperationCommand) Key ¶
func (c *MapOperationCommand) Key(key string) *MapOperationCommand
type MapSetCommand ¶
type MapSetCommand struct {
// contains filtered or unexported fields
}
func (*MapSetCommand) FilterExclude ¶
func (c *MapSetCommand) FilterExclude(path ...string) *MapSetCommand
FilterExclude does the opposite of FilterInclude. See FinterInclude for more info.
func (*MapSetCommand) FilterInclude ¶
func (c *MapSetCommand) FilterInclude(path ...string) *MapSetCommand
FilterInclude adds a include filter to Set(). Call FilterInclude("A") to only include the field A (and children). Can be combined with FilterExclude() to form more complicated patterns. Use FilterInclude or FilterExclude without parameters to include/exclude the root object. If the same field is both included and excluded the include is prioritized.
func (*MapSetCommand) Key ¶
func (c *MapSetCommand) Key(key string) *MapSetCommand
func (*MapSetCommand) WithDw ¶
func (c *MapSetCommand) WithDw(dw uint32) *MapSetCommand
func (*MapSetCommand) WithPw ¶
func (c *MapSetCommand) WithPw(pw uint32) *MapSetCommand
func (*MapSetCommand) WithW ¶
func (c *MapSetCommand) WithW(w uint32) *MapSetCommand
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
func NewRegister ¶
func NewRegister() *Register
func (Register) MarshalJSON ¶
MarshalJSON satisfies the JSON interface
func (*Register) UnmarshalJSON ¶
UnmarshalJSON satisfies the JSON interface
type ResolvedConflict ¶
type Result ¶
type Result struct { NotFound bool // Wether or not the item was not found when using Get, GetJSON, or GetRaw. Key string // Returns your automatically generated key when using Set, SetJSON, or SetRaw. Context []byte // Returns the Riak Context used in map operations. Is set when using Get. }
Result contains your query result data from Run()
type SecondaryIndexQueryResult ¶
SecondaryIndexQueryResult is the items sent to the callback function used by KeysInIndex
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session holds the connection to Riak
func Connect ¶
func Connect(opts ConnectOpts) (*Session, error)
Connect creates a new Riak connection. See ConnectOpts for the available options.
type Set ¶ added in v1.1.0
type Set struct {
// contains filtered or unexported fields
}
Set is a special type to make it easier to work with Riak Sets in Go.
Example ¶
session, _ := Connect(ConnectOpts{ Address: "127.0.0.1", }) type Article struct { Tags *Set Context []byte `goriak:"goriakcontext"` } // Initializing a new Article and the Set within art := Article{ Tags: NewSet(), } riakKey := "article-1" // Adding the tags "one" and "two" art.Tags.AddString("one") art.Tags.AddString("two") _, err := Bucket("bucket", "bucketType").Set(art).Key(riakKey).Run(session) if err != nil { // .. } // Retreiving from Riak var getArt Article _, err = Bucket("bucket", "bucketType").Get(riakKey, &getArt).Run(session) if err != nil { // .. } // Adding one extra tag. // Multiple AddString() and RemoveString() can be chained together before calling Exec(). err = getArt.Tags.AddString("three").Exec(session) if err != nil { // .. }
Output:
func NewSet ¶ added in v1.1.0
func NewSet() *Set
NewSet returnes a new and empty Set. Sets returned from NewSet() can not be used with Set.Exec()
func (*Set) Add ¶ added in v1.1.0
Add adds an item to the direct value of the Set. Save the changes to Riak with Set.Exec() or SetMap().
func (*Set) Exec ¶ added in v1.1.0
Exec executes the diff created by Add() and Remove(), and saves the data to Riak
func (Set) MarshalJSON ¶
MarshalJSON satisfies the JSON interface
func (*Set) Remove ¶ added in v1.1.0
Remove deletes an item to the direct value of the Set. Save the changes to Riak with Set.Exec() or SetMap().
func (*Set) RemoveString ¶ added in v1.1.0
RemoveString is a shortcut to Remove
func (*Set) Strings ¶ added in v1.1.0
Strings returns the same data as Value(), but encoded as strings
func (*Set) UnmarshalJSON ¶
UnmarshalJSON satisfies the JSON interface
type SetRawCommand ¶
type SetRawCommand struct {
// contains filtered or unexported fields
}
func (*SetRawCommand) AddToIndex ¶
func (c *SetRawCommand) AddToIndex(key, value string) *SetRawCommand
func (*SetRawCommand) Key ¶
func (c *SetRawCommand) Key(key string) *SetRawCommand
func (*SetRawCommand) Run ¶
func (c *SetRawCommand) Run(session *Session) (*Result, error)
buildStoreValueCommand completes the building if the StoreValueCommand used by SetRaw and SetJSON
func (*SetRawCommand) WithContext ¶
func (c *SetRawCommand) WithContext(val []byte) *SetRawCommand
func (*SetRawCommand) WithDw ¶
func (c *SetRawCommand) WithDw(val uint32) *SetRawCommand
Durable writes (to backend storage)
func (*SetRawCommand) WithPw ¶
func (c *SetRawCommand) WithPw(val uint32) *SetRawCommand
Primary node writes