omlish 0.0.0.dev84__py3-none-any.whl → 0.0.0.dev86__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omlish/__about__.py +2 -2
- omlish/formats/json/backends/default.py +4 -1
- omlish/formats/json/stream/lex.py +33 -17
- omlish/formats/xml.py +3 -3
- omlish/http/sse.py +3 -0
- omlish/marshal/__init__.py +5 -0
- omlish/marshal/polymorphism.py +80 -36
- omlish/marshal/unions.py +44 -1
- omlish/sql/queries/building.py +2 -0
- omlish/sql/queries/inserts.py +50 -0
- omlish/sql/queries/marshal.py +9 -0
- omlish/sql/queries/multi.py +1 -1
- omlish/sql/queries/rendering.py +25 -0
- {omlish-0.0.0.dev84.dist-info → omlish-0.0.0.dev86.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev84.dist-info → omlish-0.0.0.dev86.dist-info}/RECORD +19 -18
- {omlish-0.0.0.dev84.dist-info → omlish-0.0.0.dev86.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev84.dist-info → omlish-0.0.0.dev86.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev84.dist-info → omlish-0.0.0.dev86.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev84.dist-info → omlish-0.0.0.dev86.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
from .base import Backend
|
2
|
+
from .orjson import ORJSON_BACKEND
|
2
3
|
from .std import STD_BACKEND
|
3
4
|
from .ujson import UJSON_BACKEND
|
4
5
|
|
5
6
|
|
6
7
|
DEFAULT_BACKED: Backend
|
7
|
-
if
|
8
|
+
if ORJSON_BACKEND is not None:
|
9
|
+
DEFAULT_BACKED = ORJSON_BACKEND
|
10
|
+
elif UJSON_BACKEND is not None:
|
8
11
|
DEFAULT_BACKED = UJSON_BACKEND
|
9
12
|
else:
|
10
13
|
DEFAULT_BACKED = STD_BACKEND
|
@@ -52,14 +52,18 @@ SCALAR_VALUE_TYPES: tuple[type, ...] = tuple(
|
|
52
52
|
##
|
53
53
|
|
54
54
|
|
55
|
+
class Position(ta.NamedTuple):
|
56
|
+
ofs: int
|
57
|
+
line: int
|
58
|
+
col: int
|
59
|
+
|
60
|
+
|
55
61
|
class Token(ta.NamedTuple):
|
56
62
|
kind: TokenKind
|
57
63
|
value: ScalarValue
|
58
64
|
raw: str | None
|
59
65
|
|
60
|
-
|
61
|
-
line: int
|
62
|
-
col: int
|
66
|
+
pos: Position
|
63
67
|
|
64
68
|
def __iter__(self):
|
65
69
|
raise TypeError
|
@@ -94,9 +98,7 @@ CONST_TOKENS: ta.Mapping[str, tuple[TokenKind, str | float | None]] = {
|
|
94
98
|
class JsonLexError(Exception):
|
95
99
|
message: str
|
96
100
|
|
97
|
-
|
98
|
-
line: int
|
99
|
-
col: int
|
101
|
+
pos: Position
|
100
102
|
|
101
103
|
|
102
104
|
class JsonStreamLexer(GenMachine[str, Token]):
|
@@ -108,13 +110,21 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
108
110
|
self._include_raw = include_raw
|
109
111
|
|
110
112
|
self._ofs = 0
|
111
|
-
self._line =
|
113
|
+
self._line = 1
|
112
114
|
self._col = 0
|
113
115
|
|
114
116
|
self._buf = io.StringIO()
|
115
117
|
|
116
118
|
super().__init__(self._do_main())
|
117
119
|
|
120
|
+
@property
|
121
|
+
def pos(self) -> Position:
|
122
|
+
return Position(
|
123
|
+
self._ofs,
|
124
|
+
self._line,
|
125
|
+
self._col,
|
126
|
+
)
|
127
|
+
|
118
128
|
def _char_in(self, c: str) -> str:
|
119
129
|
if c and len(c) != 1:
|
120
130
|
raise ValueError(c)
|
@@ -134,14 +144,13 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
134
144
|
kind: TokenKind,
|
135
145
|
value: ScalarValue,
|
136
146
|
raw: str,
|
147
|
+
pos: Position,
|
137
148
|
) -> ta.Sequence[Token]:
|
138
149
|
tok = Token(
|
139
150
|
kind,
|
140
151
|
value,
|
141
152
|
raw if self._include_raw else None,
|
142
|
-
|
143
|
-
self._line,
|
144
|
-
self._col,
|
153
|
+
pos,
|
145
154
|
)
|
146
155
|
return (tok,)
|
147
156
|
|
@@ -152,7 +161,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
152
161
|
return raw
|
153
162
|
|
154
163
|
def _raise(self, msg: str) -> ta.NoReturn:
|
155
|
-
raise JsonLexError(msg, self.
|
164
|
+
raise JsonLexError(msg, self.pos)
|
156
165
|
|
157
166
|
def _do_main(self):
|
158
167
|
while True:
|
@@ -165,7 +174,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
165
174
|
continue
|
166
175
|
|
167
176
|
if c in CONTROL_TOKENS:
|
168
|
-
yield self._make_tok(CONTROL_TOKENS[c], c, c)
|
177
|
+
yield self._make_tok(CONTROL_TOKENS[c], c, c, self.pos)
|
169
178
|
continue
|
170
179
|
|
171
180
|
if c == '"':
|
@@ -180,8 +189,11 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
180
189
|
self._raise(f'Unexpected character: {c}')
|
181
190
|
|
182
191
|
def _do_string(self):
|
192
|
+
check.state(self._buf.tell() == 0)
|
183
193
|
self._buf.write('"')
|
184
194
|
|
195
|
+
pos = self.pos
|
196
|
+
|
185
197
|
last = None
|
186
198
|
while True:
|
187
199
|
try:
|
@@ -199,13 +211,16 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
199
211
|
|
200
212
|
raw = self._flip_buf()
|
201
213
|
sv = json.loads(raw)
|
202
|
-
yield self._make_tok('STRING', sv, raw)
|
214
|
+
yield self._make_tok('STRING', sv, raw, pos)
|
203
215
|
|
204
216
|
return self._do_main()
|
205
217
|
|
206
218
|
def _do_number(self, c: str):
|
219
|
+
check.state(self._buf.tell() == 0)
|
207
220
|
self._buf.write(c)
|
208
221
|
|
222
|
+
pos = self.pos
|
223
|
+
|
209
224
|
while True:
|
210
225
|
try:
|
211
226
|
c = self._char_in((yield None)) # noqa
|
@@ -240,7 +255,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
240
255
|
self._raise(f'Invalid number format: {raw}')
|
241
256
|
|
242
257
|
tk, tv = CONST_TOKENS[raw]
|
243
|
-
yield self._make_tok(tk, tv, raw)
|
258
|
+
yield self._make_tok(tk, tv, raw, pos)
|
244
259
|
|
245
260
|
return self._do_main()
|
246
261
|
|
@@ -250,7 +265,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
250
265
|
nv = float(raw)
|
251
266
|
else:
|
252
267
|
nv = int(raw)
|
253
|
-
yield self._make_tok('NUMBER', nv, raw)
|
268
|
+
yield self._make_tok('NUMBER', nv, raw, pos)
|
254
269
|
|
255
270
|
#
|
256
271
|
|
@@ -258,7 +273,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
258
273
|
return None
|
259
274
|
|
260
275
|
if c in CONTROL_TOKENS:
|
261
|
-
yield self._make_tok(CONTROL_TOKENS[c], c, c)
|
276
|
+
yield self._make_tok(CONTROL_TOKENS[c], c, c, pos)
|
262
277
|
|
263
278
|
elif not c.isspace():
|
264
279
|
self._raise(f'Unexpected character after number: {c}')
|
@@ -266,6 +281,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
266
281
|
return self._do_main()
|
267
282
|
|
268
283
|
def _do_const(self, c: str):
|
284
|
+
pos = self.pos
|
269
285
|
raw = c
|
270
286
|
while True:
|
271
287
|
try:
|
@@ -280,6 +296,6 @@ class JsonStreamLexer(GenMachine[str, Token]):
|
|
280
296
|
self._raise(f'Invalid literal: {raw}')
|
281
297
|
|
282
298
|
tk, tv = CONST_TOKENS[raw]
|
283
|
-
yield self._make_tok(tk, tv, raw)
|
299
|
+
yield self._make_tok(tk, tv, raw, pos)
|
284
300
|
|
285
301
|
return self._do_main()
|
omlish/formats/xml.py
CHANGED
@@ -21,13 +21,13 @@ else:
|
|
21
21
|
@dc.dataclass(frozen=True)
|
22
22
|
class SimpleElement:
|
23
23
|
tag: str
|
24
|
-
|
24
|
+
attrs: ta.Mapping[str, str] | None = dc.xfield(default=None, repr_fn=dc.truthy_repr)
|
25
25
|
body: ta.Sequence[ta.Union['SimpleElement', str]] | None = dc.xfield(default=None, repr_fn=dc.truthy_repr)
|
26
26
|
|
27
27
|
def as_dict(self) -> dict[str, ta.Any]:
|
28
28
|
dct: dict[str, ta.Any] = {'tag': self.tag}
|
29
|
-
if self.
|
30
|
-
dct['
|
29
|
+
if self.attrs:
|
30
|
+
dct['attrs'] = self.attrs
|
31
31
|
if self.body:
|
32
32
|
dct['body'] = [
|
33
33
|
c.as_dict() if isinstance(c, SimpleElement) else c
|
omlish/http/sse.py
CHANGED
omlish/marshal/__init__.py
CHANGED
@@ -77,9 +77,12 @@ from .objects import ( # noqa
|
|
77
77
|
|
78
78
|
from .polymorphism import ( # noqa
|
79
79
|
Impl,
|
80
|
+
Impls,
|
80
81
|
Polymorphism,
|
81
82
|
PolymorphismMarshalerFactory,
|
82
83
|
PolymorphismUnmarshalerFactory,
|
84
|
+
make_polymorphism_marshaler,
|
85
|
+
make_polymorphism_unmarshaler,
|
83
86
|
polymorphism_from_subclasses,
|
84
87
|
)
|
85
88
|
|
@@ -101,6 +104,8 @@ from .standard import ( # noqa
|
|
101
104
|
|
102
105
|
from .unions import ( # noqa
|
103
106
|
PRIMITIVE_UNION_TYPES,
|
107
|
+
PolymorphismUnionMarshalerFactory,
|
108
|
+
PolymorphismUnionUnmarshalerFactory,
|
104
109
|
PrimitiveUnionMarshaler,
|
105
110
|
PrimitiveUnionMarshalerFactory,
|
106
111
|
PrimitiveUnionUnmarshaler,
|
omlish/marshal/polymorphism.py
CHANGED
@@ -50,21 +50,19 @@ class Impl:
|
|
50
50
|
alts: ta.AbstractSet[str] = frozenset()
|
51
51
|
|
52
52
|
|
53
|
-
class
|
53
|
+
class Impls(ta.Sequence[Impl]):
|
54
54
|
def __init__(
|
55
55
|
self,
|
56
|
-
|
57
|
-
impls: ta.Iterable[Impl],
|
56
|
+
lst: ta.Iterable[Impl],
|
58
57
|
) -> None:
|
59
58
|
super().__init__()
|
60
|
-
self.
|
61
|
-
self._impls = list(impls)
|
59
|
+
self._lst = list(lst)
|
62
60
|
|
63
61
|
by_ty: dict[type, Impl] = {}
|
64
62
|
by_tag: dict[str, Impl] = {}
|
65
|
-
for i in self.
|
66
|
-
if
|
67
|
-
raise TypeError(i.ty
|
63
|
+
for i in self._lst:
|
64
|
+
if i.ty in by_ty:
|
65
|
+
raise TypeError(i.ty)
|
68
66
|
if i.tag in by_tag:
|
69
67
|
raise NameError(i.tag)
|
70
68
|
for a in i.alts:
|
@@ -77,13 +75,20 @@ class Polymorphism:
|
|
77
75
|
self._by_ty = by_ty
|
78
76
|
self._by_tag = by_tag
|
79
77
|
|
80
|
-
|
81
|
-
|
82
|
-
return self._ty
|
78
|
+
def __iter__(self) -> ta.Iterator[Impl]:
|
79
|
+
return iter(self._lst)
|
83
80
|
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
def __len__(self) -> int:
|
82
|
+
return len(self._lst)
|
83
|
+
|
84
|
+
@ta.overload
|
85
|
+
def __getitem__(self, index: int) -> Impl: ...
|
86
|
+
|
87
|
+
@ta.overload
|
88
|
+
def __getitem__(self, index: slice) -> ta.Sequence[Impl]: ...
|
89
|
+
|
90
|
+
def __getitem__(self, index):
|
91
|
+
return self._lst[index]
|
87
92
|
|
88
93
|
@property
|
89
94
|
def by_ty(self) -> ta.Mapping[type, Impl]:
|
@@ -94,6 +99,29 @@ class Polymorphism:
|
|
94
99
|
return self._by_tag
|
95
100
|
|
96
101
|
|
102
|
+
class Polymorphism:
|
103
|
+
def __init__(
|
104
|
+
self,
|
105
|
+
ty: type,
|
106
|
+
impls: ta.Iterable[Impl],
|
107
|
+
) -> None:
|
108
|
+
super().__init__()
|
109
|
+
self._ty = ty
|
110
|
+
self._impls = Impls(impls)
|
111
|
+
|
112
|
+
for i in self._impls:
|
113
|
+
if not issubclass(i.ty, ty):
|
114
|
+
raise TypeError(i.ty, ty)
|
115
|
+
|
116
|
+
@property
|
117
|
+
def ty(self) -> type:
|
118
|
+
return self._ty
|
119
|
+
|
120
|
+
@property
|
121
|
+
def impls(self) -> Impls:
|
122
|
+
return self._impls
|
123
|
+
|
124
|
+
|
97
125
|
def polymorphism_from_subclasses(
|
98
126
|
ty: type,
|
99
127
|
*,
|
@@ -151,6 +179,23 @@ class FieldPolymorphismMarshaler(Marshaler):
|
|
151
179
|
return {self.tf: tag, **m.marshal(ctx, o)} # type: ignore
|
152
180
|
|
153
181
|
|
182
|
+
def make_polymorphism_marshaler(
|
183
|
+
impls: Impls,
|
184
|
+
tt: TypeTagging,
|
185
|
+
ctx: MarshalContext,
|
186
|
+
) -> Marshaler:
|
187
|
+
m = {
|
188
|
+
i.ty: (i.tag, ctx.make(i.ty))
|
189
|
+
for i in impls
|
190
|
+
}
|
191
|
+
if isinstance(tt, WrapperTypeTagging):
|
192
|
+
return WrapperPolymorphismMarshaler(m)
|
193
|
+
elif isinstance(tt, FieldTypeTagging):
|
194
|
+
return FieldPolymorphismMarshaler(m, tt.field)
|
195
|
+
else:
|
196
|
+
raise TypeError(tt)
|
197
|
+
|
198
|
+
|
154
199
|
@dc.dataclass(frozen=True)
|
155
200
|
class PolymorphismMarshalerFactory(MarshalerFactory):
|
156
201
|
p: Polymorphism
|
@@ -161,16 +206,7 @@ class PolymorphismMarshalerFactory(MarshalerFactory):
|
|
161
206
|
|
162
207
|
def fn(self, ctx: MarshalContext, rty: rfl.Type) -> Marshaler:
|
163
208
|
check.is_(rty, self.p.ty)
|
164
|
-
|
165
|
-
i.ty: (i.tag, ctx.make(i.ty))
|
166
|
-
for i in self.p.impls
|
167
|
-
}
|
168
|
-
if isinstance(self.tt, WrapperTypeTagging):
|
169
|
-
return WrapperPolymorphismMarshaler(m)
|
170
|
-
elif isinstance(self.tt, FieldTypeTagging):
|
171
|
-
return FieldPolymorphismMarshaler(m, self.tt.field)
|
172
|
-
else:
|
173
|
-
raise TypeError(self.tt)
|
209
|
+
return make_polymorphism_marshaler(self.p.impls, self.tt, ctx)
|
174
210
|
|
175
211
|
|
176
212
|
##
|
@@ -199,6 +235,25 @@ class FieldPolymorphismUnmarshaler(Unmarshaler):
|
|
199
235
|
return u.unmarshal(ctx, ma)
|
200
236
|
|
201
237
|
|
238
|
+
def make_polymorphism_unmarshaler(
|
239
|
+
impls: Impls,
|
240
|
+
tt: TypeTagging,
|
241
|
+
ctx: UnmarshalContext,
|
242
|
+
) -> Unmarshaler:
|
243
|
+
m = {
|
244
|
+
t: u
|
245
|
+
for i in impls
|
246
|
+
for u in [ctx.make(i.ty)]
|
247
|
+
for t in [i.tag, *i.alts]
|
248
|
+
}
|
249
|
+
if isinstance(tt, WrapperTypeTagging):
|
250
|
+
return WrapperPolymorphismUnmarshaler(m)
|
251
|
+
elif isinstance(tt, FieldTypeTagging):
|
252
|
+
return FieldPolymorphismUnmarshaler(m, tt.field)
|
253
|
+
else:
|
254
|
+
raise TypeError(tt)
|
255
|
+
|
256
|
+
|
202
257
|
@dc.dataclass(frozen=True)
|
203
258
|
class PolymorphismUnmarshalerFactory(UnmarshalerFactory):
|
204
259
|
p: Polymorphism
|
@@ -209,15 +264,4 @@ class PolymorphismUnmarshalerFactory(UnmarshalerFactory):
|
|
209
264
|
|
210
265
|
def fn(self, ctx: UnmarshalContext, rty: rfl.Type) -> Unmarshaler:
|
211
266
|
check.is_(rty, self.p.ty)
|
212
|
-
|
213
|
-
t: u
|
214
|
-
for i in self.p.impls
|
215
|
-
for u in [ctx.make(i.ty)]
|
216
|
-
for t in [i.tag, *i.alts]
|
217
|
-
}
|
218
|
-
if isinstance(self.tt, WrapperTypeTagging):
|
219
|
-
return WrapperPolymorphismUnmarshaler(m)
|
220
|
-
elif isinstance(self.tt, FieldTypeTagging):
|
221
|
-
return FieldPolymorphismUnmarshaler(m, self.tt.field)
|
222
|
-
else:
|
223
|
-
raise TypeError(self.tt)
|
267
|
+
return make_polymorphism_unmarshaler(self.p.impls, self.tt, ctx)
|
omlish/marshal/unions.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
import dataclasses as dc
|
2
1
|
import typing as ta
|
3
2
|
|
3
|
+
from .. import cached
|
4
4
|
from .. import check
|
5
|
+
from .. import dataclasses as dc
|
5
6
|
from .. import matchfns as mfs
|
6
7
|
from .. import reflect as rfl
|
7
8
|
from .base import MarshalContext
|
@@ -10,6 +11,11 @@ from .base import MarshalerFactory
|
|
10
11
|
from .base import UnmarshalContext
|
11
12
|
from .base import Unmarshaler
|
12
13
|
from .base import UnmarshalerFactory
|
14
|
+
from .polymorphism import Impls
|
15
|
+
from .polymorphism import TypeTagging
|
16
|
+
from .polymorphism import WrapperTypeTagging
|
17
|
+
from .polymorphism import make_polymorphism_marshaler
|
18
|
+
from .polymorphism import make_polymorphism_unmarshaler
|
13
19
|
from .values import Value
|
14
20
|
|
15
21
|
|
@@ -103,3 +109,40 @@ class PrimitiveUnionUnmarshalerFactory(UnmarshalerFactory):
|
|
103
109
|
|
104
110
|
PRIMITIVE_UNION_MARSHALER_FACTORY = PrimitiveUnionMarshalerFactory()
|
105
111
|
PRIMITIVE_UNION_UNMARSHALER_FACTORY = PrimitiveUnionUnmarshalerFactory()
|
112
|
+
|
113
|
+
|
114
|
+
##
|
115
|
+
|
116
|
+
|
117
|
+
@dc.dataclass(frozen=True)
|
118
|
+
class PolymorphismUnionMarshalerFactory(MarshalerFactory):
|
119
|
+
impls: Impls
|
120
|
+
tt: TypeTagging = WrapperTypeTagging()
|
121
|
+
|
122
|
+
@cached.property
|
123
|
+
@dc.init
|
124
|
+
def rty(self) -> rfl.Union:
|
125
|
+
return rfl.type_(ta.Union[*tuple(i.ty for i in self.impls)]) # type: ignore
|
126
|
+
|
127
|
+
def guard(self, ctx: MarshalContext, rty: rfl.Type) -> bool:
|
128
|
+
return isinstance(rty, rfl.Union) and rty == self.rty
|
129
|
+
|
130
|
+
def fn(self, ctx: MarshalContext, rty: rfl.Type) -> Marshaler:
|
131
|
+
return make_polymorphism_marshaler(self.impls, self.tt, ctx)
|
132
|
+
|
133
|
+
|
134
|
+
@dc.dataclass(frozen=True)
|
135
|
+
class PolymorphismUnionUnmarshalerFactory(UnmarshalerFactory):
|
136
|
+
impls: Impls
|
137
|
+
tt: TypeTagging = WrapperTypeTagging()
|
138
|
+
|
139
|
+
@cached.property
|
140
|
+
@dc.init
|
141
|
+
def rty(self) -> rfl.Union:
|
142
|
+
return rfl.type_(ta.Union[*tuple(i.ty for i in self.impls)]) # type: ignore
|
143
|
+
|
144
|
+
def guard(self, ctx: UnmarshalContext, rty: rfl.Type) -> bool:
|
145
|
+
return isinstance(rty, rfl.Union) and rty == self.rty
|
146
|
+
|
147
|
+
def fn(self, ctx: UnmarshalContext, rty: rfl.Type) -> Unmarshaler:
|
148
|
+
return make_polymorphism_unmarshaler(self.impls, self.tt, ctx)
|
omlish/sql/queries/building.py
CHANGED
@@ -2,6 +2,7 @@ from .base import Builder
|
|
2
2
|
from .binary import BinaryBuilder
|
3
3
|
from .exprs import ExprBuilder
|
4
4
|
from .idents import IdentBuilder
|
5
|
+
from .inserts import InsertBuilder
|
5
6
|
from .multi import MultiBuilder
|
6
7
|
from .names import NameBuilder
|
7
8
|
from .relations import RelationBuilder
|
@@ -11,6 +12,7 @@ from .unary import UnaryBuilder
|
|
11
12
|
|
12
13
|
|
13
14
|
class StdBuilder(
|
15
|
+
InsertBuilder,
|
14
16
|
SelectBuilder,
|
15
17
|
StmtBuilder,
|
16
18
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import typing as ta
|
2
|
+
|
3
|
+
from ... import dataclasses as dc
|
4
|
+
from ... import lang
|
5
|
+
from .exprs import CanExpr
|
6
|
+
from .exprs import Expr
|
7
|
+
from .exprs import ExprBuilder
|
8
|
+
from .idents import CanIdent
|
9
|
+
from .idents import Ident
|
10
|
+
from .relations import CanRelation
|
11
|
+
from .relations import Relation
|
12
|
+
from .relations import RelationBuilder
|
13
|
+
from .selects import Select
|
14
|
+
from .stmts import Stmt
|
15
|
+
|
16
|
+
|
17
|
+
##
|
18
|
+
|
19
|
+
|
20
|
+
class Values(dc.Frozen, lang.Final):
|
21
|
+
vs: ta.Sequence[Expr]
|
22
|
+
|
23
|
+
|
24
|
+
class Insert(Stmt, lang.Final):
|
25
|
+
columns: ta.Sequence[Ident]
|
26
|
+
into: Relation
|
27
|
+
data: Values | Select
|
28
|
+
|
29
|
+
|
30
|
+
CanValues: ta.TypeAlias = Values | ta.Sequence[CanExpr]
|
31
|
+
|
32
|
+
|
33
|
+
class InsertBuilder(ExprBuilder, RelationBuilder):
|
34
|
+
def values(self, vs: CanValues) -> Values:
|
35
|
+
if isinstance(vs, Values):
|
36
|
+
return vs
|
37
|
+
else:
|
38
|
+
return Values(tuple(self.expr(v) for v in vs))
|
39
|
+
|
40
|
+
def insert(
|
41
|
+
self,
|
42
|
+
columns: ta.Sequence[CanIdent],
|
43
|
+
into: CanRelation,
|
44
|
+
data: Select | Values | ta.Sequence[CanExpr],
|
45
|
+
) -> Insert:
|
46
|
+
return Insert(
|
47
|
+
columns=tuple(self.ident(c) for c in columns),
|
48
|
+
into=self.relation(into),
|
49
|
+
data=data if isinstance(data, Select) else self.values(data),
|
50
|
+
)
|
omlish/sql/queries/marshal.py
CHANGED
@@ -11,8 +11,10 @@ from .base import Node
|
|
11
11
|
from .binary import BinaryOp
|
12
12
|
from .binary import BinaryOps
|
13
13
|
from .exprs import Expr
|
14
|
+
from .inserts import Values
|
14
15
|
from .multi import MultiKind
|
15
16
|
from .relations import Relation
|
17
|
+
from .selects import Select
|
16
18
|
from .stmts import Stmt
|
17
19
|
from .unary import UnaryOp
|
18
20
|
from .unary import UnaryOps
|
@@ -72,3 +74,10 @@ def _install_standard_marshalling() -> None:
|
|
72
74
|
p = msh.polymorphism_from_subclasses(cls, naming=msh.Naming.SNAKE)
|
73
75
|
msh.STANDARD_MARSHALER_FACTORIES[0:0] = [msh.PolymorphismMarshalerFactory(p)]
|
74
76
|
msh.STANDARD_UNMARSHALER_FACTORIES[0:0] = [msh.PolymorphismUnmarshalerFactory(p)]
|
77
|
+
|
78
|
+
insert_data_impls = msh.Impls([
|
79
|
+
msh.Impl(Values, 'values'),
|
80
|
+
msh.Impl(Select, 'select'),
|
81
|
+
])
|
82
|
+
msh.STANDARD_MARSHALER_FACTORIES[0:0] = [msh.PolymorphismUnionMarshalerFactory(insert_data_impls)]
|
83
|
+
msh.STANDARD_UNMARSHALER_FACTORIES[0:0] = [msh.PolymorphismUnionUnmarshalerFactory(insert_data_impls)]
|
omlish/sql/queries/multi.py
CHANGED
@@ -28,7 +28,7 @@ class MultiBuilder(ExprBuilder):
|
|
28
28
|
if len(es) == 1:
|
29
29
|
return self.expr(es[0])
|
30
30
|
else:
|
31
|
-
return Multi(k,
|
31
|
+
return Multi(k, tuple(self.expr(e) for e in es))
|
32
32
|
|
33
33
|
def and_(self, *es: CanExpr) -> Expr:
|
34
34
|
return self.multi(MultiKind.AND, *es)
|
omlish/sql/queries/rendering.py
CHANGED
@@ -27,6 +27,8 @@ from .binary import BinaryOps
|
|
27
27
|
from .exprs import Literal
|
28
28
|
from .exprs import NameExpr
|
29
29
|
from .idents import Ident
|
30
|
+
from .inserts import Insert
|
31
|
+
from .inserts import Values
|
30
32
|
from .multi import Multi
|
31
33
|
from .multi import MultiKind
|
32
34
|
from .names import Name
|
@@ -98,6 +100,29 @@ class StdRenderer(Renderer):
|
|
98
100
|
def render_ident(self, o: Ident) -> None:
|
99
101
|
self._out.write(f'"{o.s}"')
|
100
102
|
|
103
|
+
# inserts
|
104
|
+
|
105
|
+
@Renderer.render.register
|
106
|
+
def render_values(self, o: Values) -> None:
|
107
|
+
self._out.write('values (')
|
108
|
+
for i, v in enumerate(o.vs):
|
109
|
+
if i:
|
110
|
+
self._out.write(', ')
|
111
|
+
self.render(v)
|
112
|
+
self._out.write(')')
|
113
|
+
|
114
|
+
@Renderer.render.register
|
115
|
+
def render_insert(self, o: Insert) -> None:
|
116
|
+
self._out.write('insert into ')
|
117
|
+
self.render(o.into)
|
118
|
+
self._out.write(' (')
|
119
|
+
for i, c in enumerate(o.columns):
|
120
|
+
if i:
|
121
|
+
self._out.write(', ')
|
122
|
+
self.render(c)
|
123
|
+
self._out.write(') ')
|
124
|
+
self.render(o.data)
|
125
|
+
|
101
126
|
# multis
|
102
127
|
|
103
128
|
MULTI_KIND_TO_STR: ta.ClassVar[ta.Mapping[MultiKind, str]] = {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.manifests.json,sha256=hTFp9tvE72BxKloIq1s1SS0LRQlIsvMtO69Sbc47rKg,1704
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=bmf1Xnu5T4--9ykGD63NIvhEZE9Fhk9w3IlmwLH40vU,3345
|
3
3
|
omlish/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
omlish/argparse.py,sha256=Dc73G8lyoQBLvXhMYUbzQUh4SJu_OTvKUXjSUxq_ang,7499
|
5
5
|
omlish/c3.py,sha256=4vogWgwPb8TbNS2KkZxpoWbwjj7MuHG2lQG-hdtkvjI,8062
|
@@ -181,7 +181,7 @@ omlish/docker/manifests.py,sha256=LR4FpOGNUT3bZQ-gTjB6r_-1C3YiG30QvevZjrsVUQM,70
|
|
181
181
|
omlish/formats/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
182
182
|
omlish/formats/dotenv.py,sha256=UjZl3gac-0U24sDjCCGMcCqO1UCWG2Zs8PZ4JdAg2YE,17348
|
183
183
|
omlish/formats/props.py,sha256=JwFJbKblqzqnzXf7YKFzQSDfcAXzkKsfoYvad6FPy98,18945
|
184
|
-
omlish/formats/xml.py,sha256=
|
184
|
+
omlish/formats/xml.py,sha256=ggiOwSERt4d9XmZwLZiDIh5qnFJS4jdmow9m9_9USps,1491
|
185
185
|
omlish/formats/yaml.py,sha256=wTW8ECG9jyA7qIFUqKZUro4KAKpN4IvcW_qhlrKveXM,6836
|
186
186
|
omlish/formats/json/__init__.py,sha256=xqW2APLGvCTO9dVTOlroR_AdrA5bCkdmUnbTkYHhJ7U,379
|
187
187
|
omlish/formats/json/consts.py,sha256=u-x-qXqZvK0tWk3l3TrCTjk4mSjKmZ_ATdmd1hwHNAY,263
|
@@ -190,7 +190,7 @@ omlish/formats/json/json.py,sha256=Mdqv2vdMi7gp96eV0BIYH5UdWpjWfsh-tSMZeywG-08,3
|
|
190
190
|
omlish/formats/json/render.py,sha256=H6q1R3gL6ULAnfEhQRKDOzDJjWizdsRDYxIerBSEbq8,3797
|
191
191
|
omlish/formats/json/backends/__init__.py,sha256=gnaNDCxy_KmmPUPDnjxO5_WjuWxLGbI9FYWx8ZJuQUU,97
|
192
192
|
omlish/formats/json/backends/base.py,sha256=WqtyoM82pyM0NyqpPwndrebr1bUVU1QlpmVQNrcAO8c,1114
|
193
|
-
omlish/formats/json/backends/default.py,sha256=
|
193
|
+
omlish/formats/json/backends/default.py,sha256=a-eM-Y1IHdpYvZFjazwq_orRncjtYR7BKxP_2kpEXog,322
|
194
194
|
omlish/formats/json/backends/jiter.py,sha256=8qv_XWGpcupPtVm6Z_egHio_iY1Kk8eqkvXTF6fVZr4,1193
|
195
195
|
omlish/formats/json/backends/orjson.py,sha256=wR8pMGFtkhZGHcNVk7vNYUnv8lUapdK89p6QpETIs9w,3778
|
196
196
|
omlish/formats/json/backends/std.py,sha256=PM00Kh9ZR2XzollHMEvdo35Eml1N-zFfRW-LOCV5ftM,3085
|
@@ -201,7 +201,7 @@ omlish/formats/json/cli/cli.py,sha256=GkdNokklRuDWiXAIai1wijSBFVJlpdlNLTQ3Lyucos
|
|
201
201
|
omlish/formats/json/cli/formats.py,sha256=tqEZKby4HeafGcaUs-m8B-2ZV12dRo40rzL-V99cp00,1714
|
202
202
|
omlish/formats/json/stream/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
203
203
|
omlish/formats/json/stream/build.py,sha256=6deXBxTx1toFAPShz2Jo5OiXxH5Y4ppG8gDPRFoUgjA,2461
|
204
|
-
omlish/formats/json/stream/lex.py,sha256=
|
204
|
+
omlish/formats/json/stream/lex.py,sha256=01K_M9na7-3xv0h3VDBobLXuTS-w4YesNJ6GhOaDtYA,6494
|
205
205
|
omlish/formats/json/stream/parse.py,sha256=WkbW7tvcdrTSluKhw70nPvjsq943eryVcjx8FSz78tM,5198
|
206
206
|
omlish/formats/json/stream/render.py,sha256=B9ZNuBiDJOT25prhIsZu1ICKjxk4eMPwpgQF37NPufs,3212
|
207
207
|
omlish/graphs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -224,7 +224,7 @@ omlish/http/headers.py,sha256=ZMmjrEiYjzo0YTGyK0YsvjdwUazktGqzVVYorY4fd44,5081
|
|
224
224
|
omlish/http/json.py,sha256=9XwAsl4966Mxrv-1ytyCqhcE6lbBJw-0_tFZzGszgHE,7440
|
225
225
|
omlish/http/multipart.py,sha256=R9ycpHsXRcmh0uoc43aYb7BdWL-8kSQHe7J-M81aQZM,2240
|
226
226
|
omlish/http/sessions.py,sha256=VZ_WS5uiQG5y7i3u8oKuQMqf8dPKUOjFm_qk_0OvI8c,4793
|
227
|
-
omlish/http/sse.py,sha256=
|
227
|
+
omlish/http/sse.py,sha256=MDs9RvxQXoQliImcc6qK1ERajEYM7Q1l8xmr-9ceNBc,2315
|
228
228
|
omlish/http/wsgi.py,sha256=czZsVUX-l2YTlMrUjKN49wRoP4rVpS0qpeBn4O5BoMY,948
|
229
229
|
omlish/inject/__init__.py,sha256=JQ7x8l9MjU-kJ5ap7cPVq7SY7zbbCIrjyJAF0UeE5-s,1886
|
230
230
|
omlish/inject/binder.py,sha256=H8AQ4ecmBOtDL8fMgrU1yUJl1gBADLNcdysRbvO8Wso,4167
|
@@ -308,7 +308,7 @@ omlish/logs/formatters.py,sha256=q79nMnR2mRIStPyGrydQHpYTXgC5HHptt8lH3W2Wwbs,671
|
|
308
308
|
omlish/logs/handlers.py,sha256=nyuFgmO05By_Xwq7es58ClzS51-F53lJL7gD0x5IqAg,228
|
309
309
|
omlish/logs/noisy.py,sha256=Ubc-eTH6ZbGYsLfUUi69JAotwuUwzb-SJBeGo_0dIZI,348
|
310
310
|
omlish/logs/utils.py,sha256=MgGovbP0zUrZ3FGD3qYNQWn-l0jy0Y0bStcQvv5BOmQ,391
|
311
|
-
omlish/marshal/__init__.py,sha256=
|
311
|
+
omlish/marshal/__init__.py,sha256=iVA7n31L08Bdub6HKPvYOXVvDhk2CMA6rPeKDL_u1to,2298
|
312
312
|
omlish/marshal/any.py,sha256=e82OyYK3Emm1P1ClnsnxP7fIWC2iNVyW0H5nK4mLmWM,779
|
313
313
|
omlish/marshal/base.py,sha256=7ZpJOMPlvtslhDdRlNZCC5MiUGu7Qfoq_S_miD0lmQY,6738
|
314
314
|
omlish/marshal/base64.py,sha256=F-3ogJdcFCtWINRgJgWT0rErqgx6f4qahhcg8OrkqhE,1089
|
@@ -329,11 +329,11 @@ omlish/marshal/nop.py,sha256=2mWve_dicFAiUQ2Y5asKkUW-XGmEE9Qi2ClIasFad0c,461
|
|
329
329
|
omlish/marshal/numbers.py,sha256=kFRIX9l1yofiYzafV6SnYfEg0PiCsAqeRHOeT6BSxlM,1672
|
330
330
|
omlish/marshal/objects.py,sha256=74tUmMymimSqgd4a6kyMh_owJe6J7YQXwCXEF-JWt1c,8419
|
331
331
|
omlish/marshal/optionals.py,sha256=r0XB5rqfasvgZJNrKYd6Unq2U4nHt3JURi26j0dYHlw,1499
|
332
|
-
omlish/marshal/polymorphism.py,sha256=
|
332
|
+
omlish/marshal/polymorphism.py,sha256=2SxrfneA9QdhNdxieEGFnHDHpUo3ftETA9dMbCbmbWY,6511
|
333
333
|
omlish/marshal/primitives.py,sha256=f_6m24Cb-FDGsZpYSas11nLt3xCCEUXugw3Hv4-aNhg,1291
|
334
334
|
omlish/marshal/registries.py,sha256=FvC6qXHCizNB2QmU_N3orxW7iqfGYkiUXYYdTRWS6HA,2353
|
335
335
|
omlish/marshal/standard.py,sha256=vcC17ZZW33lRki7jrRd-saHGUZcXEHOpbPNGxWWbLWI,3143
|
336
|
-
omlish/marshal/unions.py,sha256=
|
336
|
+
omlish/marshal/unions.py,sha256=DSs_g0F6EiefCturQPWv70VUAmsZgqEU9flmgxpxm7o,4137
|
337
337
|
omlish/marshal/utils.py,sha256=puKJpwPpuDlMOIrKMcLTRLJyMiL6n_Xs-p59AuDEymA,543
|
338
338
|
omlish/marshal/uuids.py,sha256=H4B7UX_EPNmP2tC8bubcKrPLTS4aQu98huvbXQ3Zv2g,910
|
339
339
|
omlish/marshal/values.py,sha256=ssHiWdg_L6M17kAn8GiGdPW7UeQOm3RDikWkvwblf5I,263
|
@@ -408,15 +408,16 @@ omlish/sql/alchemy/sqlean.py,sha256=RbkuOuFIfM4fowwKk8-sQ6Dxk-tTUwxS94nY5Kxt52s,
|
|
408
408
|
omlish/sql/queries/__init__.py,sha256=BdhONMw2JebX-jEgYb1WrM5L3vkJOzQRm0nt04IYKgQ,1229
|
409
409
|
omlish/sql/queries/base.py,sha256=_8O3MbH_OEjBnhp2oIJUZ3ClaQ8l4Sj9BdPdsP0Ie-g,224
|
410
410
|
omlish/sql/queries/binary.py,sha256=dcEzeEn104AMPuQ7QrJU2O-YCN3SUdxB5S4jaWKOUqY,2253
|
411
|
-
omlish/sql/queries/building.py,sha256=
|
411
|
+
omlish/sql/queries/building.py,sha256=dIQyEqNef2egKAf5qO_aZvXxlAEfxIGWS23qvJ-ozqQ,591
|
412
412
|
omlish/sql/queries/exprs.py,sha256=kAI5PmvfJ-TqEzzc9H4_womFShT1eA0jWSZH2j2Wg-c,1802
|
413
413
|
omlish/sql/queries/idents.py,sha256=erW6fE9UapuvW1ZeLfGFz7yuW6zzktWIWmOuAHeF8_g,496
|
414
|
-
omlish/sql/queries/
|
415
|
-
omlish/sql/queries/
|
414
|
+
omlish/sql/queries/inserts.py,sha256=PS3oqGjDgnjUd4sxHVpfKDQnsjG4_6KTseRzWyiJQl0,1229
|
415
|
+
omlish/sql/queries/marshal.py,sha256=Q-N6RcBzpj3FIa2-7eX6dniLjXKzUhRC9g--61UQUbM,2890
|
416
|
+
omlish/sql/queries/multi.py,sha256=7x6x-4jnPzxA6ZasBjnjFuhHFpWt5rGCua3UvuTMIJ0,837
|
416
417
|
omlish/sql/queries/names.py,sha256=YiIyS6ehYMYrdLlUxMawV_Xf2zdi7RwVO9Qsxr_W4_4,772
|
417
418
|
omlish/sql/queries/ops.py,sha256=B7IDfjr2DW5LJhWoNaY1WW90BJhe5ZtmxIELhWXbW-0,129
|
418
419
|
omlish/sql/queries/relations.py,sha256=-d3n-dN17c3TPMZmzSplhWawllUzdq12XPDAuzoeMEQ,838
|
419
|
-
omlish/sql/queries/rendering.py,sha256=
|
420
|
+
omlish/sql/queries/rendering.py,sha256=vpZY6rAjX5MZl72Tk6_tle3CUPi6U28sN4PcQ7aZ1iI,5055
|
420
421
|
omlish/sql/queries/selects.py,sha256=EcHlyKl5kGSY1d3GVxnImhGCTB6WvwQnlSA9eZanBqU,1364
|
421
422
|
omlish/sql/queries/stmts.py,sha256=pBqwD7dRlqMu6uh6vR3xaWOEgbZCcFWbOQ9ryYd17T4,441
|
422
423
|
omlish/sql/queries/unary.py,sha256=MEYBDZn_H0bexmUrJeONOv5-gIpYowUaXOsEHeQM4ks,1144
|
@@ -453,9 +454,9 @@ omlish/text/delimit.py,sha256=ubPXcXQmtbOVrUsNh5gH1mDq5H-n1y2R4cPL5_DQf68,4928
|
|
453
454
|
omlish/text/glyphsplit.py,sha256=Ug-dPRO7x-OrNNr8g1y6DotSZ2KH0S-VcOmUobwa4B0,3296
|
454
455
|
omlish/text/indent.py,sha256=6Jj6TFY9unaPa4xPzrnZemJ-fHsV53IamP93XGjSUHs,1274
|
455
456
|
omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
|
456
|
-
omlish-0.0.0.
|
457
|
-
omlish-0.0.0.
|
458
|
-
omlish-0.0.0.
|
459
|
-
omlish-0.0.0.
|
460
|
-
omlish-0.0.0.
|
461
|
-
omlish-0.0.0.
|
457
|
+
omlish-0.0.0.dev86.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
458
|
+
omlish-0.0.0.dev86.dist-info/METADATA,sha256=w6dXN4XU0iMfkJxV1fEHQ96o_V5idhf7cy3GApDwdAc,3987
|
459
|
+
omlish-0.0.0.dev86.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
460
|
+
omlish-0.0.0.dev86.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
461
|
+
omlish-0.0.0.dev86.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
462
|
+
omlish-0.0.0.dev86.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|