Is it possible to store Python class objects in SQLite?

后端 未结 9 2052
独厮守ぢ
独厮守ぢ 2020-12-22 17:42

I would like to store Python objects into a SQLite database. Is that possible?

If so what would be some links / examples for it?

9条回答
  •  孤城傲影
    2020-12-22 18:05

    Yes it's possible but there are different approaches and which one is the suitable one, will depend on your requirements.

    • Pickling

      You can use the pickle module to serialize objects, then store these objects in a blob in sqlite3 (or a textfield, if the dump is e.g. base64 encoded). Be aware of some possible problems: questions/198692/can-i-pickle-a-python-dictionary-into-a-sqlite3-text-field

    • Object-Relational-Mapping

      You can use object relational mapping. This creates, in effect, a "virtual object database" that can be used from within the programming language (Wikipedia). For python, there is a nice toolkit for that: sqlalchemy.

提交回复
热议问题