sql-blocks 1.25.32011301__py3-none-any.whl → 1.25.33022255__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 CHANGED
@@ -1135,7 +1135,13 @@ class CypherParser(Parser):
1135
1135
  Count().As(token, extra_classes).add(pk_field, self.queries[-1])
1136
1136
  return
1137
1137
  else:
1138
- class_list = [ FUNCTION_CLASS[func_name] ]
1138
+ class_type = FUNCTION_CLASS.get(func_name)
1139
+ if not class_type:
1140
+ raise ValueError(f'Unknown function `{func_name}`.')
1141
+ if ':' in token:
1142
+ token, field_alias = token.split(':')
1143
+ class_type = class_type().As(field_alias)
1144
+ class_list = [class_type]
1139
1145
  class_list += extra_classes
1140
1146
  FieldList(token, class_list).add('', self.queries[-1])
1141
1147
 
@@ -1504,6 +1510,17 @@ class CTE(Select):
1504
1510
  justify(q) for q in self.query_list
1505
1511
  ), super().__str__()
1506
1512
  )
1513
+ def join(self, pattern: str, fields: list | str, format: str):
1514
+ if isinstance(fields, str):
1515
+ count = len( fields.split(',') )
1516
+ else:
1517
+ count = len(fields)
1518
+ queries = detect(
1519
+ pattern*count, join_queries=False, format=format
1520
+ )
1521
+ FieldList(fields, queries, ziped=True).add('', self)
1522
+ self.break_lines = True
1523
+ return self
1507
1524
 
1508
1525
  class Recursive(CTE):
1509
1526
  prefix = 'RECURSIVE '
@@ -1535,23 +1552,13 @@ class Recursive(CTE):
1535
1552
  Where.formula(formula).add(foreign_key or pk_field, t2)
1536
1553
  return cls(name, [t1, t2])
1537
1554
 
1538
- def join(self, pattern: str, fields: list | str, format: str):
1539
- if isinstance(fields, str):
1540
- count = len( fields.split(',') )
1541
- else:
1542
- count = len(fields)
1543
- queries = detect(
1544
- pattern*count, join_queries=False, format=format
1545
- )
1546
- FieldList(fields, queries, ziped=True).add('', self)
1547
- self.break_lines = True
1548
-
1549
1555
  def counter(self, name: str, start, increment: str='+1'):
1550
1556
  for i, query in enumerate(self.query_list):
1551
1557
  if i == 0:
1552
1558
  Field.add(f'{start} AS {name}', query)
1553
1559
  else:
1554
1560
  Field.add(f'({name}{increment}) AS {name}', query)
1561
+ return self
1555
1562
 
1556
1563
 
1557
1564
  # ----- Rules -----
@@ -1697,3 +1704,9 @@ def detect(text: str, join_queries: bool = True, format: str='') -> Select | lis
1697
1704
  return result
1698
1705
 
1699
1706
 
1707
+ if __name__ == "__main__":
1708
+ CAMPO_MEDIA = 'MEDIA_SALARIAL_DEPTO'
1709
+ employees = detect(
1710
+ f'Employees@department_id(avg$salary:{CAMPO_MEDIA})'
1711
+ )
1712
+ print(employees)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.25.32011301
3
+ Version: 1.25.33022255
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=orYGCD6mnYmPZT4xzLXMy8Na_nwUdAe0HxsVPeas6LM,57510
3
+ sql_blocks-1.25.33022255.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
+ sql_blocks-1.25.33022255.dist-info/METADATA,sha256=mOP6W7LDKvEHlfrZUVooyBwYs1A9a55K9bpLQpVt2N0,19574
5
+ sql_blocks-1.25.33022255.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ sql_blocks-1.25.33022255.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
+ sql_blocks-1.25.33022255.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
- sql_blocks/sql_blocks.py,sha256=VW8n2nWu7RREnns8dmYruhlvzGBCA3EeuBKiXCjClmE,56975
3
- sql_blocks-1.25.32011301.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
- sql_blocks-1.25.32011301.dist-info/METADATA,sha256=g_Yr5mTcquKqG5PM6qSNeWsuZ4wbo88pdZUldp_rt9k,19574
5
- sql_blocks-1.25.32011301.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- sql_blocks-1.25.32011301.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
- sql_blocks-1.25.32011301.dist-info/RECORD,,