sql-blocks 1.2025.630__tar.gz → 1.2025.701__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.2025.630
3
+ Version: 1.2025.701
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sql_blocks"
3
- version = "1.2025.0630"
3
+ version = "1.2025.0701"
4
4
  authors = [
5
5
  { name="Julio Cascalles", email="julio.cascalles@outlook.com" },
6
6
  ]
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name = 'sql_blocks',
6
- version = '1.2025.0630',
6
+ version = '1.2025.0701',
7
7
  author = 'Júlio Cascalles',
8
8
  author_email = 'julio.cascalles@outlook.com',
9
9
  packages = ['sql_blocks'],
@@ -399,15 +399,15 @@ class Frame:
399
399
  keywords = ''
400
400
  for field, obj in args.items():
401
401
  is_valid = any([
402
- obj is OrderBy,
402
+ obj is OrderBy, obj is DescOrderBy,
403
403
  obj is Partition,
404
404
  isinstance(obj, Rows),
405
405
  ])
406
406
  if not is_valid:
407
407
  continue
408
- keywords += '{}{} {}'.format(
408
+ keywords += '{}{}'.format(
409
409
  '\n\t\t' if self.break_lines else ' ',
410
- obj.cls_to_str(), field if field != '_' else ''
410
+ obj.cls_to_str(field if field != '_' else '')
411
411
  )
412
412
  if keywords and self.break_lines:
413
413
  keywords += '\n\t'
@@ -777,10 +777,14 @@ class If(Code, Frame):
777
777
  super().__init__()
778
778
 
779
779
  def format(self, name: str, main: SQLObject) -> str:
780
- return '{func}({param})'.format(
780
+ return '{func}({param}){over}'.format(
781
781
  func=self.func_class.__name__,
782
- param=Case(self.field).when(self.condition, f'={name}').else_value(0)
782
+ param=Case(self.field).when(self.condition, f'={name}').else_value(0),
783
+ over=self.pattern
783
784
  )
785
+
786
+ def get_pattern(self) -> str:
787
+ return ''
784
788
 
785
789
 
786
790
  class Options:
@@ -881,7 +885,7 @@ class Rows:
881
885
  def __init__(self, *rows: list[Row]):
882
886
  self.rows = rows
883
887
 
884
- def cls_to_str(self) -> str:
888
+ def cls_to_str(self, field: str='') -> str:
885
889
  return 'ROWS {}{}'.format(
886
890
  'BETWEEN ' if len(self.rows) > 1 else '',
887
891
  ' AND '.join(str(row) for row in self.rows)
@@ -894,6 +898,11 @@ class DescOrderBy:
894
898
  name = Clause.format(name, main)
895
899
  main.values.setdefault(ORDER_BY, []).append(name + SortType.DESC.value)
896
900
 
901
+ @classmethod
902
+ def cls_to_str(cls, field: str='') -> str:
903
+ return f"{ORDER_BY} {field} DESC"
904
+
905
+
897
906
  class OrderBy(Clause):
898
907
  sort: SortType = SortType.ASC
899
908
  DESC = DescOrderBy
@@ -918,14 +927,13 @@ class OrderBy(Clause):
918
927
  return super().format(name, main)
919
928
 
920
929
  @classmethod
921
- def cls_to_str(cls) -> str:
922
- return ORDER_BY
930
+ def cls_to_str(cls, field: str='') -> str:
931
+ return f"{ORDER_BY} {field}"
923
932
 
924
- PARTITION_BY = 'PARTITION BY'
925
933
  class Partition:
926
934
  @classmethod
927
- def cls_to_str(cls) -> str:
928
- return PARTITION_BY
935
+ def cls_to_str(cls, field: str) -> str:
936
+ return f'PARTITION BY {field}'
929
937
 
930
938
 
931
939
  class GroupBy(Clause):
@@ -2322,3 +2330,15 @@ def detect(text: str, join_queries: bool = True, format: str='') -> Select | lis
2322
2330
  result += query
2323
2331
  return result
2324
2332
  # ===========================================================================================//
2333
+
2334
+ if __name__ == "__main__":
2335
+ query = Select(
2336
+ 'Emprestimos e',
2337
+ taxa=If('atraso', gt(0), Sum).over(
2338
+ mes_ano=OrderBy.DESC,
2339
+ _=Rows(Current(), Following(5)),
2340
+ # _=Rows(Preceding(3), Following()),
2341
+ # _=Rows( Preceding(3) ),
2342
+ ).As('multa')
2343
+ )
2344
+ print(query)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.2025.630
3
+ Version: 1.2025.701
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
File without changes