當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。