sql-blocks 1.25.312022057__py3-none-any.whl → 1.25.313022106__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
@@ -633,20 +633,24 @@ class Case:
633
633
  self.default = None
634
634
  self.field = field
635
635
 
636
- def when(self, condition: Where, result: str):
636
+ def when(self, condition: Where, result):
637
+ if isinstance(result, str):
638
+ result = quoted(result)
637
639
  self.__conditions[result] = condition
638
640
  return self
639
641
 
640
- def else_value(self, default: str):
642
+ def else_value(self, default):
643
+ if isinstance(default, str):
644
+ default = quoted(default)
641
645
  self.default = default
642
646
  return self
643
647
 
644
648
  def add(self, name: str, main: SQLObject):
645
649
  field = Field.format(self.field, main)
646
- default = quoted(self.default)
650
+ default = self.default
647
651
  name = 'CASE \n{}\n\tEND AS {}'.format(
648
652
  '\n'.join(
649
- f'\t\tWHEN {field} {cond.expr} THEN {quoted(res)}'
653
+ f'\t\tWHEN {field} {cond.content} THEN {res}'
650
654
  for res, cond in self.__conditions.items()
651
655
  ) + f'\n\t\tELSE {default}' if default else '',
652
656
  name
@@ -1796,27 +1800,19 @@ def detect(text: str, join_queries: bool = True, format: str='') -> Select | lis
1796
1800
 
1797
1801
  if __name__ == "__main__":
1798
1802
  print('='*50)
1799
- visitante = Select(
1800
- 'Pessoa p1',
1801
- nome=NamedField('nome_visitante'),
1802
- tipo=eq('V'), cpf=PrimaryKey
1803
- )
1804
- dono_do_apto = Select(
1805
- 'Apartamento A',
1806
- dono=Select(
1807
- 'Pessoa p2',
1808
- cpf=PrimaryKey,
1809
- nome=NamedField('nome_morador')
1810
- ),
1811
- id=PrimaryKey
1812
- )
1813
1803
  movimento = Select(
1814
- 'Movimento M',
1815
- entrada_saida=eq('E'),
1816
- apartamento=dono_do_apto,
1817
- pessoa=visitante
1804
+ 'Movimento.parquet M',
1805
+ direcao=Case('entrada_saida').when(
1806
+ eq('E'), 1
1807
+ ).else_value( -1 ),
1808
+ pessoa=Field
1818
1809
  )
1819
- print(dono_do_apto)
1820
- print('-'*50)
1821
1810
  print(movimento)
1811
+ print('-'*50)
1812
+ cte = CTE('Ciclo C', [movimento])
1813
+ cte(
1814
+ pessoa=[GroupBy, Field],
1815
+ direcao=Having.sum(gt(0))
1816
+ )
1817
+ print(cte)
1822
1818
  print('='*50)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.25.312022057
3
+ Version: 1.25.313022106
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=rJThLDIWJpyI-plCdfpG5UwZDpp_pEriUbw1GgXRs0U,60595
3
+ sql_blocks-1.25.313022106.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
+ sql_blocks-1.25.313022106.dist-info/METADATA,sha256=M9_xMMjLg9SYWM4m2ocomFow70Xu8eoqlBZ2BQdt3_4,20512
5
+ sql_blocks-1.25.313022106.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ sql_blocks-1.25.313022106.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
+ sql_blocks-1.25.313022106.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
- sql_blocks/sql_blocks.py,sha256=ICqvEtrB1xnCqquTyTgDX-O9hkeeysQLcLz9pdkFBYs,60671
3
- sql_blocks-1.25.312022057.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
- sql_blocks-1.25.312022057.dist-info/METADATA,sha256=VCXJmWhUPrpSd5dD_Jj5JeXnr2D5XLQNnXMYkWRsN0g,20512
5
- sql_blocks-1.25.312022057.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- sql_blocks-1.25.312022057.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
- sql_blocks-1.25.312022057.dist-info/RECORD,,