首页 > 解决方案 > Peewee Sqlite 在内存数据库中的共享

问题描述

阅读这篇文章,我了解到可以跨线程共享内存数据库:

https://stackoverflow.com/a/24708173/7754093

使用 sqlite python 包我可以做到这一点:

sqlite3.connect('file:foobar_database?mode=memory&cache=shared', uri=True)

如何在 Peewee 中做到这一点?我找不到任何描述它的文档。

标签: multithreadingsqlitepeeweein-memory-database

解决方案


如果您的sqlite3模块可以成功连接到共享内存数据库,则以下操作将起作用:

from peewee import *
sqlite_db = SqliteDatabase('file:foobar_database?mode=memory&cache=shared')

推荐阅读