- table.update(dict(name='John Doe', age=47), ['name'])
- # 第二个参数相当于sql update语句中的where,用来过滤出须要更新的记录
事务操作
事务操作可以简单的应用高低文治理器来实现,出现异常,将会回滚
- with dataset.connect() as tx:
- tx['user'].insert(dict(name='John Doe', age=46, country='China'))
- # 相当于:
- db = dataset.connect()
- db.begin()
- try:
- db['user'].insert(dict(name='John Doe', age=46, country='China'))
- db.commit()
- except:
- db.rollback()
- # 也可以嵌套应用:
- db = dataset.connect()
- with db as tx1:
- tx1['user'].insert(dict(name='John Doe', age=46, country='China'))
- with db as tx2:
- tx2['user'].insert(dict(name='Jane Doe', age=37, country='France', gender='female'))
大年夜表获取数据
- users = db['user'].all()
- for user in db['user']:
- # print(user['age'])
- # chinese_users = user.find(country='China')
- john = user.find_one(
推荐阅读
沙龙晃荡 | 去哪儿、陌陌、ThoughtWorks在主动化运维中的实践!10.28不见不散! 而Sapienz对象的工作方法是如许的。上班族会在日间进行正常的工作义务,并且申报他们发明的任何软件马脚。在>>>详细阅读
地址:http://www.17bianji.com/lsqh/38023.html
1/2 1