sql-blocks 1.20250712__py3-none-any.whl → 1.20250714__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 +27 -12
- {sql_blocks-1.20250712.dist-info → sql_blocks-1.20250714.dist-info}/METADATA +9 -2
- sql_blocks-1.20250714.dist-info/RECORD +7 -0
- sql_blocks-1.20250712.dist-info/RECORD +0 -7
- {sql_blocks-1.20250712.dist-info → sql_blocks-1.20250714.dist-info}/LICENSE +0 -0
- {sql_blocks-1.20250712.dist-info → sql_blocks-1.20250714.dist-info}/WHEEL +0 -0
- {sql_blocks-1.20250712.dist-info → sql_blocks-1.20250714.dist-info}/top_level.txt +0 -0
sql_blocks/sql_blocks.py
CHANGED
@@ -945,15 +945,16 @@ class OrderBy(Clause):
|
|
945
945
|
|
946
946
|
@classmethod
|
947
947
|
def format(cls, name: str, main: SQLObject) -> str:
|
948
|
-
if cls.ascending(name):
|
949
|
-
|
950
|
-
else:
|
948
|
+
# if cls.ascending(name):
|
949
|
+
# cls.sort = SortType.ASC
|
950
|
+
# else:
|
951
|
+
if not cls.ascending(name):
|
951
952
|
cls.sort = SortType.DESC
|
952
953
|
return super().format(name, main)
|
953
954
|
|
954
955
|
@classmethod
|
955
956
|
def cls_to_str(cls, field: str='') -> str:
|
956
|
-
return f"{ORDER_BY} {field}"
|
957
|
+
return f"{ORDER_BY} {field}{cls.sort.value}"
|
957
958
|
|
958
959
|
class Partition:
|
959
960
|
@classmethod
|
@@ -1064,7 +1065,8 @@ class QueryLanguage:
|
|
1064
1065
|
return self.join_with_tabs(values, ' AND ')
|
1065
1066
|
|
1066
1067
|
def sort_by(self, values: list) -> str:
|
1067
|
-
|
1068
|
+
is_ascending = OrderBy.ascending(values[-1]) if values else False
|
1069
|
+
if OrderBy.sort == SortType.DESC and is_ascending:
|
1068
1070
|
values[-1] += ' DESC'
|
1069
1071
|
return self.join_with_tabs(values, ',')
|
1070
1072
|
|
@@ -2203,14 +2205,25 @@ class CTEFactory:
|
|
2203
2205
|
Table1(field, `function$`field`:alias`, `group@`) <- Table2(field)
|
2204
2206
|
`...`MainTable(field)
|
2205
2207
|
"""
|
2206
|
-
self.main = None
|
2207
2208
|
if parser_class(txt) == CypherParser:
|
2208
|
-
|
2209
|
-
txt, other = txt.split('...')
|
2210
|
-
self.main = detect(other)
|
2211
|
-
alias = self.main.table_name
|
2209
|
+
txt, main_script = txt.split('...')
|
2212
2210
|
query_list = Select.parse(txt, CypherParser)
|
2213
|
-
if
|
2211
|
+
if main_script:
|
2212
|
+
main_script = ''.join(main_script)
|
2213
|
+
if '(*)' in main_script:
|
2214
|
+
field_list = [
|
2215
|
+
re.split(
|
2216
|
+
r'\bas\b|\bAS\b', field
|
2217
|
+
)[-1].strip()
|
2218
|
+
for query in query_list
|
2219
|
+
for field in query.values.get(SELECT, [])
|
2220
|
+
]
|
2221
|
+
main_script = main_script.replace('(*)', '({}, *)'.format(
|
2222
|
+
','.join(field_list)
|
2223
|
+
))
|
2224
|
+
self.main = detect(main_script)
|
2225
|
+
alias = self.main.table_name
|
2226
|
+
else:
|
2214
2227
|
alias = '_'.join(query.table_name for query in query_list)
|
2215
2228
|
self.main = Select(alias)
|
2216
2229
|
self.main.break_lines = False
|
@@ -2425,7 +2438,9 @@ def detect(text: str, join_method = join_queries, format: str='') -> Select | li
|
|
2425
2438
|
return result
|
2426
2439
|
# ===========================================================================================//
|
2427
2440
|
|
2441
|
+
|
2428
2442
|
if __name__ == "__main__":
|
2443
|
+
OrderBy.sort = SortType.DESC
|
2429
2444
|
cte = CTEFactory(
|
2430
2445
|
"Sales(year$ref_date:ref_year@, sum$quantity:qty_sold, vendor) <- Vendor(id, name:vendors_name@)"
|
2431
2446
|
# ^^^ ^^^ ^^^
|
@@ -2439,6 +2454,6 @@ if __name__ == "__main__":
|
|
2439
2454
|
# | |
|
2440
2455
|
# +--- The Sales table |
|
2441
2456
|
# Also groups by vendor´s name ------------------+
|
2442
|
-
"...Annual_Sales_per_Vendor(
|
2457
|
+
"...Annual_Sales_per_Vendor(*) -> Goal(^year, target)"
|
2443
2458
|
)
|
2444
2459
|
print(cte)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.20250714
|
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
|
@@ -995,7 +995,14 @@ results...
|
|
995
995
|
|
996
996
|
#### 17.3.1 - You can also pass a Cypher script like in the example below:
|
997
997
|
|
998
|
-
|
998
|
+
cte = CTEFactory(
|
999
|
+
"Sales(year$ref_date:ref_year@, sum$quantity:qty_sold, vendor)"
|
1000
|
+
" <- Vendor(id, name:vendors_name@)"
|
1001
|
+
"...Annual_Sales_per_Vendor(*) -> Goal(year, target)"
|
1002
|
+
)
|
1003
|
+
print(cte)
|
1004
|
+
|
1005
|
+

|
999
1006
|
|
1000
1007
|
results...
|
1001
1008
|
```
|
@@ -0,0 +1,7 @@
|
|
1
|
+
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
+
sql_blocks/sql_blocks.py,sha256=wYBE0XgHwsWQM0Wng5w03HtGMJ5aAqIoHpr0sAvlH-A,84546
|
3
|
+
sql_blocks-1.20250714.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
+
sql_blocks-1.20250714.dist-info/METADATA,sha256=CPrPfsQDAQcGlGZ2z9ajGXsj_u7UHwlZia9kDqSgvrc,25388
|
5
|
+
sql_blocks-1.20250714.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
sql_blocks-1.20250714.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
+
sql_blocks-1.20250714.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
-
sql_blocks/sql_blocks.py,sha256=A-i1B6jUA6_SYRfZAA65mhqHMkSQApXO7NcmIt3O5O8,83911
|
3
|
-
sql_blocks-1.20250712.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
-
sql_blocks-1.20250712.dist-info/METADATA,sha256=Kj2I_aL5fxL2bxn3hoj8hb54kKDt3M510VDn8mGmA7o,25079
|
5
|
-
sql_blocks-1.20250712.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
sql_blocks-1.20250712.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
-
sql_blocks-1.20250712.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|