SQLalchemy 使用记录
2024-09-08 07:54:53
1.models.py中添加该方法,可通过该方法转dict
#驼峰
def to_hump_dict(self):
return {commonUtils.str2Hump(c.name): getattr(self, c.name, None) for c in self.__table__.columns}
def to_dict(self):
return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}
Base.to_hump_dict = to_hump_dict
Base.to_dict = to_dict
class User(Base):
__tablename__ = 'key_user' id = Column(INTEGER(11), primary_key=True, nullable=False, index=True)
uid = Column(String(32), primary_key=True, nullable=False)
username = Column(String(255), primary_key=True, nullable=False, index=True)
remarks = Column(String(255))
creater = Column(String(255))
create_time = Column(TIMESTAMP)
2.查询(入参没有的情况)、分页、排序
if username:
q = self.dbsession.query(KeyUser).filter(User.username == username)
if passwd:
q = q.filter(User.passwd== passwd)
q.limit(pageSize).offset(int(page-1)*pageSize).order_by(User.id.desc()).all() 3.使用timestamp类型时,对应的python获取
func.current_timestamp()
最新文章
- 使用 RequireJS 优化 Web 应用前端
- 增强拉格朗日乘子法(Augmented Lagrange Method)
- linux下的vim使用教程
- win系统下nodejs安装及环境配置
- Hashtable、Dictionary和List 谁效率更高
- 【poj2891-Strange Way to Express Integers】拓展欧几里得-同余方程组
- 【python】 入门 搭建环境
- object-c 入门基础篇
- mysql数据库操作语句大全
- Codeforces 463D Gargari and Permutations
- Oracle事物基础
- FlexiGrid使用手册
- memcached常用命令
- Tensorflow小技巧整理:修改张量特定元素的值
- Sublime text3所遇到的问题
- MySQL物理备份 lvm-snapshot
- Java学习——方法
- vue组件推荐
- linux E325: 注意 发现交换文件 ";*.swp"; 解决方法
- linux测试环境搭建步骤