Skip to content

Commit

Permalink
Some Documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
grigi committed Feb 18, 2019
1 parent 1c82b3f commit 93248e3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 8 deletions.
74 changes: 68 additions & 6 deletions docs/databases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,84 @@ The supported ``DB_TYPE``:
``mysql``:
Typically in the form of :samp:`mysql://myuser:mypass:pass@db.host:3306/somedb`

Capabilities
============

Since each database has a different set of features we have a ``Capabilities`` that is registered on each client.
Primarily this is to work around larger-than SQL differences, or common issues.

.. autoclass:: tortoise.backends.base.client.Capabilities
:members:


SQLite
======

.. todo::
Document SQLite options and behaviour
SQLite is an embedded database, and can run on a file or in-memory. Good database for local development or testing of code logic, but not recommended for production use.

DB URL is typically in the form of :samp:`sqlite://{DB_FILE}`
So if the ``DB_FILE`` is "/data/db.sqlite3" then the string will be ``sqlite:///data/db.sqlite`` (note the three /'s)

Parameters
----------

``path``:
Path to SQLite3 file. ``:memory:`` is a special path that indicates in-memory database.


PostgreSQL
==========

.. todo::
Document PostgreSQL options and behaviour
DB URL is typically in the form of :samp:`postgres://postgres:pass@db.host:5432/somedb`

Parameters
----------

``user``:
Username to connect with.
``password``:
Password for username.
``host``:
Network host that database is available at.
``port``:
Network port that database is available at. (defaults to ``5432``)
``database``:
Database to use.
``min_size``:
Minimum connection pool size (not used right now)
``max_size``:
Maximum connection pool size (not used right now)
``max_queries``:
Maximum no of queries to allow before forcing a re-connect.
``max_inactive_connection_lifetime``:
Duration of inactive connection before assuming that it has gone stale, and force a re-connect.


MySQL/MariaDB
=============

.. todo::
Document MySQL/MariaDB options and behaviour
DB URL is typically in the form of :samp:`mysql://myuser:mypass:pass@db.host:3306/somedb`

Parameters
----------

``user``:
Username to connect with.
``password``:
Password for username.
``host``:
Network host that database is available at.
``port``:
Network port that database is available at. (defaults to ``3306``)
``database``:
Database to use.
``minsize``:
Minimum connection pool size (not used right now)
``maxsize``:
Maximum connection pool size (not used right now)
``connect_timeout``:
Duration to wait for connection before throwing error.
``echo``:
Echo SQL queries (debug only)
``no_delay``:
Sets TCP NO_DELAY to disable Nagle.
8 changes: 7 additions & 1 deletion docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ If you don't define a primary key, we will create a primary key of type ``IntFie

Sadly, currently only simple integer primary key is supported, there is plans to enhance this in the not too distant future.

Further we have field ``fields.DatetimeField(auto_now=True)``. Options ``auto_now`` and ``auto_now_add`` work like Django's options.

``ForeignKeyField``
-------------------

.. code-block:: python3
tournament = fields.ForeignKeyField('models.Tournament', related_name='events')
Expand All @@ -102,10 +107,11 @@ or like this:
await tournament.fetch_related('events')
``ManyToManyField``
-------------------

Next field is ``fields.ManyToManyField('models.Team', related_name='events')``. It describes many to many relation to model Team.

Further we have field ``fields.DatetimeField(auto_now=True)``. Options ``auto_now`` and ``auto_now_add`` work like Django's options.


Reference
Expand Down
9 changes: 9 additions & 0 deletions tortoise/backends/base/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class Capabilities:
* Defeciences: assume it is working right.
* Features: assume it doesn't have it.
Fields:
``dialect``:
Dialect name of the DB Client driver.
``safe_indexes``:
Indicates that this DB supports optional index creation using ``IF NOT EXISTS``.
``requires_limit``:
Indicates that this DB requires a ``LIMIT`` statement for an ``OFFSET`` statement to work.
'''

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion tortoise/contrib/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ async def test_run_sqlite_only(self):
...
:param connection_name: name of the connection to retrieve capabilities from.
:param **conditions: capability tests which must all pass for the test to run.
:param conditions: capability tests which must all pass for the test to run.
"""
def decorator(test_item):
@wraps(test_item)
Expand Down

0 comments on commit 93248e3

Please sign in to comment.