Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use SQLite's backup API from Python/SQLAlchemy

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.

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

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?

like image 655
Ryan Ginstrom Avatar asked Jul 02 '09 04:07

Ryan Ginstrom


2 Answers

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.

like image 79
zzzeek Avatar answered Oct 13 '22 00:10

zzzeek


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

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.

like image 37
Paul Harrington Avatar answered Oct 13 '22 00:10

Paul Harrington