python dataset 库用法[Python常见问题]

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)
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » python dataset 库用法