~jdahlin-deactivatedaccount/storm/storm-sqlobject-improvements

« back to all changes in this revision

Viewing changes to storm/databases/postgres.py

  • Committer: Thomas Hervé
  • Date: 2008-08-18 19:49:58 UTC
  • mfrom: (256.1.4 postgres-autocommit-2)
  • Revision ID: thomas@canonical.com-20080818194958-uydo6svy9zutggzl
Merge postgres-autocommit-2 [r=jamesh,niemeyer]

Add the ability to specify the isolation level via the URI for Postgres
connections.

Show diffs side-by-side

added added

removed removed

Lines of Context:
313
313
        if psycopg2 is dummy:
314
314
            raise DatabaseModuleError("'psycopg2' module not found")
315
315
        self._dsn = make_dsn(uri)
 
316
        isolation = uri.options.get("isolation", "serializable")
 
317
        isolation_mapping = {
 
318
            "autocommit": psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT,
 
319
            "serializable": psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE,
 
320
            "read-committed": psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED,
 
321
        }
 
322
        try:
 
323
            self._isolation = isolation_mapping[isolation]
 
324
        except KeyError:
 
325
            raise ValueError(
 
326
                "Unknown serialization level %r: expected one of "
 
327
                "'autocommit', 'serializable', 'read-committed'" %
 
328
                (isolation,))
316
329
 
317
330
    def raw_connect(self):
318
331
        raw_connection = psycopg2.connect(self._dsn)
350
363
            raw_connection.rollback()
351
364
 
352
365
        raw_connection.set_client_encoding("UTF8")
353
 
        raw_connection.set_isolation_level(
354
 
            psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE)
 
366
        raw_connection.set_isolation_level(self._isolation)
355
367
        return raw_connection
356
368
 
357
369