Models to facilitate some common interactions with Riak documents.
Project description
Riak Docs
=========
This is a little module to save me time by modeling Riak docs and then providing common operations.
It is nowhere near complete and is probably unsuitable for whatever you want to do. Do NOT use this in production
unless you know what you're doing and by that I mean: you're me.
Example Usage
=============
:::python
from riakdoc.documents import BaseDocument
from riakdoc.indexes import StrFieldsIndex
from blinker import signal
class MyDoc(BaseDocument):
"""
Create a Riak document that:
1. Automatically creates a 2i index called "complex_index" which holds an id and category as {id}_{cat}
2. Initializes data if created without data.
"""
complex_index = StrFieldsIndex(['id', 'person.category'])
def initialize_data(self, *args, **kwargs):
# Extra args/kwargs are passed to the initialize_data call, making it easy to pass data to help init docs.
return {'id': self.key, 'violations': [], 'tag': kwargs.get('tag', '')}
# Listen for the post save event, but only from MyDoc, and then print.
def announce(sender, **kwargs):
print "just saved: {0}".format(kwargs.pop('document').data)
signal('post-document save').connect(announce, sender=MyDoc)
doc = MyDoc('abc1', tag='noodle')
# Doc can be accessed like a dict since initialize_data(), above, returns a dict.
doc['person'] = {'category': 'engineer'}
print doc.complex_index # prints "abc1_engineer"
doc.save() # stores to Riak, prints "just saved: {'id': 'abc1', 'tag': 'noodle', 'person': ..."
=========
This is a little module to save me time by modeling Riak docs and then providing common operations.
It is nowhere near complete and is probably unsuitable for whatever you want to do. Do NOT use this in production
unless you know what you're doing and by that I mean: you're me.
Example Usage
=============
:::python
from riakdoc.documents import BaseDocument
from riakdoc.indexes import StrFieldsIndex
from blinker import signal
class MyDoc(BaseDocument):
"""
Create a Riak document that:
1. Automatically creates a 2i index called "complex_index" which holds an id and category as {id}_{cat}
2. Initializes data if created without data.
"""
complex_index = StrFieldsIndex(['id', 'person.category'])
def initialize_data(self, *args, **kwargs):
# Extra args/kwargs are passed to the initialize_data call, making it easy to pass data to help init docs.
return {'id': self.key, 'violations': [], 'tag': kwargs.get('tag', '')}
# Listen for the post save event, but only from MyDoc, and then print.
def announce(sender, **kwargs):
print "just saved: {0}".format(kwargs.pop('document').data)
signal('post-document save').connect(announce, sender=MyDoc)
doc = MyDoc('abc1', tag='noodle')
# Doc can be accessed like a dict since initialize_data(), above, returns a dict.
doc['person'] = {'category': 'engineer'}
print doc.complex_index # prints "abc1_engineer"
doc.save() # stores to Riak, prints "just saved: {'id': 'abc1', 'tag': 'noodle', 'person': ..."
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
riak-docs-0.1.3.zip
(10.3 kB
view hashes)
Built Distribution
riak-docs-0.1.3.win-amd64.exe
(234.2 kB
view hashes)