使用Python / SQLAlchemy中的SQLite备份API

时间:2021-02-21 17:03:01

I'm using an SQLite database from python (with SQLAlchemy). For performance reasons, I'd like to populate an in-memory database in the application, and then back up that database to disk.

我正在使用python中的SQLite数据库(使用SQLAlchemy)。出于性能原因,我想在应用程序中填充内存数据库,然后将该数据库备份到磁盘。

SQLite has a backup API, which seems would do this transparently.

SQLite有一个备份API,它似乎可以透明地执行此操作。

The APSW documentation says that it wraps the backup API, but I'd like to access this functionality from Python's standard sqlite3 module, or in the best case from SQLAlchemy. Is this possible?

APSW文档说它包装了备份API,但是我想从Python的标准sqlite3模块访问这个功能,或者最好从SQLAlchemy访问。这可能吗?

4 个解决方案

#1


The python-sqlite3-backup module claims to solve this problem.

python-sqlite3-backup模块声称可以解决这个问题。

#2


the APSW dialect can be added to SQLAlchemy pretty easily as well. It would be very easy to achieve in 0.6, which allows multiple kinds of DBAPI adapters to make use of a common dialect for the database in use.

APSW方言也可以很容易地添加到SQLAlchemy中。在0.6中实现它将非常容易,它允许多种DBAPI适配器为使用中的数据库使用通用方言。

#3


If pysqlite and apsw are linked against the same sqlite library then pysqlite can accept apsw connections. See:

如果pysqlite和apsw链接到同一个sqlite库,那么pysqlite可以接受apsw连接。看到:

http://docs.pysqlite.googlecode.com/hg/sqlite3.html#combining-apsw-and-pysqlite

I will try to do work on this (and other) approaches to getting apsw to work with SQLAlchemy as they are a very useful combination.

我将尝试使用这种(和其他)方法来使用apsw与SQLAlchemy一起工作,因为它们是非常有用的组合。

#4


When I do the following

当我做以下

import sqlite3
dir(sqlite3)

I see none of the backup API methods.

我没有看到任何备份API方法。

Therefore, the answer is no; you cannot access the API from the sqlite3 module. It appears that no one implemented it.

因此,答案是否定的;您无法从sqlite3模块访问API。似乎没有人实现它。

#1


The python-sqlite3-backup module claims to solve this problem.

python-sqlite3-backup模块声称可以解决这个问题。

#2


the APSW dialect can be added to SQLAlchemy pretty easily as well. It would be very easy to achieve in 0.6, which allows multiple kinds of DBAPI adapters to make use of a common dialect for the database in use.

APSW方言也可以很容易地添加到SQLAlchemy中。在0.6中实现它将非常容易,它允许多种DBAPI适配器为使用中的数据库使用通用方言。

#3


If pysqlite and apsw are linked against the same sqlite library then pysqlite can accept apsw connections. See:

如果pysqlite和apsw链接到同一个sqlite库,那么pysqlite可以接受apsw连接。看到:

http://docs.pysqlite.googlecode.com/hg/sqlite3.html#combining-apsw-and-pysqlite

I will try to do work on this (and other) approaches to getting apsw to work with SQLAlchemy as they are a very useful combination.

我将尝试使用这种(和其他)方法来使用apsw与SQLAlchemy一起工作,因为它们是非常有用的组合。

#4


When I do the following

当我做以下

import sqlite3
dir(sqlite3)

I see none of the backup API methods.

我没有看到任何备份API方法。

Therefore, the answer is no; you cannot access the API from the sqlite3 module. It appears that no one implemented it.

因此,答案是否定的;您无法从sqlite3模块访问API。似乎没有人实现它。