sql-blocks 1.25.312022057__py3-none-any.whl → 1.25.414021502__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
@@ -1528,7 +1532,7 @@ class Select(SQLObject):
1528
1532
  Recognizes if the field is from the current table
1529
1533
  '''
1530
1534
  if key in (ORDER_BY, GROUP_BY) and '.' not in field:
1531
- return main.has_named_field(field)
1535
+ return self.has_named_field(field)
1532
1536
  return re.findall(f'\b*{self.alias}[.]', field) != []
1533
1537
 
1534
1538
  @classmethod
@@ -1793,30 +1797,3 @@ def detect(text: str, join_queries: bool = True, format: str='') -> Select | lis
1793
1797
  result += query
1794
1798
  return result
1795
1799
  # ===========================================================================================//
1796
-
1797
- if __name__ == "__main__":
1798
- 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
- movimento = Select(
1814
- 'Movimento M',
1815
- entrada_saida=eq('E'),
1816
- apartamento=dono_do_apto,
1817
- pessoa=visitante
1818
- )
1819
- print(dono_do_apto)
1820
- print('-'*50)
1821
- print(movimento)
1822
- 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.414021502
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=HUDdXrSDuippY7buAAMuFyYS9mRetAu7woy_6yBUQ7c,60161
3
+ sql_blocks-1.25.414021502.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
+ sql_blocks-1.25.414021502.dist-info/METADATA,sha256=3GGtGw0pl-9zIqwCZM2AH0GHykI1Sawkb0fpfpsLMlc,20512
5
+ sql_blocks-1.25.414021502.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ sql_blocks-1.25.414021502.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
+ sql_blocks-1.25.414021502.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,,