python - sqlalchemy使用上的小tips
迷茫
迷茫 2017-04-18 10:17:26
0
0
467

1.sqlalchemy object序列化为json

posts = Post.query.all()
serializer = Serializer(posts,many=True)
data = serializer.data

2.像django orm一样使用sqlalchemy

posts = Post.query.filter_by(id__in=['1','2','3'],tags__name='sqlalchemy').order_by('-id').all()

3.去掉一些sqlalchemy的重复工作

# 关联用户表
class Post(ModelUserMixin, Model):
    
    user_related_name = 'posts'
    titile = ...

地址:https://github.com/honmaple/maple-json

代码很简单,没写注释应该也能看懂,感觉不错,所以分享出来一下

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template