Skip to content

Commit 95ccef1

Browse files
committed
add docs about directly awaiting queries
1 parent 8c22aae commit 95ccef1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/src/piccolo/getting_started/sync_and_async.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ ORMs which support asyncio.
99
However, you can use Piccolo in synchronous apps as well, whether that be a
1010
WSGI web app, or a data science script.
1111

12+
-------------------------------------------------------------------------------
13+
1214
Sync example
1315
------------
1416

@@ -24,6 +26,8 @@ Sync example
2426
if __name__ == '__main__':
2527
main()
2628
29+
-------------------------------------------------------------------------------
30+
2731
Async example
2832
-------------
2933

@@ -40,6 +44,22 @@ Async example
4044
if __name__ == '__main__':
4145
asyncio.run(main())
4246
47+
Direct await
48+
~~~~~~~~~~~~
49+
50+
You can directly await a query if you prefer. For example:
51+
52+
.. code-block:: python
53+
54+
>>> await Band.select()
55+
[{'id': 1, 'name': 'Pythonistas', 'manager': 1, 'popularity': 1000},
56+
{'id': 2, 'name': 'Rustaceans', 'manager': 2, 'popularity': 500}]
57+
58+
By convention, we await the ``run`` method (``await Band.select().run()``), but
59+
you can use this shorter form if you prefer.
60+
61+
-------------------------------------------------------------------------------
62+
4363
Which to use?
4464
-------------
4565

@@ -50,6 +70,8 @@ Using the async version is useful for web applications which require high
5070
throughput, based on `ASGI frameworks <https://piccolo-orm.com/blog/introduction-to-asgi>`_.
5171
Piccolo makes building an ASGI web app really simple - see :ref:`ASGICommand`.
5272

73+
-------------------------------------------------------------------------------
74+
5375
Explicit
5476
--------
5577

0 commit comments

Comments
 (0)