-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
selectable.py
84 lines (67 loc) · 1.96 KB
/
selectable.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from sqlalchemy.sql.base import _generative
from sqlalchemy.sql.selectable import (
Select as StandardSelect,
Join
)
from ..ext.clauses import (
ArrayJoin,
LeftArrayJoin,
LimitByClause,
sample_clause,
)
__all__ = ('Select', 'select')
class Select(StandardSelect):
_with_cube = False
_with_rollup = False
_with_totals = False
_final_clause = None
_sample_clause = None
_limit_by_clause = None
_array_join = None
@_generative
def with_cube(self):
self._with_cube = True
return self
@_generative
def with_rollup(self):
self._with_rollup = True
return self
@_generative
def with_totals(self):
self._with_totals = True
return self
@_generative
def final(self):
self._final_clause = True
return self
@_generative
def sample(self, sample):
self._sample_clause = sample_clause(sample)
return self
@_generative
def limit_by(self, by_clauses, limit, offset=None):
self._limit_by_clause = LimitByClause(by_clauses, limit, offset)
return self
def _add_array_join(self, columns, left):
join_type = ArrayJoin if not left else LeftArrayJoin
self._array_join = join_type(*columns)
@_generative
def array_join(self, *columns, **kwargs):
left = kwargs.get("left", False)
self._add_array_join(columns, left=left)
return self
@_generative
def left_array_join(self, *columns):
self._add_array_join(columns, left=True)
return self
def join(self, right, onclause=None, isouter=False, full=False, type=None,
strictness=None, distribution=None):
flags = {
'full': full,
'type': type,
'strictness': strictness,
'distribution': distribution
}
return Join(self, right, onclause=onclause, isouter=isouter,
full=flags)
select = Select