本文整理汇总了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_=''
)
示例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
示例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_=''
)
示例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)
示例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_)
示例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})
示例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 ------------------------------------------------------------------------
示例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)