Skip to main content

async orm for async web framework

Project description


Async orm for async web framework, you should use Django to manage your database(ddl etc).

pip install -U async-orm


from django.db import models
from async_orm import BaseModel, transation, Q

class FooBar(BaseModel):
    """ foo bar """

    game = models.CharField(verbose_name='game', max_length=30, blank=False, null=False, db_index=True)
    title = models.CharField(verbose_name='title', max_length=100, blank=False, null=False)
    weight = models.IntegerField(verbose_name='weight', blank=False, null=False, default=0)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        app_label = 'test'
        verbose_name = "foo_bar"
        verbose_name_plural = "foo_bar"
        ordering = ['key', '-title']

async def test_foo_bar():
    game = 'game1'
    title = 'title2'
    # select
    await, title=title) | Q(game='game2'), limit=2, offset=5)
    await['id', 'title'], order_by=['-title'])
    await, limit=1)
    await['game'], distinct=True, where=Q(id__gte=2))

    ret = await'game2'), limit=1)
    if not ret:
        # insert
        ret = FooBar(game='game2', title='title22', weight=0)
        num = await
        # result = FooBar.create(game='game2', title='title22', weight=0)
        # update
        ret.title = 'new title' + str(
        num = await

        # delete
        # num = await ret.delete()
        # print(num)

    # transaction
    if ret is not None:
        async with transaction() as ts:
            await FooBar.create(game='game2', title='ttitle1', weight=0, ts=ts)
            await FooBar.create(game='game2', title='ttitle2', weight=0, ts=ts)
            await FooBar.create(game='game2', title='ttitle3', weight=0, ts=ts)
            await ts.conn.rollback()
            await FooBar.create(game='game2', title='ttitle4', weight=0, ts=ts)
            await ts.conn.commit()

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for async-orm, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size async_orm-1.0.0-py3-none-any.whl (5.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size async-orm-1.0.0.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page