Skip to content

Commit

Permalink
Add a very basic example to the README (and use doctests to verify it)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenisanerd committed Dec 7, 2011
1 parent 7705941 commit 2189b92
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
56 changes: 55 additions & 1 deletion README.md
@@ -1,6 +1,60 @@
# Object Mapper for Riak #

## Configuring Riak for RiakAlchemy ##
## What is RiakAlchemy ##

RiakAlchemy is an object mapper for Riak written in Python. It's
supposed to make it easy to create data types that you can move between
Riak and Python. It's rather crude so far, but that'll probably change
as my needs (or yours!) arise. Notably, it has no conflict
resolution/sibling reconciliation logic.

## Quick Start Guide ##

To get Riak set up, see the <a href="#configuring-riak">Configuring
Riak for RiakAlchemy</a> section further down.

Let's create a data type:

>>> import riakalchemy
>>> from riakalchemy.types import String, Integer

>>> class Person(riakalchemy.RiakObject):
... # bucket_name is the name of the Riak bucket that will hold these objects
... bucket_name = 'people'
...
... # A couple of attributes
... name = String()
... age = Integer()
...
... # And a handy __repr__ method (entirely optional!)
... def __repr__(self):
... return '<Person name=%r age=%r>' % (self.name, self.age)

Pretty straight forward.

Before we can start using this, we need to connect to Riak.

>>> riakalchemy.connect()

Let's create a Person object:

>>> person = Person()
>>> person.name = 'Soren Hansen'
>>> person.age = '30'
>>> person.save()
>>> person
<Person name='Soren Hansen' age=30>

As we didn't provide a key, Riak assigned one automatically:

>>> person.key # doctest: +SKIP
'NUD2opa92uFD9JaFefXktCxzEUW'

We can delete the object again like so:

>>> person.delete()

## <a name="configuring-riak">Configuring Riak for RiakAlchemy</a> ##

You need to do tweak Riak a little bit for RiakAlchemy to work.
Namely, you need to enable Riak Search, use the eleveldb storage
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
@@ -0,0 +1,3 @@
[nosetests]
with-doctest=1
doctest-extension=md

0 comments on commit 2189b92

Please sign in to comment.