sql-blocks 1.25.1801__py3-none-any.whl → 1.25.19011745__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.
- sql_blocks/sql_blocks.py +23 -14
- {sql_blocks-1.25.1801.dist-info → sql_blocks-1.25.19011745.dist-info}/METADATA +1 -1
- sql_blocks-1.25.19011745.dist-info/RECORD +7 -0
- sql_blocks-1.25.1801.dist-info/RECORD +0 -7
- {sql_blocks-1.25.1801.dist-info → sql_blocks-1.25.19011745.dist-info}/LICENSE +0 -0
- {sql_blocks-1.25.1801.dist-info → sql_blocks-1.25.19011745.dist-info}/WHEEL +0 -0
- {sql_blocks-1.25.1801.dist-info → sql_blocks-1.25.19011745.dist-info}/top_level.txt +0 -0
sql_blocks/sql_blocks.py
CHANGED
@@ -335,6 +335,9 @@ class Cast(Function):
|
|
335
335
|
...
|
336
336
|
|
337
337
|
|
338
|
+
FUNCTION_CLASS = {f.__name__.lower(): f for f in Function.__subclasses__()}
|
339
|
+
|
340
|
+
|
338
341
|
class ExpressionField:
|
339
342
|
def __init__(self, expr: str):
|
340
343
|
self.expr = expr
|
@@ -468,8 +471,18 @@ class Where:
|
|
468
471
|
return cls(f'IN ({values})')
|
469
472
|
|
470
473
|
def add(self, name: str, main: SQLObject):
|
474
|
+
func_type = FUNCTION_CLASS.get(name.lower())
|
475
|
+
exists = any(
|
476
|
+
main.is_named_field(fld, SELECT)
|
477
|
+
for fld in main.values.get(SELECT, [])
|
478
|
+
if name in fld
|
479
|
+
)
|
480
|
+
if func_type:
|
481
|
+
name = func_type.format('*', main)
|
482
|
+
elif not exists:
|
483
|
+
name = Field.format(name, main)
|
471
484
|
main.values.setdefault(WHERE, []).append('{}{} {}'.format(
|
472
|
-
self.prefix,
|
485
|
+
self.prefix, name, self.expr
|
473
486
|
))
|
474
487
|
|
475
488
|
|
@@ -549,7 +562,6 @@ class Clause:
|
|
549
562
|
def format(cls, name: str, main: SQLObject) -> str:
|
550
563
|
def is_function() -> bool:
|
551
564
|
diff = main.diff(SELECT, [name.lower()], True)
|
552
|
-
FUNCTION_CLASS = {f.__name__.lower(): f for f in Function.__subclasses__()}
|
553
565
|
return diff.intersection(FUNCTION_CLASS)
|
554
566
|
found = re.findall(r'^_\d', name)
|
555
567
|
if found:
|
@@ -1068,7 +1080,6 @@ class CypherParser(Parser):
|
|
1068
1080
|
Count().As(token, extra_classes).add(pk_field, self.queries[-1])
|
1069
1081
|
return
|
1070
1082
|
else:
|
1071
|
-
FUNCTION_CLASS = {f.__name__.lower(): f for f in Function.__subclasses__()}
|
1072
1083
|
class_list = [ FUNCTION_CLASS[func_name] ]
|
1073
1084
|
class_list += extra_classes
|
1074
1085
|
FieldList(token, class_list).add('', self.queries[-1])
|
@@ -1544,14 +1555,12 @@ def detect(text: str, join_queries: bool = True) -> Select:
|
|
1544
1555
|
|
1545
1556
|
|
1546
1557
|
if __name__ == '__main__':
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
'
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
).limit(10)
|
1557
|
-
print(query)
|
1558
|
+
query = Select(
|
1559
|
+
'Tips t',
|
1560
|
+
tip=[Field, Lag().over(day=OrderBy).As('last')],
|
1561
|
+
diff=[
|
1562
|
+
ExpressionField('Round(tip-last, 2) as {f}'),
|
1563
|
+
Not.is_null()
|
1564
|
+
]
|
1565
|
+
)
|
1566
|
+
print(query)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 1.25.
|
3
|
+
Version: 1.25.19011745
|
4
4
|
Summary: Allows you to create objects for parts of SQL query commands. Also to combine these objects by joining them, adding or removing parts...
|
5
5
|
Home-page: https://github.com/julio-cascalles/sql_blocks
|
6
6
|
Author: Júlio Cascalles
|
@@ -0,0 +1,7 @@
|
|
1
|
+
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
+
sql_blocks/sql_blocks.py,sha256=lPUpYOLHjvx84EVjlydJK03rm7qG1DWotRtqyldKqvo,52020
|
3
|
+
sql_blocks-1.25.19011745.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
+
sql_blocks-1.25.19011745.dist-info/METADATA,sha256=KPw30aPiITpjBHpfWU9yAuTtr8aQ5cW5cdIdzM4iD0k,15031
|
5
|
+
sql_blocks-1.25.19011745.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
sql_blocks-1.25.19011745.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
+
sql_blocks-1.25.19011745.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
-
sql_blocks/sql_blocks.py,sha256=iFS3drlQaazFkbBBFIH58RPZt4Lhe6R2Xqi_Ujef7Bg,51893
|
3
|
-
sql_blocks-1.25.1801.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
-
sql_blocks-1.25.1801.dist-info/METADATA,sha256=WnwFnhle4YXNyeC6dBVAnQmUqJiboT1CDhbvRHOmEQY,15027
|
5
|
-
sql_blocks-1.25.1801.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
sql_blocks-1.25.1801.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
-
sql_blocks-1.25.1801.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|