异步PeeWee

aiopeewee的Python项目详细描述


Build StatusGitential Active ContributorsGitential Coding HoursGitential Efficiency

空气压缩机

torpeewee之后建模的peewee的异步接口

实现的数据库适配器:

  • [X]aiomysql
  • []AIOPG
  • []sqlite

目前,peewee已经移植了125个测试用例,并不是全部,而是不断增加。

也支持简单的原子操作(事务),但现在已经过了很好的测试。

安装

pip install aiopeewee

使用量

fromaiopeeweeimportAioModel,AioMySQLDatabasefrompeeweeimportCharField,TextField,DateTimeFieldfrompeeweeimportForeignKeyField,PrimaryKeyFielddb=AioMySQLDatabase('test',host='127.0.0.1',port=3306,user='root',password='')classUser(AioModel):username=CharField()classMeta:database=dbclassBlog(AioModel):user=ForeignKeyField(User)title=CharField(max_length=25)content=TextField(default='')pub_date=DateTimeField(null=True)pk=PrimaryKeyField()classMeta:database=db# create connection poolawaitdb.connect(loop)# countawaitUser.select().count()# async iteration on select queryasyncforuserinUser.select():print(user)# fetch all records as a list from a query in one passusers=awaitUser.select()# insertuser=awaitUser.create(username='kszucs')# modifyuser.username='krisztian'awaituser.save()# async iteration on blog set[b.titleasyncforbinuser.blog_set.order_by(Blog.title)]# close connection poolawaitdb.close()# see more in the tests

许多

注意,必须使用aiomanytomanyfield而不是manytomy。

fromaiopeeweeimportAioManyToManyFieldclassUser(AioModel):username=CharField(unique=True)classMeta:database=dbclassNote(AioModel):text=TextField()users=AioManyToManyField(User)classMeta:database=dbNoteUserThrough=Note.users.get_through_model()asyncforuserinnote.users:# do something with the users

目前,我所知道的实例关系的immidiate设置的唯一限制必须替换为方法调用:

# original, which is not supportedcharlie.notes=[n2,n3]# use insteadawaitcharlie.notes.set([n2,n3])

序列化

转换为dict需要异步版本的model-to-dict

fromaiopeeweeimportmodel_to_dictserialized=awaitmodel_to_dict(user)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
jsf-java。安全NoSuchAlgorithmException:在jboss上部署时AES密钥生成器不可用   使用servlet与持久化java应用程序对话   java SPNEGO获取用户详细信息   如何向数组中的每个元素添加特定的数字?JAVA   佛教日历中的java JSpinner日期编辑器   tomcat6如何使用ip地址从另一台机器运行java动态web项目   向数据模型添加行时发生java ArrayIndexOutOfBoundsException   java奇怪的线程行为   java为什么程序没有显示任何输出?   具有弱值的java HashMap   java可以收集数据。不可修改地图是否保留原始地图?   java如何确定应用程序中的gccpu利用率?   带文本文件和比较索引的java摩尔斯电码   java第二个按钮没有响应   Maven LifecycleExecutionException java。util。ConcurrentModificationException帮助读取此堆栈跟踪/调试   java试图实现持有密钥绑定   运行时如何在Java程序中检索环境变量(外部修改)的修改值?   java可以在Gsheets数据验证下拉菜单中使用IF函数吗   java应该是抽象还是实现的一部分?