Skip to content

Commit

Permalink
Document streaming api
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor Sibanda committed Nov 18, 2020
1 parent 98b1c7e commit f147101
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,41 @@ Basic Usage
print(indexes)
Document Streaming
-----------
Fauna supports document streaming, where changes to a streamed document are pushed to all clients subscribing to that document.

The following section provides an example for managing a document stream.

The streaming API is blocking by default, the choice and mechanism for handling concurrent streams is left to the application developer:

.. code-block:: python
from faunadb import query as q
from faunadb.objects import Ref
from faunadb.client import FaunaClient
client = FaunaClient(secret="your-secret-here")
coll = client.query(q.create_collection({"name":"sc"}))
doc = client.query(q.create(coll["ref"], {"data":{"x": 0}}))
stream = None
def on_start(event):
print("started stream at %s"%(event.txn))
client.query(q.update(doc["ref"], {"data": {"x": "updated"}}))
def on_version(event):
print("on_version event at %s"%(event.txn))
print(" event: %s"%(event.event))
stream.close()
def on_error(event):
print("Received error event %s"%(event))
options = {"fields": ["document", "diff"]}
stream = client.stream(doc["ref"], options, on_start, on_version, on_error)
stream.start()
Building it yourself
--------------------

Expand Down

0 comments on commit f147101

Please sign in to comment.