Example #1
0
def db():
    """Function db - returns a Database Connection object from pool.

    A Connection pool is created if one does not exist yet.

    Database types and parameters obtained from settings.ini file.

    Supported types are:

        * mysql
        * sqlite3

    Returns:
         Database Connection object
    """
    kwargs = g.app.config.kwargs('database')
    global _cached_pool
    if kwargs.get('type') == 'mysql':
        if _cached_pool.get(os.getpid()) is None:
            _cached_pool[os.getpid()] = Pool(
                _get_conn,
                pool_size=kwargs.get('pool_size', 64),
                max_overflow=kwargs.get('max_overflow', 0))
        return _cached_pool[os.getpid()]()
    elif kwargs.get('type') == 'sqlite3':
        from luxon.core.db.sqlite import connect
        db = "sqlite3.db"

        db = (os.path.abspath(os.path.join(g.app.path, db)))
        return connect(db)
    else:
        raise TypeError('Unknown Database type defined in configuration')
Example #2
0
def _get_conn():
    """_get_conn function for internal use

    Returns a connect object populated with the information under
    the 'database' section
    """
    kwargs = g.app.config.kwargs('database')
    if kwargs.get('type') == 'mysql':
        return connect(kwargs.get('host', '127.0.0.1'),
                       kwargs.get('username', 'tachyonic'),
                       kwargs.get('password', 'password'),
                       kwargs.get('database', 'tachyonic'))
Example #3
0
def _get_conn():
    """_get_conn function for internal use

    Imports connect module if required.
    i.e. the database type in settings.ini is mysql
    Returns a connect object populated with the information under the 'database' section

    """
    # #PERFORMANCE - ONLY IMPORT HERE!
    kwargs = g.config.kwargs('database')
    if kwargs.get('type') == 'mysql':
        from luxon.core.db.mysql import connect
        return connect(kwargs.get('host', '127.0.0.1'),
                       kwargs.get('username', 'tachyonic'),
                       kwargs.get('password', 'password'),
                       kwargs.get('database', 'tachyonic'))