Skip to content

Instantly share code, notes, and snippets.

@patrys
Created July 20, 2011 11:59
Show Gist options
  • Save patrys/1094832 to your computer and use it in GitHub Desktop.
Save patrys/1094832 to your computer and use it in GitHub Desktop.
A custom sqlite3 database backend for Django that turns synchronous mode off
"""
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