Skip to content

Commit

Permalink
Import docs patterns #13
Browse files Browse the repository at this point in the history
  • Loading branch information
numberoverzero committed Jun 26, 2016
1 parent fc9013c commit d25ba98
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion docs/user/patterns.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
Common Patterns
===============

TODO
DynamoDB Local
--------------

Connect to a local DynamoDB instance.

::

import boto3
import bloop

boto_client = boto3.client(
"dynamodb",
endpoint="http://127.0.0.1:8000",
region_name="us-west-2")
client = bloop.Client(boto_client=boto_client)
engine = bloop.Engine(client=client)

.. note::

DynamoDB Local has an issue with expressions and Global Secondary Indexes, and will throw errors about
ExpressionAttributeName when you query or scan against a GSI. For example, see
`this issue <https://github.com/numberoverzero/bloop/issues/43>`_.

Generic "if not exist"
----------------------

Condition to ensure an object's hash (or hash + range) key are not set (item doesn't exist).

::

def if_not_exist(obj):
hash_key = obj.Meta.hash_key
range_key = obj.Meta.range_key

condition = hash_key.is_(None)
if range_key:
condition &= range_key.is_(None)
return condition


# Usage
tweet = Tweet(account=uuid.uuid4(), id="numberoverzero", ...)
engine.save(tweet, condition=if_not_exist(tweet))

0 comments on commit d25ba98

Please sign in to comment.