// Define a basic document to reduce API calls
type Document struct {
Bucket string
Key string
Value []byte
Links []*Link
JSONObject interface{}
}
This encapsulates most of the values that I was passing as parameters to the functions. Since Riak is a key/value it is pretty straight forward that a Put(doc) will store the for the string Key the bytes in Value. However if JSONObject != nil then it will marshal it. This works in reverse for Get(doc) if the JSONObject != nil then it will unmarshal.
// Definition of a link from one document to another
type Link struct {
Bucket string
Key string
Tag string
}
Link between documents is such a simple feature but is also very powerful. Using links can quickly turn a key/value database into a graph. Specifically with the linkwalking that will allow traversal of the graph. To support it I just had to parse and set the header "Link:". Both Put and Get now support storing or retrieving the list of Links associated with a document.
The API now:
PutWDWReturn(doc *Document, w, dw int, returnObject bool)
Put(doc *Document)
DeleteRW(bucketName, key string, rw int)
Delete(bucketName, key string)
GetR(doc *Document, r int)
Get(doc *Document)
The methods with r,w,dw and rw are all wrappers around the Riak REST API. The default is to use whatever the bucket is configured for node persistence control. Since the expectation is the exception that to override the bucket default configuration I provide the wrapper like Get that wraps GetR to save typing.
Next on my list to implement is LinkWalking!
Next on my list to implement is LinkWalking!
0 comments:
Post a Comment