沙龙晃荡 | 去哪儿、陌陌、ThoughtWorks在主动化运维中的实践!10.28不见不散!
更新数据
数据集使得数据库中的数据攫取和写入数据就像浏览和编写JSON文件一样简单。
Dataset对于操作JSON、CSV文件、NoSQL异常好用。
- import dataset
- db = dataset.connect('mysql://username:password@10.10.10.10/ctf?charset=utf8')
用户名:username,暗码:password,数据库地址(地址+端口):10.10.10.10,database名: ctf
连接SQLite数据库:
- db = dataset.connect('sqlite:///ctf.db')
- db = dataset.connect('postgresql://scott:tiger@localhost:5432/mydatabase')
必定要留意指定字符编码
- table = db['city'] #(选择city表)
- user = table('name') # 找出表中'name'列属性所稀有据
- res = db.query('select name from table limit 10') # 如不雅不须要查看全部数据的话最好用limit,因为全部数据的载入异常异常耗时光
- for x in res:
- print x['name'] # 选name字段的数据
- table.insert(dict(name='John Doe', age=37))
- table.insert(dict(name='Jane Doe', age=34, gender='female'))
- john = table.find_one(name='John Doe')
插入数据
dataset会根据输入主动创建表和字段名
- table = db['user']
- # 或者table = db.get_table('user')
- table.insert(dict(name='John Doe', age=46, country='China'))
- table.insert(dict(name='Jane Doe', age=37, country='France', gender='female'))
- # 主键id主动生成
推荐阅读
沙龙晃荡 | 去哪儿、陌陌、ThoughtWorks在主动化运维中的实践!10.28不见不散! 而Sapienz对象的工作方法是如许的。上班族会在日间进行正常的工作义务,并且申报他们发明的任何软件马脚。在>>>详细阅读
地址:http://www.17bianji.com/lsqh/38023.html
1/2 1