SQLite3 join from StringIO (Python)

I am wondering if anyone knows a way to create a connection to a SQLite database in python from a StringIO object.

I have a compressed SQLite3 database file and I would like to unzip it using the gzip library and then connect to it without first creating a temporary file.

I looked at the source of the slqite3 library, but it looks like the filename is passed completely to the C code. Are there any other SQLite3 connection libraries for which you can use the file identifier? Or are there some reasons why I can trick the sqlite3 built-in library sqlite3 believing that my StringIO (or some other type of object) is the actual file?

+6
source share
1 answer

Python's sqlite3 module cannot open the database from a file number, and even using StringIO will not give you the file number (since it does not open the file, it simply emulates a Python file object).

You can use a special file name :memory: to avoid writing the file to disk and then writing it to disk as soon as you are done with it. It also ensures that the file is optimized for size, and you can opt out of writing, for example. indexes if size is really a big problem.

+3
source

Source: https://habr.com/ru/post/958428/


All Articles