Skip to content

Latest commit

 

History

History
74 lines (51 loc) · 1.85 KB

README.md

File metadata and controls

74 lines (51 loc) · 1.85 KB

peewee-async

Asynchronous interface for peewee ORM powered by asyncio.

Build Status PyPi Version Documentation Status

Documentation

http://peewee-async.readthedocs.org

Install

Works on Python 3.3+ and PostgreSQL database.

Install with pip:

pip install peewee-async

Quickstart

Create test PostgreSQL database, i.e. 'test' for running this snippet:

import asyncio
import peewee
import peewee_async

database = peewee_async.PostgresqlDatabase('test')
loop = asyncio.get_event_loop()

class TestModel(peewee.Model):
    text = peewee.CharField()

    class Meta:
        database = database

# Create table synchronously!
TestModel.create_table(True)
# This is optional: close sync connection
database.close()

@asyncio.coroutine
def my_handler():
    TestModel.create(text="Yo, I can do it sync!")
    yield from peewee_async.create_object(TestModel, text="Not bad. Watch this, I'm async!")
    all_objects = yield from peewee_async.execute(TestModel.select())
    for obj in all_objects:
        print(obj.text)

loop.run_until_complete(database.connect_async(loop=loop))
loop.run_until_complete(my_handler())

Discuss

You are welcome to add discussion topics or bug reports to tracker on GitHub: https://github.com/05bit/peewee-async/issues

License

Copyright (c) 2014, Alexey Kinev rudy@05bit.com

Licensed under The MIT License (MIT), see LICENSE file for more details.