conn.create_table(MyModel, read_units=10, write_units=10, wait_for_active=True)
+Important note: Unlike most databases, table creation may take up to 1 minute.
+during this time, the table is *not* usable. Also, you can not have more than 10
+tables in ``CREATING`` or ``DELETING`` state any given time for your whole Amazon
+account. This is an Amazon's DynamoDB limitation.
The connection manager automatically reads your credentials from either:
Before using this feature, make sure you *really need it*. In most cases another
-field can be used in place. A good hint is "witch field would I have marked
+field can be used in place. A good hint is "witch field would I have marked
- for users, ``email`` or ``login`` field shoud do it.
# Create a new ticket and auto-generate an ID
- ticket.title = "Chuck Norris is the reason why Waldo hides"
+ ticket.title = "Chuck Norris is the reason why Waldo hides"
ticket.tags = set([u'priority:critical', u'version:yesterday'])
ticket.description = u"Ludia needs to create a new social game to help people all around the world find him again. Where is Waldo?"
# Create a new ticket and force the ID
- ticket.ticket_number = "42"
- ticket.payload = "foo/bar"
+ ticket.ticket_number = u"42"
+ ticket.payload = u"foo/bar"
ticket.save() # create or replace item #42
print ticket.ticket_number # id has not changed
-.. TODO: lien vers save pour eviter d'ecraser
-.. Autre idee a la con: lever la limitation du sur range key, surtout pour stocker des revisions
+To prevent accidental data overwrite when saving to an arbitrary location, please
+see the detailed presentation of :ref:`saving`.
+.. Suggestion: remove the range_key limitation when using `autoincrement_int`. might be useful to store revisions for ex
Please note that ``hash_key=-1`` is currently reserved and nothing can be stored
+ # Get all orders for customer u"John Doe"
+ customer = Customer(u"John Doe")
+ order_generator = Order.get_batch(customer.order_ids)
But this approach has many drawbacks.
- An update to generate a new autoinc ID
- An insertion for the new order item
- An update to add the new order id to the customer
+ - Items are limited to 64KB but the ``order_ids`` set has no growth limit
- To get all orders from a giver customer, you need to read the customer first
and use a :py:meth:`~.DynamoDBModel.get_batch` request
+ u"orders": set,
- # Get all orders for customer "John Doe"
+ # Get all orders for customer "John Doe"
- # Get all orders for customer "John Doe" after agiven date
- Order.query(u"John Doe")
-.. TODO: lien vers query high level
-.. TODO link to query high level doc
+Not only is this approach u"better", it is also much more powerful. We could
+easily limit the result count, sort them in reverse order or filter them by
+creation date if needed. For more background on the querying system, please see
+the :ref:`accessing data <accessing-data>` section of this manual.
-When instanciating a model, all fields are initialised to "neutral" values. For
+When instanciating a model, all fields are initialised to "neutral" values. For
containers (``dict``, ``set``, ``list``, ...) it is the empty container, for
``unicode``, it's the empty string, for numbers, 0...
- from dynamodb_mapper.model import DynamoDBModel
+ from dynamodb_mapper.model import DynamoDBModel
from datetime import datetime
# define a model with defaults
- __table__ = "player_strength"
- __hash_key__ = "player_id"
+ __table__ = u"player_strength"
+ __hash_key__ = u"player_id"
- "lastUpdate": datetime,
+ u"last_update": datetime,
- "strength": u'weak', # scalar default value
- "lastUpdate": lambda: datetime.now(), # callable default value
+ u"strength": u'weak', # scalar default value
+ u"last_update": lambda: datetime.now(utc_tz), # callable default value
>>> player = PlayerStrength(strength=u"chuck norris") # overload one of the defaults