在python中,如何在连接之前将sqlite db完全加载到内存中?

rel*_*ima 8 python sql memory sqlite

我有一个100兆字节的sqlite db文件,我想在执行sql查询之前加载到内存.有可能在python中这样做吗?

谢谢

Rya*_*rom 12

apsw是sqlite的备用包装器,它允许您在执行操作之前将磁盘上的数据库备份到内存.

来自文档:

###
### 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
Run Code Online (Sandbox Code Playgroud)

connection 上面是你的磁盘数据库.