Advertisement
Guest User

Creating a new scheme for storm.orm to handle sqlite with foreign keys support

a guest
Nov 17th, 2010
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. from storm.databases.sqlite import SQLite
  2. import storm.database
  3.  
  4. try:
  5.     from pysqlite2 import dbapi2 as sqlite
  6. except ImportError:
  7.     try:
  8.         from sqlite3 import dbapi2 as sqlite
  9.     except ImportError:
  10.         sqlite = dummy
  11.  
  12.  
  13. class SQLiteFK(SQLite):
  14.     def __init__(self, uri):
  15.         SQLite.__init__(self, uri)
  16.  
  17.     def raw_connect(self):
  18.         # See the story at the end to understand why we set isolation_level.
  19.         raw_connection = sqlite.connect(self._filename, timeout=self._timeout,
  20.                                         isolation_level=None)
  21.         if self._synchronous is not None:
  22.             raw_connection.execute("PRAGMA synchronous = %s" %
  23.                                    (self._synchronous,))
  24.  
  25.         # enable foreign keys
  26.         raw_connection.execute("PRAGMA foreign_keys = ON;")
  27.         return raw_connection
  28.  
  29.  
  30. storm.database.register_scheme("sqlite", SQLiteFK)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement