原文连接:http://blog.csdn.net/tomorrow13210073213/article/category/6931287
实际使用
前文中我们定义了数据库操作额度基础类,目的是为了尽量简化数据库操作,减少重复代码;下面我们来看一下具体怎么使用;
Talk is cheap. Show me the code
新增
# 执行工具
__m_exe = MapperExecute()
# 表配置
__user_cfg = UserCfg()
# 待插入数据
user_info = {}
# 执行插入
__m_exe.insert_selective(__user_cfg, user_info)
更新
# 执行工具
__m_exe = MapperExecute()
# 表配置
__user_cfg = UserCfg()
# 待更新数据
user_info = {"ID":1}
# 执行更新
__m_exe.update_by_pk_selective(__user_cfg, user_info)
删除
# 执行工具
__m_exe = MapperExecute()
# 表配置
__user_cfg = UserCfg()
# 主键
uid = 1
# 执行删除
__m_exe.delete_by_condition(__user_cfg, Qwhere("ID", "=", uid))
查询
# 执行工具
__m_exe = MapperExecute()
# 表配置
__user_cfg = UserCfg()
# 主键
uid = 1
# 执行查询
__m_exe.select_by_condition(__user_cfg, (Qwhere("ID", "=", uid), "and", Qwhere("ZT", "=", "1"), Qpage(1, 1)))
统计
# 执行工具
__m_exe = MapperExecute()
# 表配置
__user_cfg = UserCfg()
# 执行统计
__m_exe.count_by_condition(__user_cfg , (Qwhere("ZT", "=", "1")))
以上是基本的增删改查,工具只能执行简单的增删改查,复杂操作并不能实现;但能满足我们的需求就足够了;
以上内容仅供练习,学习使用;