orm.py 文件源码

python
阅读 42 收藏 0 点赞 0 评论 0

项目:fleaker 作者: croscon 项目源码 文件源码
def _discover_ideal_backend(orm_backend):
    """Auto-discover the ideal backend based on what is installed.

    Right now, handles discovery of:
      * PeeWee
      * SQLAlchemy

    Args:
        orm_backend (str): The ``orm_backend`` value that was passed to the
            ``create_app`` function. That is, the ORM Backend the User
            indicated they wanted to use.

    Returns:
        str|fleaker.missing.MissingSentinel: Returns a string for the ideal
            backend if it found one, or :obj:`fleaker.MISSING` if we couldn't
            find one.

    Raises:
        RuntimeError: Raised if no user provided ORM Backend is given and BOTH
            PeeWee and SQLAlchemy are installed.
    """
    if orm_backend:
        return orm_backend

    if peewee is not MISSING and sqlalchemy is not MISSING:
        raise RuntimeError('Both PeeWee and SQLAlchemy detected as installed, '
                           'but no explicit backend provided! Please specify '
                           'one!')
    if peewee is not MISSING:
        return _PEEWEE_BACKEND
    elif sqlalchemy is not MISSING:
        return _SQLALCHEMY_BACKEND
    else:
        return MISSING
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号