As sqlite3.connect (': memory:') The DB image created in memory is You can save it by making it a dump file.
In the sample below, the dump file is stored as gzip.
python
#Load from file
con = sqlite3.connect(':memory:')
fp = gzip.open('./dump.sql.gz' ,'rb')
con.executescript(fp.read())
fp.close()
#Save to file
fp = gzip.open('./dump.sql.gz','wb')
for line in con.iterdump():
fp.write('%s\n' % line)
fp.close()
However, if the number of cases increases with this method, It is not practical because it takes a long time to load.
Practically without using sqlite3.connect (': memory:') You should put the db file in tmpfs.
Recommended Posts