def db_uri(db_conf):
    """Return the database URI, given the database config."""
    if db_conf.get('engine') == 'memory':
        return 'sqlite:///:memory:'
    elif db_conf.get('engine') == 'sqlite':
        return '{engine}:///{host}'.format(**dict(db_conf))
    return '{engine}://{user}:{password}@{host}:{port}/{name}'.format(
        **dict(db_conf)
    )