异步的sqlalchemy之上的小型和部分obejct映射器
asyncom的Python项目详细描述
异步
async om它是一个超级基本的对象映射器,几乎全部基于sqlalchemy ORM层。
我们使用声明性扩展来构建类,而且, 在查询上为它们的实例设置因子。(*支持有限)
仍然没有人支持这种关系。
依赖于encode/databases依赖关系。
动机
我不喜欢AsyncPgsa方法, 核心层,构建运行sqlgenerator。我喜欢建造, 在sqlachemy的声明层周围,后来发现 我可以将session.query上的一些方法修补到 使用它自己的sql生成器,并使查询系统异步。
对象持久性是最小的,需要一些爱。
用法
fromsqlalchemy.ext.declarativeimportdeclarative_baseimportsqlalchemyassafromdatabasesimportDatabaseURLBase=declarative_base()classOrmTest(Base):__tablename__='orm_test'id=sa.Column(sa.Integer,primary_key=True)name=sa.Column(sa.String(100),index=True)value=sa.Column(sa.Text)# Instead of usign Database from databases, you can use:db=OMDatabase(DatabaseURL('postgres://root@postgres:{port}/guillotina'))# instances of the object can be created with:test=OrmTest(name='xx',value='yy')awaitdb.add(test)print(test.id)# pk column is correct set# get an instanceins=awaitdb.query(OrmTest).get(1)total=awaitdb.query(OrmTest).count()asserttotal==1# remove itawaitdb.delete(ins)# filter themres=awaitdb.query(OrmTest).filter(OrmTest.name.like('xx')).all()# Or just iterate over the results with a cursor:asyncforrowindb.query(OrmTest).filter(OrmTest.name.like('xx')):print(f'Row {row.name}: {row.value}')# There is basic support for table inheritance query OneToOne# Look at tests
更改日志
0.3.1
- 能够为
OMQuery
提供映射程序工厂 [范希姆]
0.3.0
- 使用OM修复错误。删除继承的对象
0.2.3
- 在添加产品时修复布尔表达式。 允许使用0添加值
0.2.1
- 在json字段数组上选中none时的小修正
0.1.9
- 在更新和添加时添加了默认列和on update (仅适用于标量值和可调用项)
- 在omdatabaes上添加了小代理属性,用于原始asyncpg连接
0.1.8
- yaml数据导入程序
0.1.7
- 支持添加基本继承模型
0.1.6
- 查询应该是异步迭代器
0.1.5
- 加载继承的模型。
0.1.4
- query(object).get如果未找到,则应返回none
0.1.3
- 修复和改进。布置基本API
0.1.0(2019-04-07)
- pypi上的第一个版本。