[英]Python: How to store a dictionary with UnQLite?
I want to store a dictionary in an UnQLite database, so I can use it later on. 我想将字典存储在UnQLite数据库中,因此以后可以使用它。 However UnQLite stores it as a string:
但是UnQLite将其存储为字符串:
>>> from unqlite import UnQLite
>>> db = UnQLite()
>>> db['dict'] = {'a': 5}
>>> db['dict']
"{'a': 5}"
I've figured out that I can use collection
which then retrieves data with their native type. 我发现我可以使用
collection
,然后使用其本机类型检索数据。
>>> from unqlite import UnQLite
>>> db = UnQLite()
>>> colors = db.collection('colors')
>>> if not colors.exists():
... colors.create()
...
>>> colors.store([{'name': 'red', 'code': '#ff0000'}, {'name': 'green', 'code': '#00ff00'}])
1
>>> colors.all()
[{'code': '#ff0000', 'name': 'red', '__id': 0}, {'code': '#00ff00', 'name': 'green', '__id': 1}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.