[英]Python 3 : Storing Data without loading it into memory
I am currently building a flask app that will have lots of data that I think I cannot load into memory.我目前正在构建一个 Flask 应用程序,其中包含大量我认为无法加载到内存中的数据。 I have searched many places, and have found the SQL seems to be a good solution.我搜索了很多地方,发现 SQL 似乎是一个很好的解决方案。 Sadly I cannot use SQL for this project due to some limitations of SQL.遗憾的是,由于 SQL 的一些限制,我无法在这个项目中使用 SQL。
My project consists many entries of我的项目包括许多条目
database[lookupkey1][lookupkey2]...and more lookup keys
My current plan is to override __getitem__ and __setitem__ and __delitem__ and replace them with calls to the database.我目前的计划是覆盖 __getitem__ 和 __setitem__ 和 __delitem__ 并将它们替换为对数据库的调用。 Is their any kind of database that can store large amounts of maps/dictionaries like他们的任何类型的数据库都可以存储大量地图/字典,例如
{"spam":{"bar":["foo","test"],"foo":["bar"]}}
I am also currently using JSON to save data, so it would be appreciated if the database had a easy way to migrate my current database.我目前也在使用 JSON 来保存数据,所以如果数据库有一种简单的方法来迁移我当前的数据库,我将不胜感激。
Sorry that I'm not very good at writing stack overflow questions.抱歉,我不太擅长编写堆栈溢出问题。
Most document-oriented DBs like MongoDB would allow you to save data as nested dict-list-like objects and query them using their keys and indexes.大多数面向文档的数据库(如 MongoDB)允许您将数据保存为嵌套的类似 dict-list 的对象,并使用它们的键和索引查询它们。
PS Accessing such a DB through a Python's dict accessors is a bad idea as it would produce a redundant DB query for each step which is highly ineffective and may lead to performance problems. PS 通过 Python 的 dict 访问器访问这样的数据库是一个坏主意,因为它会为每个步骤产生一个冗余的数据库查询,这是非常低效的,并可能导致性能问题。 Try looking at ORM for a DB you choose as most ORMs would allow you to access document-oriented DB's data in a way similar to accessing dicts and lists.尝试查看您选择的 DB 的 ORM,因为大多数 ORM 允许您以类似于访问字典和列表的方式访问面向文档的 DB 数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.