async orm for async web framework
Project description
async-orm
Async orm for async web framework, you should use Django to manage your database(ddl etc).
pip install -U async-orm
Usage
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 FooBar.select(where=Q(game=game, title=title) | Q(game='game2'), limit=2, offset=5)
await FooBar.select(fields=['id', 'title'], order_by=['-title'])
await FooBar.select(where=Q(weight__gt=0), limit=1)
await FooBar.select(count=['game'], distinct=True, where=Q(id__gte=2))
ret = await FooBar.select(where=Q(game='game2'), limit=1)
if not ret:
# insert
ret = FooBar(game='game2', title='title22', weight=0)
num = await ret.save()
print(ret.id)
print(num)
# result = FooBar.create(game='game2', title='title22', weight=0)
else:
# update
ret.title = 'new title' + str(datetime.datetime.now())
num = await ret.save()
print(ret.id)
print(num)
# 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
async-orm-1.0.0.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file async-orm-1.0.0.tar.gz
.
File metadata
- Download URL: async-orm-1.0.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc142155931d937f1d4e708619ecc3535fc3b81325b1435a4ae3d3b7fcd84763 |
|
MD5 | ff0954aad4234cca8e0a1e79a360d071 |
|
BLAKE2b-256 | c7bb551b59d866563736aa94bc94fe507818cd71aad72ac3f606650bebb6f6b4 |
File details
Details for the file async_orm-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: async_orm-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcd2fee4e1e26963979f7ad6e779d5546efe6c38371de1e4a72cd821dbb534e4 |
|
MD5 | 5b1e8e556fd49bc5ddb66341874ab166 |
|
BLAKE2b-256 | 409a34d2be0b7c6518e495a36d6bd0df8d873fef3748fee41df4dce06305f65d |