这个问题已经有了答案:
How to load existing db file to memory in Python sqlite3?
9个答案
我有一个100兆字节的sqlite-db文件,我想在执行SQL查询之前加载到内存中。在Python中可以这样做吗?
谢谢
最佳答案
apsw是sqlite的备用包装器,它使您能够在执行操作之前将磁盘上的数据库备份到内存中。
从docs开始:
###
### Backup to memory
###
# We will copy the disk database into a memory database
memcon=apsw.Connection(":memory:")
# Copy into memory
with memcon.backup("main", connection, "main") as backup:
backup.step() # copy whole database in one go
# There will be no disk accesses for this query
for row in memcon.cursor().execute("select * from s"):
pass
上面的是您的磁盘数据库。