Skip to content

Commit 02320a9

Browse files
committed
Add some docs for default and per-query TTL
1 parent 351d332 commit 02320a9

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

docs/api/cassandra/cqlengine/models.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ Model
3232

3333
.. autoattribute:: __keyspace__
3434

35-
.. _ttl-change:
36-
.. autoattribute:: __default_ttl__
35+
.. attribute:: __default_ttl__
36+
:annotation: = None
37+
38+
Will be deprecated in release 4.0. You can set the default ttl by configuring the table ``__options__``. See :ref:`ttl-change` for more details.
3739

3840
.. autoattribute:: __discriminator_value__
3941

docs/cqlengine/queryset.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,42 @@ None means no timeout.
343343
Setting the timeout on the model is meaningless and will raise an AssertionError.
344344

345345

346+
.. _ttl-change:
347+
348+
Default TTL and Per Query TTL
349+
=============================
350+
351+
Model default TTL now relies on the *default_time_to_live* feature, introduced in Cassandra 2.0. It is not handled anymore in the CQLEngine Model (cassandra-driver >=3.6). You can set the default TTL of a table like this:
352+
353+
Example:
354+
355+
.. code-block:: python
356+
357+
class User(Model):
358+
__options__ = {'default_time_to_live': 20}
359+
360+
user_id = columns.UUID(primary_key=True)
361+
...
362+
363+
You can set TTL per-query if needed. Here are a some examples:
364+
365+
Example:
366+
367+
.. code-block:: python
368+
369+
class User(Model):
370+
__options__ = {'default_time_to_live': 20}
371+
372+
user_id = columns.UUID(primary_key=True)
373+
...
374+
375+
user = User.objects.create(user_id=1) # Default TTL 20 will be set automatically on the server
376+
377+
user.ttl(30).update(age=21) # Update the TTL to 30
378+
User.objects.ttl(10).create(user_id=1) # TTL 10
379+
User(user_id=1, age=21).ttl(10).save() # TTL 10
380+
381+
346382
Named Tables
347383
===================
348384

0 commit comments

Comments
 (0)