db = dataset.connect(url='mysql://user:password@host:port/db?charset=utf8')

# 查询一行,支持多个关键字搜索,中间以逗号隔开
res = db["instance"].find_one(Id = 6057)

#查询多行
res1 = db["instance"].find()

res1 为列表,每个元素为一个字典
acc_ins = {}
for k,v in res.items():
acc_ins[k] = v
acc_ins['Id'] = 26057
acc_ins['Name'] = 'aaa'
acc_ins['tanceId'] = 'ACCTINS_2663'

#用字典插入数据
db["instance"].insert(acc_ins)

# 存在则更新不存在插入,ID为26057,Name的值,ensure = False
db["instance"].upsert(dict(Id=26057, Name='dddddeeeee'),['Id'] ,ensure = False)
res = db["instance"].find_one(Id = 26057)
print(res)
内容来源于网络如有侵权请私信删除