Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/python-tools/aioorm
a fork of aiopeewee-0.3.5,support postgresql
https://github.com/python-tools/aioorm
asyncio mysql orm postgresql python-3-5
Last synced: about 1 month ago
JSON representation
a fork of aiopeewee-0.3.5,support postgresql
- Host: GitHub
- URL: https://github.com/python-tools/aioorm
- Owner: Python-Tools
- License: mpl-2.0
- Archived: true
- Created: 2017-06-21T11:00:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-17T16:06:45.000Z (about 6 years ago)
- Last Synced: 2024-09-28T16:43:42.750Z (about 1 month ago)
- Topics: asyncio, mysql, orm, postgresql, python-3-5
- Language: Python
- Homepage: https://python-tools.github.io/aioorm/
- Size: 1.78 MB
- Stars: 12
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aioorm
+ version: 0.1.6
+ status: production
+ author: hsz
+ email: [email protected]## Description
Asyncio interface for peewee modeled after torpeewee
keywords:python3.5+,asyncio,orm,mysql,postgresql
## Feature
+ support mysql and postgresql
+ database factory using database URL
+ use peewee's fields
+ ManyToManyField support
+ Shortcuts support
+ csv dump /load support
+ can use playhose.postgres_ext.JSONField## Install
`python -m pip install aioorm`
## Examples
There are some Examples to show the use case
### Example: GRUD
```python
from aioorm import AioModel, AioMySQLDatabase
from peewee import CharField, TextField, DateTimeField
from peewee import ForeignKeyField, PrimaryKeyFielddb = AioMySQLDatabase('test', host='127.0.0.1', port=3306,
user='root', password='')class User(AioModel):
username = CharField()class Meta:
database = dbclass Blog(AioModel):
user = ForeignKeyField(User)
title = CharField(max_length=25)
content = TextField(default='')
pub_date = DateTimeField(null=True)
pk = PrimaryKeyField()class Meta:
database = db# create connection pool
await db.connect(loop)# count
await User.select().count()# async iteration on select query
async for user in User.select():
print(user)# fetch all records as a list from a query in one pass
users = await User.select()# insert
user = await User.create(username='kszucs')# modify
user.username = 'krisztian'
await user.save()# async iteration on blog set
[b.title async for b in user.blog_set.order_by(Blog.title)]# close connection pool
await db.close()# see more in the tests
```### Example: Many to many
Note that `AioManyToManyField` must be used instead of `ManyToMany`.
```python
from aioorm import AioManyToManyField
class User(AioModel):
username = CharField(unique=True)class Meta:
database = dbclass Note(AioModel):
text = TextField()
users = AioManyToManyField(User)class Meta:
database = dbNoteUserThrough = Note.users.get_through_model()
async for user in note.users:
# do something with the users
```Currently the only limitation I'm aware of immidiate setting of instance relation must be replaced with a method call:
```python
# original, which is not supported
charlie.notes = [n2, n3]# use instead
await charlie.notes.set([n2, n3])
```### Serializing
Converting to dict requires the asyncified version of `model_to_dict`
```python
from aioorm import model_to_dictserialized = await model_to_dict(user)
```### Dump to csv
tables can be dump to a csv file.
```python
from aioorm.utils import aiodump_csv
query = User.select().order_by(User_csv.id)
await aiodump_csv(query,str(filepath))
```Documentation
--------------------------------`Documentation on Readthedocs `_.
## TODO
+ async dataset support
+ more test## Limitations
+ untested transactions
+ only support mysql and postgresql## Bug fix
+ fixed `get` and `get_or_create` 's bug