omlish 0.0.0.dev200__py3-none-any.whl → 0.0.0.dev201__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev200'
2
- __revision__ = '2c496f686e6c5d735b06d5836f93f26d8f63cf4e'
1
+ __version__ = '0.0.0.dev201'
2
+ __revision__ = '77be9dbd97d16b54293dbf9f3803e3fa882ecc5f'
3
3
 
4
4
 
5
5
  #
@@ -17,13 +17,13 @@ class StdBuilder(
17
17
  SelectBuilder,
18
18
  StmtBuilder,
19
19
 
20
+ RelationBuilder,
21
+
20
22
  MultiBuilder,
21
23
  BinaryBuilder,
22
24
  UnaryBuilder,
23
25
  ExprBuilder,
24
26
 
25
- RelationBuilder,
26
-
27
27
  ParamBuilder,
28
28
 
29
29
  NameBuilder,
@@ -30,7 +30,7 @@ class Insert(Stmt, lang.Final):
30
30
  CanValues: ta.TypeAlias = Values | ta.Sequence[CanExpr]
31
31
 
32
32
 
33
- class InsertBuilder(ExprBuilder, RelationBuilder):
33
+ class InsertBuilder(RelationBuilder, ExprBuilder):
34
34
  def values(self, vs: CanValues) -> Values:
35
35
  if isinstance(vs, Values):
36
36
  return vs
@@ -17,6 +17,7 @@ from .binary import BinaryOps
17
17
  from .exprs import Expr
18
18
  from .inserts import Values
19
19
  from .multi import MultiKind
20
+ from .relations import JoinKind
20
21
  from .relations import Relation
21
22
  from .selects import Select
22
23
  from .stmts import Stmt
@@ -66,8 +67,12 @@ def _install_standard_marshalling() -> None:
66
67
  msh.STANDARD_MARSHALER_FACTORIES[0:0] = [msh.TypeMapMarshalerFactory({ty: OpMarshalerUnmarshaler(ty, ns)})]
67
68
  msh.STANDARD_UNMARSHALER_FACTORIES[0:0] = [msh.TypeMapUnmarshalerFactory({ty: OpMarshalerUnmarshaler(ty, ns)})]
68
69
 
69
- msh.STANDARD_MARSHALER_FACTORIES[0:0] = [msh.TypeMapMarshalerFactory({MultiKind: LowerEnumMarshaler(MultiKind)})]
70
- msh.STANDARD_UNMARSHALER_FACTORIES[0:0] = [msh.TypeMapUnmarshalerFactory({MultiKind: LowerEnumMarshaler(MultiKind)})] # noqa
70
+ ets = [
71
+ JoinKind,
72
+ MultiKind,
73
+ ]
74
+ msh.STANDARD_MARSHALER_FACTORIES[0:0] = [msh.TypeMapMarshalerFactory({t: LowerEnumMarshaler(t) for t in ets})]
75
+ msh.STANDARD_UNMARSHALER_FACTORIES[0:0] = [msh.TypeMapUnmarshalerFactory({t: LowerEnumMarshaler(t) for t in ets})]
71
76
 
72
77
  for cls in [
73
78
  Expr,
@@ -3,15 +3,18 @@ TODO:
3
3
  - join
4
4
  - subquery
5
5
  """
6
+ import enum
6
7
  import typing as ta
7
8
 
8
9
  from ... import dataclasses as dc
9
10
  from ... import lang
10
11
  from .base import Node
12
+ from .exprs import CanExpr
13
+ from .exprs import Expr
11
14
  from .idents import Ident
15
+ from .multi import MultiBuilder
12
16
  from .names import CanName
13
17
  from .names import Name
14
- from .names import NameBuilder
15
18
 
16
19
 
17
20
  ##
@@ -21,22 +24,100 @@ class Relation(Node, lang.Abstract):
21
24
  pass
22
25
 
23
26
 
27
+ #
28
+
29
+
24
30
  class Table(Relation, lang.Final):
25
31
  n: Name
26
32
  a: Ident | None = dc.xfield(None, repr_fn=dc.opt_repr)
27
33
 
28
34
 
35
+ #
36
+
37
+
38
+ class JoinKind(enum.Enum):
39
+ DEFAULT = enum.auto()
40
+ INNER = enum.auto()
41
+ LEFT = enum.auto()
42
+ LEFT_OUTER = enum.auto()
43
+ RIGHT = enum.auto()
44
+ RIGHT_OUTER = enum.auto()
45
+ FULL = enum.auto()
46
+ FULL_OUTER = enum.auto()
47
+ CROSS = enum.auto()
48
+ NATURAL = enum.auto()
49
+
50
+
51
+ class Join(Relation, lang.Final):
52
+ k: JoinKind
53
+ l: Relation
54
+ r: Relation
55
+
56
+ c: Expr | None = None
57
+
58
+
59
+ ##
60
+
61
+
29
62
  CanTable: ta.TypeAlias = Table | CanName
30
63
  CanRelation: ta.TypeAlias = Relation | CanTable
31
64
 
32
65
 
33
- class RelationBuilder(NameBuilder):
66
+ class RelationBuilder(MultiBuilder):
34
67
  def table(self, n: CanTable) -> Table:
35
68
  if isinstance(n, Table):
36
69
  return n
37
70
  else:
38
71
  return Table(self.name(n))
39
72
 
73
+ #
74
+
75
+ def join(
76
+ self,
77
+ k: JoinKind,
78
+ l: CanRelation,
79
+ r: CanRelation,
80
+ *cs: CanExpr,
81
+ ) -> Join:
82
+ return Join(
83
+ k,
84
+ self.relation(l),
85
+ self.relation(r),
86
+ self.or_(*cs) if cs else None,
87
+ )
88
+
89
+ def default_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
90
+ return self.join(JoinKind.DEFAULT, l, r, *cs)
91
+
92
+ def inner_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
93
+ return self.join(JoinKind.INNER, l, r, *cs)
94
+
95
+ def left_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
96
+ return self.join(JoinKind.LEFT, l, r, *cs)
97
+
98
+ def left_outer_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
99
+ return self.join(JoinKind.LEFT_OUTER, l, r, *cs)
100
+
101
+ def right_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
102
+ return self.join(JoinKind.RIGHT, l, r, *cs)
103
+
104
+ def right_outer_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
105
+ return self.join(JoinKind.RIGHT_OUTER, l, r, *cs)
106
+
107
+ def full_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
108
+ return self.join(JoinKind.FULL, l, r, *cs)
109
+
110
+ def full_outer_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
111
+ return self.join(JoinKind.FULL_OUTER, l, r, *cs)
112
+
113
+ def cross_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
114
+ return self.join(JoinKind.CROSS, l, r, *cs)
115
+
116
+ def natural_join(self, l: CanRelation, r: CanRelation, *cs: CanExpr) -> Join:
117
+ return self.join(JoinKind.NATURAL, l, r, *cs)
118
+
119
+ #
120
+
40
121
  def relation(self, o: CanRelation) -> Relation:
41
122
  if isinstance(o, Relation):
42
123
  return o
@@ -36,6 +36,8 @@ from .multi import Multi
36
36
  from .multi import MultiKind
37
37
  from .names import Name
38
38
  from .params import Param
39
+ from .relations import Join
40
+ from .relations import JoinKind
39
41
  from .relations import Table
40
42
  from .selects import Select
41
43
  from .selects import SelectItem
@@ -156,7 +158,6 @@ class StdRenderer(Renderer):
156
158
  MULTI_KIND_TO_STR: ta.ClassVar[ta.Mapping[MultiKind, str]] = {
157
159
  MultiKind.AND: 'and',
158
160
  MultiKind.OR: 'or',
159
-
160
161
  }
161
162
 
162
163
  @Renderer.render.register
@@ -187,6 +188,30 @@ class StdRenderer(Renderer):
187
188
  self._out.write(' as ')
188
189
  self.render(o.a)
189
190
 
191
+ JOIN_KIND_TO_STR: ta.ClassVar[ta.Mapping[JoinKind, str]] = {
192
+ JoinKind.DEFAULT: 'join',
193
+ JoinKind.INNER: 'inner join',
194
+ JoinKind.LEFT: 'left join',
195
+ JoinKind.LEFT_OUTER: 'left outer join',
196
+ JoinKind.RIGHT: 'right join',
197
+ JoinKind.RIGHT_OUTER: 'right outer join',
198
+ JoinKind.FULL: 'full join',
199
+ JoinKind.FULL_OUTER: 'full outer join',
200
+ JoinKind.CROSS: 'cross join',
201
+ JoinKind.NATURAL: 'natural join',
202
+ }
203
+
204
+ @Renderer.render.register
205
+ def render_join(self, o: Join) -> None:
206
+ self.render(o.l)
207
+ self._out.write(' ')
208
+ self._out.write(self.JOIN_KIND_TO_STR[o.k])
209
+ self._out.write(' ')
210
+ self.render(o.r)
211
+ if o.c is not None:
212
+ self._out.write(' on ')
213
+ self.render(o.c)
214
+
190
215
  # selects
191
216
 
192
217
  @Renderer.render.register
@@ -30,7 +30,7 @@ class Select(Stmt, lang.Final):
30
30
  CanSelectItem: ta.TypeAlias = SelectItem | CanExpr
31
31
 
32
32
 
33
- class SelectBuilder(ExprBuilder, RelationBuilder):
33
+ class SelectBuilder(RelationBuilder, ExprBuilder):
34
34
  def select_item(self, o: CanSelectItem) -> SelectItem:
35
35
  if isinstance(o, SelectItem):
36
36
  return o
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: omlish
3
- Version: 0.0.0.dev200
3
+ Version: 0.0.0.dev201
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -1,5 +1,5 @@
1
1
  omlish/.manifests.json,sha256=dyIpveH7Z8OnQp2pTn6NVv7LCDXVrozJWAzbk8PBavg,7950
2
- omlish/__about__.py,sha256=AJX5iNOlWrDlDBEKE35thbObkh7MHjKwPM855AMs7ls,3409
2
+ omlish/__about__.py,sha256=nozjeM6WZjCDpl0YL18Qfh8ve_0Ihl-hf7OLBlfHY70,3409
3
3
  omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
4
4
  omlish/c3.py,sha256=ubu7lHwss5V4UznbejAI0qXhXahrU01MysuHOZI9C4U,8116
5
5
  omlish/cached.py,sha256=UI-XTFBwA6YXWJJJeBn-WkwBkfzDjLBBaZf4nIJA9y0,510
@@ -545,18 +545,18 @@ omlish/sql/alchemy/sqlean.py,sha256=RbkuOuFIfM4fowwKk8-sQ6Dxk-tTUwxS94nY5Kxt52s,
545
545
  omlish/sql/queries/__init__.py,sha256=8wdq6PBf5YzqQWFu-CE8om6BN38sDAD9UEz9VzkojzM,1337
546
546
  omlish/sql/queries/base.py,sha256=_8O3MbH_OEjBnhp2oIJUZ3ClaQ8l4Sj9BdPdsP0Ie-g,224
547
547
  omlish/sql/queries/binary.py,sha256=dcEzeEn104AMPuQ7QrJU2O-YCN3SUdxB5S4jaWKOUqY,2253
548
- omlish/sql/queries/building.py,sha256=lmHItVEi0IkIDEhYL1le8adNhjah0SHhffm59CZtpH4,643
548
+ omlish/sql/queries/building.py,sha256=J2ZDfDyLzRm8q5-TLAN6I_qjhs-7RpfW23yuCYYLf5k,643
549
549
  omlish/sql/queries/exprs.py,sha256=THeSyFF8bouDvU-Keej-hyFUwbp63bw0HpAF4lCYuiQ,1187
550
550
  omlish/sql/queries/idents.py,sha256=w2RxO6SR3K-u30S259OtnAZaPv7YA70PzY9R7RtuCQ8,891
551
- omlish/sql/queries/inserts.py,sha256=Uo0ewnLPEt43dnX5AJWOC9ioViou7xYes7sGT9lD_0k,1281
552
- omlish/sql/queries/marshal.py,sha256=uLN_gOqiYHBQioZEvg7OREycY0bzKwzBw5mnbg_0cio,2938
551
+ omlish/sql/queries/inserts.py,sha256=H0Dv_6l--T7WXuoJQbLFd23PnjXA-3RETegjYnPr9lc,1281
552
+ omlish/sql/queries/marshal.py,sha256=T94501RbQn8UsUiRJkklvehtxJTYm2XTp03urMl1fas,3011
553
553
  omlish/sql/queries/multi.py,sha256=7x6x-4jnPzxA6ZasBjnjFuhHFpWt5rGCua3UvuTMIJ0,837
554
554
  omlish/sql/queries/names.py,sha256=4sDvgRobMEt_6mDeuYVbCqHzLCOwpXUdEyyB4-QjxKo,1996
555
555
  omlish/sql/queries/ops.py,sha256=B7IDfjr2DW5LJhWoNaY1WW90BJhe5ZtmxIELhWXbW-0,129
556
556
  omlish/sql/queries/params.py,sha256=iR8tnetkZFWY378iUbPe08d86g-Wf1J3YqfZr_KhIwQ,1175
557
- omlish/sql/queries/relations.py,sha256=-d3n-dN17c3TPMZmzSplhWawllUzdq12XPDAuzoeMEQ,838
558
- omlish/sql/queries/rendering.py,sha256=NOJqwxK8yt3Morq5yhgI-zU_51MSyhDvSc8S-8tURVM,5946
559
- omlish/sql/queries/selects.py,sha256=8dqm4KyrJvOsW3KHSO7qLEfPlZa7sJDp8puuGxrfvoA,1369
557
+ omlish/sql/queries/relations.py,sha256=7YrEC9IjoVpRGLAFKRSRsHHnTmx-g7hBNXsOgP2HOuI,2998
558
+ omlish/sql/queries/rendering.py,sha256=8naCMwxVEFAJaMP5m2bf6kCyhvwFZhXiWYEma51fQ4k,6813
559
+ omlish/sql/queries/selects.py,sha256=RFySZ9sb-nE29QrLLbQ7JYZW_V_ifaFTcl-RQTgQncY,1369
560
560
  omlish/sql/queries/stmts.py,sha256=pBqwD7dRlqMu6uh6vR3xaWOEgbZCcFWbOQ9ryYd17T4,441
561
561
  omlish/sql/queries/unary.py,sha256=MEYBDZn_H0bexmUrJeONOv5-gIpYowUaXOsEHeQM4ks,1144
562
562
  omlish/sql/tabledefs/__init__.py,sha256=TvtQsp-jJu6_ZahyCOFAaElSSBcRftNyJpdiDPGYCDk,190
@@ -609,9 +609,9 @@ omlish/text/indent.py,sha256=YjtJEBYWuk8--b9JU_T6q4yxV85_TR7VEVr5ViRCFwk,1336
609
609
  omlish/text/minja.py,sha256=jZC-fp3Xuhx48ppqsf2Sf1pHbC0t8XBB7UpUUoOk2Qw,5751
610
610
  omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
611
611
  omlish/text/random.py,sha256=jNWpqiaKjKyTdMXC-pWAsSC10AAP-cmRRPVhm59ZWLk,194
612
- omlish-0.0.0.dev200.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
613
- omlish-0.0.0.dev200.dist-info/METADATA,sha256=ZStmAEKO4tvTAtBeGJDad2z_76jk0FY_eVEe6fcobNw,4264
614
- omlish-0.0.0.dev200.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
615
- omlish-0.0.0.dev200.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
616
- omlish-0.0.0.dev200.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
617
- omlish-0.0.0.dev200.dist-info/RECORD,,
612
+ omlish-0.0.0.dev201.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
613
+ omlish-0.0.0.dev201.dist-info/METADATA,sha256=_xm1Dh4zcl8xwhcC7IQ83_lZs18KGg7gufxEsCbfPHA,4264
614
+ omlish-0.0.0.dev201.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
615
+ omlish-0.0.0.dev201.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
616
+ omlish-0.0.0.dev201.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
617
+ omlish-0.0.0.dev201.dist-info/RECORD,,