Skip to content

Commit

Permalink
fix: docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
kalombos authored Sep 14, 2024
1 parent 5de420b commit 3f7b9df
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 139 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Overview
* Asynchronous analogues of peewee sync methods with prefix aio_
* Drop-in replacement for sync code, sync will remain sync
* Basic operations are supported
* Transactions support is present, yet not heavily tested
* Transactions support is present

The complete documentation:
http://peewee-async-lib.readthedocs.io
Expand Down
59 changes: 5 additions & 54 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ peewee-async
.. _peewee: https://github.com/coleifer/peewee
.. _asyncio: https://docs.python.org/3/library/asyncio.html

Current state: **beta**, API is fine and mostly stable.

* Works on Python 3.8+
* Has support for PostgreSQL via `aiopg`
* Has support for MySQL via `aiomysql`
* Single point for high-level async API
* Asynchronous analogues of peewee sync methods with prefix aio_
* Drop-in replacement for sync code, sync will remain sync
* Basic operations are supported
* Transactions support is present, yet not heavily tested
* Transactions support is present

The source code is hosted on `GitHub`_.

Expand All @@ -28,53 +27,7 @@ The source code is hosted on `GitHub`_.
Quickstart
----------

.. code-block:: python
import asyncio
import peewee
import peewee_async
# Nothing special, just define model and database:
database = peewee_async.PostgresqlDatabase('test')
class TestModel(peewee.Model):
text = peewee.CharField()
class Meta:
database = database
# Look, sync code is working!
TestModel.create_table(True)
TestModel.create(text="Yo, I can do it sync!")
database.close()
# Create async models manager:
objects = peewee_async.Manager(database)
# No need for sync anymore!
database.set_allow_sync(False)
async def handler():
await objects.create(TestModel, text="Not bad. Watch this, I'm async!")
all_objects = await objects.execute(TestModel.select())
for obj in all_objects:
print(obj.text)
loop = asyncio.get_event_loop()
loop.run_until_complete(handler())
loop.close()
# Clean up, can do it sync again:
with objects.allow_sync():
TestModel.drop_table(True)
# Expected output:
# Yo, I can do it sync!
# Not bad. Watch this, I'm async!
.. literalinclude:: ./samples/quickstart.py


Install
Expand Down Expand Up @@ -109,14 +62,13 @@ Running tests
Prepare environment for tests:

* Clone source code from GitHub as shown above
* Create PostgreSQL database for testing, i.e. named 'test'
* Create ``tests.json`` config file based on ``tests.json.sample``
* Run docker environment with PostgreSQL database for testing

Then run tests:

.. code-block:: console
python setup.py test
pytest -s -v
Report bugs and discuss
-----------------------
Expand All @@ -132,7 +84,6 @@ Contents
:maxdepth: 2

peewee_async/api
peewee_async/api_older
peewee_async/examples

Indices and tables
Expand Down
2 changes: 1 addition & 1 deletion docs/peewee_async/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Databases
.. autoclass:: peewee_async.PooledPostgresqlDatabase
:members: init

.. autoclass:: peewee_asyncext.PooledPostgresqlExtDatabase
.. autoclass:: peewee_async.PooledPostgresqlExtDatabase
:members: init

.. autoclass:: peewee_async.PooledMySQLDatabase
Expand Down
83 changes: 0 additions & 83 deletions docs/peewee_async/api_older.rst

This file was deleted.

41 changes: 41 additions & 0 deletions docs/samples/quickstart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import asyncio
import peewee
import peewee_async

# Nothing special, just define model and database:

database = peewee_async.PooledPostgresqlExtDatabase('test')


class TestModel(peewee_async.AioModel):
text = peewee.CharField()

class Meta:
database = database


# Look, sync code is working!

TestModel.create_table(True)
TestModel.create(text="Yo, I can do it sync!")
database.close()

# No need for sync anymore!

database.set_allow_sync(False)


async def handler():
await TestModel.aio_create(text="Not bad. Watch this, I'm async!")
all_objects = await TestModel.select().aio_execute()
for obj in all_objects:
print(obj.text)


loop = asyncio.get_event_loop()
loop.run_until_complete(handler())
loop.close()

# Clean up, can do it sync again:
with database.allow_sync():
TestModel.drop_table(True)

0 comments on commit 3f7b9df

Please sign in to comment.