sql-blocks 1.25.1901__py3-none-any.whl → 1.25.19011849__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
@@ -472,9 +472,14 @@ class Where:
472
472
 
473
473
  def add(self, name: str, main: SQLObject):
474
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
+ )
475
480
  if func_type:
476
481
  name = func_type.format('*', main)
477
- else:
482
+ elif not exists:
478
483
  name = Field.format(name, main)
479
484
  main.values.setdefault(WHERE, []).append('{}{} {}'.format(
480
485
  self.prefix, name, self.expr
@@ -561,7 +566,7 @@ class Clause:
561
566
  found = re.findall(r'^_\d', name)
562
567
  if found:
563
568
  name = found[0].replace('_', '')
564
- elif main.alias and not is_function():
569
+ elif '.' not in name and main.alias and not is_function():
565
570
  name = f'{main.alias}.{name}'
566
571
  return name
567
572
 
@@ -1003,8 +1008,11 @@ class SQLParser(Parser):
1003
1008
  if not key in values:
1004
1009
  continue
1005
1010
  separator = self.class_type.get_separator(key)
1011
+ cls = {
1012
+ ORDER_BY: OrderBy, GROUP_BY: GroupBy
1013
+ }.get(key, Field)
1006
1014
  obj.values[key] = [
1007
- Field.format(fld, obj)
1015
+ cls.format(fld, obj)
1008
1016
  for fld in re.split(separator, values[key])
1009
1017
  if (fld != '*' and len(tables) == 1) or obj.match(fld, key)
1010
1018
  ]
@@ -1550,10 +1558,22 @@ def detect(text: str, join_queries: bool = True) -> Select:
1550
1558
 
1551
1559
 
1552
1560
  if __name__ == '__main__':
1553
- query = Select(
1554
- 'Tips t',
1555
- tip=[Field, Lag().over(day=OrderBy).As('last')],
1556
- diff=ExpressionField('Round(tip-last, 2) as {f}'),
1557
- Row_Number=gt(1)
1558
- )
1561
+ # query = Select(
1562
+ # 'Tips t',
1563
+ # tip=[Field, Lag().over(day=OrderBy).As('last')],
1564
+ # diff=[
1565
+ # ExpressionField('Round(tip-last, 2) as {f}'),
1566
+ # Not.is_null()
1567
+ # ]
1568
+ # )
1569
+ p, c, a = Select.parse('''
1570
+ Professor(?nome="Júlio Cascalles", id)
1571
+ <- Curso@disciplina(professor, aluno) ->
1572
+ Aluno(id ^count$qtd_alunos)
1573
+ ''', CypherParser)
1574
+ query = p + c + a
1575
+ print(query)
1576
+ print('------------------')
1577
+ query.optimize([RuleReplaceJoinBySubselect])
1578
+ # ==============================================
1559
1579
  print(query)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.25.1901
3
+ Version: 1.25.19011849
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=nMIOewFh6X7vC0UNKs4mdqz4F_gpCSvtF0oAkocEGHw,52542
3
+ sql_blocks-1.25.19011849.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
+ sql_blocks-1.25.19011849.dist-info/METADATA,sha256=jp-OY-e66KmW-tXSklUT3l5-01CX0jfCCPJ6iANNpSY,15031
5
+ sql_blocks-1.25.19011849.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ sql_blocks-1.25.19011849.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
+ sql_blocks-1.25.19011849.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
- sql_blocks/sql_blocks.py,sha256=U2bcs8SnXcGOlsY9rhB3lpPzzb-W4MsG64N7r0QjKEI,51822
3
- sql_blocks-1.25.1901.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
- sql_blocks-1.25.1901.dist-info/METADATA,sha256=MCkLq9JFvLiVAEJc_IhDLd3rExUKeVa04EtC9IwJwsA,15027
5
- sql_blocks-1.25.1901.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- sql_blocks-1.25.1901.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
- sql_blocks-1.25.1901.dist-info/RECORD,,