Esempio n. 1
0
    def db(self, role='replica', db_name=None):
        if not hasattr(self, '_db'): self._db = {}
        name = db_name or self.db_names.get(role)

        if name not in self._db:
            self._db[name] = DatabaseConnections.connection(name)

        return self._db[name]
Esempio n. 2
0
def query(sql=None, filename=None, extract=None, db=None, **kwargs):
    if db is None:
        raise argparse.ArgumentError('You must provide a database name')

    kwargs['stack'] = stack_marker(inspect.stack())

    filename = filename or extract

    if filename and not filename.startswith('/'):
        filename = os.path.join(os.environ['PWD'], filename)

    if 'where' not in kwargs and 'params' in kwargs:
        kwargs['where'] = kwargs['params']

    return DatabaseAdapter(DatabaseConnections.connection(db),
                           None).raw_query(sql=sql,
                                           filename=filename,
                                           **kwargs)
Esempio n. 3
0
 def wrapper(*args, **kwargs):
     if DatabaseConnections.connection(
             'jardin_test').db_config.scheme in schemes:
         return func(*args, **kwargs)
Esempio n. 4
0
 def __init__(self, db):
     self.connection = DatabaseConnections.connection(db)
Esempio n. 5
0
def reset_session():
    DatabaseConnections.shuffle_connections()