Exemplo n.º 1
0
from sqlalchemy import schema

from sqlalchemy import MetaData
from sqlalchemy.engine import reflection
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import Session
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.query import Query
from sqlalchemy import sql

from nailgun.db import deadlock_detector as dd
from nailgun.db.sqlalchemy import utils
from nailgun.settings import settings

#按配置生成与数据库的连接
db_str = utils.make_dsn(**settings.DATABASE)
engine = create_engine(db_str, client_encoding='utf8')


class DeadlocksSafeQueryMixin(object):
    """Introduces ordered by id bulk deletes and updates into Query

    """
    def _get_tables(self):
        """ Extracts table names from Query

        :return: generator to collection of strings
        """
        for ent in self._entities:
            yield '{0}'.format(ent.selectable)
Exemplo n.º 2
0
 def test_make_dsn_with_socket(self):
     self.default_settings['host'] = '/path/to/socket'
     dsn = utils.make_dsn(**self.default_settings)
     self.assertEqual(
         dsn, 'db_engine://db_user:db_pass@/database?host=/path/to/socket')
Exemplo n.º 3
0
 def test_make_dsn_with_regular_host(self):
     dsn = utils.make_dsn(**self.default_settings)
     self.assertEqual(
         dsn, 'db_engine://db_user:db_pass@localhost:8080/database')
Exemplo n.º 4
0
 def test_make_dsn_with_socket(self):
     self.default_settings["host"] = "/path/to/socket"
     dsn = utils.make_dsn(**self.default_settings)
     self.assertEqual(dsn, "db_engine://db_user:db_pass@/database?host=/path/to/socket")
Exemplo n.º 5
0
 def test_make_dsn_with_regular_host(self):
     dsn = utils.make_dsn(**self.default_settings)
     self.assertEqual(dsn, "db_engine://db_user:db_pass@localhost:8080/database")
Exemplo n.º 6
0
from sqlalchemy import schema

from sqlalchemy import MetaData
from sqlalchemy.engine import reflection
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import Session
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.query import Query
from sqlalchemy import sql

from nailgun.db import deadlock_detector as dd
from nailgun.db.sqlalchemy import utils
from nailgun.settings import settings


db_str = utils.make_dsn(**settings.DATABASE)
engine = create_engine(db_str, client_encoding='utf8')


class NoCacheQuery(Query):
    """Override for common Query class.
    Needed for automatic refreshing objects
    from database during every query for evading
    problems with multiple sessions
    """
    def __init__(self, *args, **kwargs):
        self._populate_existing = True
        super(NoCacheQuery, self).__init__(*args, **kwargs)


class DeadlocksSafeQueryMixin(object):