def getStore(url, create = False): # register new Storm scheme register_scheme("sqlitefk", ForeignKeysSQLite) d = create_database(url) s = Store(d) if create: schema = file(os.path.join(os.path.dirname(__file__), "schema.sql"), "r").read().split("\n\n") for cmd in schema: s.execute(cmd) version = Meta() version.key = u"created" s.add(version) s.commit() return s
# 'database' setting instead of 'dbname' + 'dbhost' settings. self._dsn = 'dbname=%s user=%s' % (config.launchpad_session.dbname, config.launchpad_session.dbuser) if config.launchpad_session.dbhost: self._dsn += ' host=%s' % config.launchpad_session.dbhost flags = _get_dirty_commit_flags() raw_connection = super(LaunchpadSessionDatabase, self).raw_connect() if safe_hasattr(raw_connection, 'auto_close'): raw_connection.auto_close = False raw_connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) _reset_dirty_commit_flags(*flags) return raw_connection register_scheme('launchpad', LaunchpadDatabase) register_scheme('launchpad-session', LaunchpadSessionDatabase) class LaunchpadTimeoutTracer(PostgresTimeoutTracer): """Storm tracer class to keep statement execution time bounded.""" def __init__(self): # The parent class __init__ just sets the granularity # attribute, which we are handling with a property. pass @property def granularity(self): return config.database.db_statement_timeout_precision / 1000.0 def connection_raw_execute(self, connection, raw_cursor, statement,
using PsycoSpans paired with Spans. from spans import intrange from storm.locals import * from stormspans import IntRange class Model(Storm): id = Int(primary=True) span = IntRange(default=intrange(1, 10)) To connect to the database "postgres+spans://..." must be specified instead of "postgres://..." """ __version__ = "0.1.0" from storm.database import register_scheme from .database import PostgresStormSpans, install_range from .properties import * __all__ = [ "IntRange", "FloatRange", "DateRange", "DateTimeRange", "install_range" ] register_scheme("postgres+spans", PostgresStormSpans)
"""Create a connection and set it's name to the database name. The connection name is used by storm's TimelineTracer to identify the connection used for a specific query. """ connection = super(FilesyncDatabase, self).connect(event=event) connection.name = self.name return connection # We set the override the registered uri scheme for 'postgres' so that the # custom Postgres-based database factory above is used, setting a 'name' # attribute on the connection that matches the requested database, causing the # TimelineTracer to then include that database name as part of the actions # traced. register_scheme("postgres", FilesyncDatabase) def get_django_stores(): """Return a dictionary of configured stores for django.""" settings = get_connection_settings() storm_stores = {} for key, cfg in settings.items(): storm_stores[key] = get_postgres_uri(cfg) return storm_stores def get_store(store_name, zstorm=None): """Return the Storm.Store for the given schema""" if not zstorm: zstorm = account_zstorm
self._dsn = 'dbname=%s user=%s' % ( config.launchpad_session.dbname, config.launchpad_session.dbuser) if config.launchpad_session.dbhost: self._dsn += ' host=%s' % config.launchpad_session.dbhost flags = _get_dirty_commit_flags() raw_connection = super(LaunchpadSessionDatabase, self).raw_connect() if safe_hasattr(raw_connection, 'auto_close'): raw_connection.auto_close = False raw_connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) _reset_dirty_commit_flags(*flags) return raw_connection register_scheme('launchpad', LaunchpadDatabase) register_scheme('launchpad-session', LaunchpadSessionDatabase) class LaunchpadTimeoutTracer(PostgresTimeoutTracer): """Storm tracer class to keep statement execution time bounded.""" def __init__(self): # The parent class __init__ just sets the granularity # attribute, which we are handling with a property. pass @property def granularity(self): return config.database.db_statement_timeout_precision / 1000.0
""" StormSpans brings support for PostgreSQL's range types to Canonical's Storm using PsycoSpans paired with Spans. from spans import intrange from storm.locals import * from stormspans import IntRange class Model(Storm): id = Int(primary=True) span = IntRange(default=intrange(1, 10)) To connect to the database "postgres+spans://..." must be specified instead of "postgres://..." """ __version__ = "0.1.0" from storm.database import register_scheme from .database import PostgresStormSpans, install_range from .properties import * __all__ = [ "IntRange", "FloatRange", "DateRange", "DateTimeRange", "install_range" ] register_scheme("postgres+spans", PostgresStormSpans)