sqlalchemy_traversal
====================
This is a pyramid extension that allows you to use traversal with SQLAlchemy objects
Demo App here: https://github.com/eventray/sqlalchemy_traversal_demo
To use this you just have to include sqlalchemy_traversal in your pyramid application
by either putting it in your development.ini:
pyramid.includes =
sqlalchemy_traversal
or by including it in your main:
config.include('sqlalchemy_traversal')
Then you just register your SQLAlchemy session and declarative base:
from sqlalchemy_traversal.interfaces import ISASession
from sqlalchemy_traversal.interfaces import ISABase
config.registry.registerUtility(DBSession, ISASession)
config.registry.registerUtility(Base, ISABase)
And then place the TraversalMixin on any SQLAlchemy class and it will automatically
be traversed:
from sqlalchemy_traversal import TraversalMixin
class User(TraversalMixin, Base):
pass
Now you will be able to hit the URL /traverse/user to get all the users in your database
You can also tell it to load relationships via the _json_eager_load property:
class User(TraversalMixin, Base):
_json_eager_load = ['permissions']
Saving
==================================
If you want to be able to create data with your API but the content
coming back doesn't exactly match your model or you want to run it through
schema validation first you can use the register save decorator:
@register_save(MyModel, MySchema):
def saving_my_model(request, data):
data['my_prop'] = 'NEW DATA'
return data
You can also handle data exceptions with exception_handlers:
def handle_integrity_error(model, exception):
return {
'errors': {
'message': 'That data is not unique'
}
}
@register_save(
MyModel
, MySchema
, exception_handlers={
IntegrityError: handle_integrity_error
}
):
def saving_my_model(request, data):
data['my_prop'] = 'NEW DATA'
return data
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
最新资源
- C#物联订单仓储综合管理系统源码 物联综合管理系统源码数据库 SQL2008源码类型 WebForm
- 2024年最新敏感词库(7万余条)
- java带财务进销存ERP管理系统源码数据库 MySQL源码类型 WebForm
- java制造业MES生产管理系统源码 MES源码数据库 MySQL源码类型 WebForm
- 基于无人机航拍数据实现的三维场景重建python源代码+文档说明+数据集(高分项目)
- 【重磅,更新!】全国2000-2022年植被指数数据(分辨率30m)
- 包含Qt5Core.dll Qt5Gui.dll Qt5Network.dll Qt5Svg.dll Qt5Widgets.dl
- python3.6 get-pip.py
- python期末大作业基于ResNet的人脸表情识别项目源码+数据集+模型文件(高分项目)
- C#大型多门店4S连锁汽车维修保养管理系统源码(带文档)数据库 SQL2008源码类型 WebForm
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈