当前位置: 首页>>代码示例>>Python>>正文


Python sql.case方法代码示例

本文整理汇总了Python中sqlalchemy.sql.case方法的典型用法代码示例。如果您正苦于以下问题:Python sql.case方法的具体用法?Python sql.case怎么用?Python sql.case使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.sql的用法示例。


在下文中一共展示了sql.case方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: recurrence_str

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import case [as 别名]
def recurrence_str(cls):
        return case(
            [
                (
                    cls.date.isnot(None),
                    func.date_format(cls.date, '%Y-%m-%d')
                ),
                (
                    cls.day_of_month.isnot(None),
                    cls.day_of_month
                ),
                (
                    cls.num_per_period.isnot(None),
                    func.concat(cls.num_per_period, ' per period')
                )
            ],
            else_=''
        ) 
开发者ID:jantman,项目名称:biweeklybudget,代码行数:20,代码来源:scheduled_transaction.py

示例2: _validate_join_arg_on

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import case [as 别名]
def _validate_join_arg_on(on, sql_on = None):
    # handle sql on case
    if sql_on is not None:
        if on is not None:
            raise ValueError("Cannot specify both on and sql_on")

        return sql_on

    # handle general cases
    if on is None:
        raise NotImplementedError("on arg currently cannot be None (default) for SQL")
    elif isinstance(on, str):
        on = {on: on}
    elif isinstance(on, (list, tuple)):
        on = dict(zip(on, on))

    if not isinstance(on, Mapping):
        raise TypeError("on must be a Mapping (e.g. dict)")

    return on 
开发者ID:machow,项目名称:siuba,代码行数:22,代码来源:verbs.py

示例3: schedule_type

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import case [as 别名]
def schedule_type(cls):
        return case(
            [
                (cls.date.isnot(None), 'date'),
                (cls.day_of_month.isnot(None), 'monthly'),
                (cls.num_per_period.isnot(None), 'per period')
            ],
            else_=''
        ) 
开发者ID:jantman,项目名称:biweeklybudget,代码行数:11,代码来源:scheduled_transaction.py

示例4: case_greatest

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import case [as 别名]
def case_greatest(element, compiler, **kw):
    arg1, arg2 = list(element.clauses)
    return compiler.process(case([(arg1 > arg2, arg1)], else_=arg2), **kw) 
开发者ID:Nukesor,项目名称:sticker-finder,代码行数:5,代码来源:db.py

示例5: sql_if

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import case [as 别名]
def sql_if(cond, then, else_=None):
    return case([(cond, then)], else_=else_) 
开发者ID:fedora-infra,项目名称:koschei,代码行数:4,代码来源:api.py

示例6: _sql_rank_over

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import case [as 别名]
def _sql_rank_over(rank_func, col, partition):
    # partitioning ensures aggregates that use total length are correct
    # e.g. percent rank, cume_dist and friends
    over_clause = RankOver(
            rank_func(),
            order_by = col,
            partition_by = col.isnot(None) if partition else None
            )

    return sql.case({col.isnot(None): over_clause}) 
开发者ID:machow,项目名称:siuba,代码行数:12,代码来源:vector.py

示例7: _case_when

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import case [as 别名]
def _case_when(__data, cases):
    # TODO: will need listener to enter case statements, to handle when they use windows
    if isinstance(cases, Call):
        cases = cases(__data)

    whens = []
    case_items = list(cases.items())
    n_items = len(case_items)

    else_val = None
    for ii, (expr, val) in enumerate(case_items):
        # handle where val is a column expr
        if callable(val):
            val = val(__data)

        # handle when expressions
        if ii+1 == n_items and expr is True:
            else_val = val
        elif callable(expr):
            whens.append((expr(__data), val))
        else:
            whens.append((expr, val))

    return sql.case(whens, else_ = else_val)
        

# Join ------------------------------------------------------------------------ 
开发者ID:machow,项目名称:siuba,代码行数:29,代码来源:verbs.py

示例8: _if_else

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import case [as 别名]
def _if_else(cond, true_vals, false_vals):
    whens = [(cond, true_vals)]
    return sql.case(whens, else_ = false_vals) 
开发者ID:machow,项目名称:siuba,代码行数:5,代码来源:verbs.py


注:本文中的sqlalchemy.sql.case方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。