diff --git a/cqlengine/__init__.py b/cqlengine/__init__.py index d5e7b74f..184a4c8a 100644 --- a/cqlengine/__init__.py +++ b/cqlengine/__init__.py @@ -1,6 +1,7 @@ from cqlengine.columns import * from cqlengine.functions import * from cqlengine.models import Model +from cqlengine.query import BatchQuery __version__ = '0.1.2' diff --git a/docs/topics/queryset.rst b/docs/topics/queryset.rst index ce3a2c81..6733080c 100644 --- a/docs/topics/queryset.rst +++ b/docs/topics/queryset.rst @@ -213,6 +213,34 @@ Ordering QuerySets *For instance, given our Automobile model, year is the only column we can order on.* +Batch Queries +=============== + + cqlengine now supports batch queries using the BatchQuery class. Batch queries can be started and stopped manually, or within a context manager. To add queries to the batch object, you just need to precede the create/save/delete call with a call to batch, and pass in the batch object. + + You can only create, update, and delete rows with a batch query, attempting to read rows out of the database with a batch query will fail. + + .. code-block:: python + + from cqlengine import BatchQuery + + #using a context manager + with BatchQuery() as b: + now = datetime.now() + em1 = ExampleModel.batch(b).create(example_type=0, description="1", created_at=now) + em2 = ExampleModel.batch(b).create(example_type=0, description="2", created_at=now) + em3 = ExampleModel.batch(b).create(example_type=0, description="3", created_at=now) + + # -- or -- + + #manually + b = BatchQuery() + now = datetime.now() + em1 = ExampleModel.batch(b).create(example_type=0, description="1", created_at=now) + em2 = ExampleModel.batch(b).create(example_type=0, description="2", created_at=now) + em3 = ExampleModel.batch(b).create(example_type=0, description="3", created_at=now) + b.execute() + QuerySet method reference =========================