-
-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathclauses.py
More file actions
65 lines (46 loc) · 1.59 KB
/
Copy pathclauses.py
File metadata and controls
65 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from sqlalchemy import util, exc
from sqlalchemy.sql import type_api, roles
from sqlalchemy.sql.elements import (
BindParameter,
ColumnElement,
ClauseList
)
from sqlalchemy.sql.util import _offset_or_limit_clause
from sqlalchemy.sql.visitors import Visitable
class SampleParam(BindParameter):
pass
def sample_clause(element):
"""Convert the given value to an "sample" clause.
This handles incoming element to an expression; if
an expression is already given, it is passed through.
"""
if element is None:
return None
elif hasattr(element, '__clause_element__'):
return element.__clause_element__()
elif isinstance(element, Visitable):
return element
else:
return SampleParam(None, element, unique=True)
class LimitByClause:
def __init__(self, by_clauses, limit, offset):
self.by_clauses = ClauseList(
*by_clauses, _literal_as_text=roles.ByOfRole
)
self.offset = _offset_or_limit_clause(offset)
self.limit = _offset_or_limit_clause(limit)
def __bool__(self):
return bool(self.by_clauses.clauses)
class Lambda(ColumnElement):
"""Represent a lambda function, ``Lambda(lambda x: 2 * x)``."""
__visit_name__ = 'lambda'
inherit_cache = True
def __init__(self, func):
if not util.callable(func):
raise exc.ArgumentError('func must be callable')
self.type = type_api.NULLTYPE
self.func = func
class ArrayJoin(ClauseList):
__visit_name__ = 'array_join'
class LeftArrayJoin(ClauseList):
__visit_name__ = 'left_array_join'