Created
July 20, 2011 11:59
-
-
Save patrys/1094832 to your computer and use it in GitHub Desktop.
A custom sqlite3 database backend for Django that turns synchronous mode off
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
sqlite3 database backend with non-synchronous mode. | |
It gives you a huge performance boost by turning off the overzealous | |
synchronous operation mode. The tradeoff is less data protection in case of | |
power outages but come on, you were not going to use it in production, were you? | |
""" | |
from django.db.backends.sqlite3.base import ( | |
DatabaseWrapper as Sqlite3Wrapper, | |
DatabaseError, | |
IntegrityError, | |
DatabaseFeatures, | |
DatabaseOperations, | |
) | |
__all__ = ['DatabaseWrapper', 'DatabaseError', 'IntegrityError', | |
'DatabaseFeatures', 'DatabaseOperations'] | |
class DatabaseWrapper(Sqlite3Wrapper): | |
def _cursor(self): | |
new_conn = self.connection is None | |
cur = super(DatabaseWrapper, self)._cursor() | |
if new_conn: | |
cur.execute('PRAGMA synchronous=OFF') | |
return cur |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment