Skip to content

Commit

Permalink
More complete example docs
Browse files Browse the repository at this point in the history
  • Loading branch information
grigi committed Oct 10, 2019
1 parent f428a68 commit a01a17d
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 105 deletions.
4 changes: 4 additions & 0 deletions docs/contrib/quart.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _contrib_quart:

==============================
Tortoise-ORM Quart integration
==============================
Expand All @@ -6,6 +8,8 @@ We have a lightweight integration util ``tortoise.contrib.quart`` which has a si

Note that the modules path can not be ``__main__`` as that changes depending on the launch point. One wants to be able to launch a Quart service from the ASGI runner directly, so all paths need to be explicit.

See the :ref:`example_quart`

Usage
=====

Expand Down
4 changes: 4 additions & 0 deletions docs/contrib/sanic.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
.. _contrib_sanic:

==============================
Tortoise-ORM Sanic integration
==============================

We have a lightweight integration util ``tortoise.contrib.sanic`` which has a single function ``register_tortoise`` which sets up Tortoise-ORM on startup and cleans up on teardown.

See the :ref:`example_sanic`

Reference
=========

Expand Down
4 changes: 4 additions & 0 deletions docs/contrib/starlette.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
.. _contrib_starlette:

==================================
Tortoise-ORM Starlette integration
==================================

We have a lightweight integration util ``tortoise.contrib.starlette`` which has a single function ``register_tortoise`` which sets up Tortoise-ORM on startup and cleans up on teardown.

See the :ref:`example_starlette`

Reference
=========

Expand Down
94 changes: 6 additions & 88 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,10 @@
Examples
========

.. toctree::
:maxdepth: 3

.. rst-class:: html-toggle

.. _example_basic:

Basic
=====
.. literalinclude:: ../examples/basic.py


.. rst-class:: html-toggle

.. _example_basic_comments:

Basic with comments
===================
.. literalinclude:: ../examples/basic_comments.py


.. rst-class:: html-toggle

.. _example_prefetching:

Prefetching
===========
.. literalinclude:: ../examples/complex_prefetching.py


.. rst-class:: html-toggle

.. _example_transactions:

Transactions
============
.. literalinclude:: ../examples/transactions.py


.. rst-class:: html-toggle

.. _example_aggregation:

Aggregation
===========
.. literalinclude:: ../examples/aggregation.py


.. rst-class:: html-toggle

.. _example_schema_create:

Schema creation
===============
.. literalinclude:: ../examples/schema_create.py


.. rst-class:: html-toggle

.. _example_two_databases:

Two Databases
=============
.. literalinclude:: ../examples/two_databases.py


.. rst-class:: html-toggle

.. _example_filtering:

Filtering
=========
.. literalinclude:: ../examples/complex_filtering.py


.. rst-class:: html-toggle

.. _example_relations:

Relations
=========
.. literalinclude:: ../examples/relations.py


.. rst-class:: html-toggle

.. _example_relations_recursive:

Schema creation
===============
.. literalinclude:: ../examples/relations_recursive.py
examples/basic
examples/quart
examples/sanic
examples/starlette
95 changes: 95 additions & 0 deletions docs/examples/basic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
.. _examples_simple:

===============
Simple Examples
===============

.. rst-class:: html-toggle

.. _example_basic:

Basic
=====
.. literalinclude:: ../../examples/basic.py


.. rst-class:: html-toggle

.. _example_basic_comments:

Comments
========
.. literalinclude:: ../../examples/basic_comments.py


.. rst-class:: html-toggle

.. _example_prefetching:

Prefetching
===========
.. literalinclude:: ../../examples/complex_prefetching.py


.. rst-class:: html-toggle

.. _example_transactions:

Transactions
============
.. literalinclude:: ../../examples/transactions.py


.. rst-class:: html-toggle

.. _example_aggregation:

Aggregation
===========
.. literalinclude:: ../../examples/aggregation.py


.. rst-class:: html-toggle

.. _example_schema_create:

Schema creation
===============
.. literalinclude:: ../../examples/schema_create.py


.. rst-class:: html-toggle

.. _example_two_databases:

Two Databases
=============
.. literalinclude:: ../../examples/two_databases.py


.. rst-class:: html-toggle

.. _example_filtering:

Filtering
=========
.. literalinclude:: ../../examples/complex_filtering.py


.. rst-class:: html-toggle

.. _example_relations:

Relations
=========
.. literalinclude:: ../../examples/relations.py


.. rst-class:: html-toggle

.. _example_relations_recursive:

Recursive Relations
===================
.. literalinclude:: ../../examples/relations_recursive.py

35 changes: 35 additions & 0 deletions docs/examples/quart.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _example_quart:

=============
Quart Example
=============

This is an example of the :ref:`contrib_quart`

**Usage:**

.. code-block:: sh
QUART_APP=main quart
...
Commands:
generate-schemas Populate DB with Tortoise-ORM schemas.
run Start and run a development server.
shell Open a shell within the app context.
# To generate schemas
QUART_APP=main quart generate-schemas
# To run
QUART_APP=main quart run
models.py
=========
.. literalinclude:: ../../examples/quart/models.py

main.py
=======
.. literalinclude:: ../../examples/quart/main.py


24 changes: 24 additions & 0 deletions docs/examples/sanic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _example_sanic:

=============
Sanic Example
=============

This is an example of the :ref:`contrib_sanic`

**Usage:**

.. code-block:: sh
python3 main.py
models.py
=========
.. literalinclude:: ../../examples/sanic/models.py

main.py
=======
.. literalinclude:: ../../examples/sanic/main.py


24 changes: 24 additions & 0 deletions docs/examples/starlette.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _example_starlette:

=================
Starlette Example
=================

This is an example of the :ref:`contrib_starlette`

**Usage:**

.. code-block:: sh
python3 main.py
models.py
=========
.. literalinclude:: ../../examples/starlette/models.py

main.py
=======
.. literalinclude:: ../../examples/starlette/main.py


8 changes: 4 additions & 4 deletions tests/requirements-pypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
aiomysql==0.0.20
aiosqlite==0.10.0
apipkg==1.5 # via execnet
asn1crypto==1.0.0 # via cryptography
asn1crypto==1.0.1 # via cryptography
asynctest==0.13.0
atomicwrites==1.3.0 # via pytest
attrs==19.1.0 # via pytest
attrs==19.2.0 # via pytest
certifi==2019.9.11 # via requests
cffi==1.12.3 # via cryptography
chardet==3.0.4 # via requests
Expand All @@ -30,10 +30,10 @@ pycparser==2.19 # via cffi
pymysql==0.9.2 # via aiomysql
pyparsing==2.4.2 # via packaging
pypika==0.35.8
pytest-cov==2.8.0
pytest-cov==2.8.1
pytest-forked==1.0.2 # via pytest-xdist
pytest-xdist==1.30.0
pytest==5.2.0
pytest==5.2.1
pyyaml==5.1.2
requests==2.22.0 # via coveralls
six==1.12.0 # via cryptography, packaging, pytest-xdist
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ sanic

# Sample integration - Starlette
starlette
uvicorn < 0.9
Loading

0 comments on commit a01a17d

Please sign in to comment.