sql-blocks 1.25.113__py3-none-any.whl → 1.25.1301__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
@@ -282,14 +282,15 @@ class Frame:
282
282
  keywords = ''
283
283
  for field, obj in args.items():
284
284
  is_valid = any([
285
- obj is class_type # or isinstance(obj, class_type)
286
- for class_type in (OrderBy, Partition)
285
+ obj is OrderBy,
286
+ obj is Partition,
287
+ isinstance(obj, Rows),
287
288
  ])
288
289
  if not is_valid:
289
290
  continue
290
291
  keywords += '{}{} {}'.format(
291
292
  '\n\t\t' if self.break_lines else ' ',
292
- obj.cls_to_str(), field
293
+ obj.cls_to_str(), field if field != '_' else ''
293
294
  )
294
295
  if keywords and self.break_lines:
295
296
  keywords += '\n\t'
@@ -561,6 +562,34 @@ class SortType(Enum):
561
562
  ASC = ''
562
563
  DESC = ' DESC'
563
564
 
565
+ class Row:
566
+ def __init__(self, value: int=0):
567
+ self.value = value
568
+
569
+ def __str__(self) -> str:
570
+ return '{} {}'.format(
571
+ 'UNBOUNDED' if self.value == 0 else self.value,
572
+ self.__class__.__name__.upper()
573
+ )
574
+
575
+ class Preceding(Row):
576
+ ...
577
+ class Following(Row):
578
+ ...
579
+ class Current(Row):
580
+ def __str__(self) -> str:
581
+ return 'CURRENT ROW'
582
+
583
+ class Rows:
584
+ def __init__(self, *rows: list[Row]):
585
+ self.rows = rows
586
+
587
+ def cls_to_str(self) -> str:
588
+ return 'ROWS {}{}'.format(
589
+ 'BETWEEN ' if len(self.rows) > 1 else '',
590
+ ' AND '.join(str(row) for row in self.rows)
591
+ )
592
+
564
593
 
565
594
  class OrderBy(Clause):
566
595
  sort: SortType = SortType.ASC
@@ -1475,7 +1504,7 @@ def parser_class(text: str) -> Parser:
1475
1504
  return None
1476
1505
 
1477
1506
 
1478
- def detect(text: str) -> Select:
1507
+ def detect(text: str, join_queries: bool = True) -> Select:
1479
1508
  from collections import Counter
1480
1509
  parser = parser_class(text)
1481
1510
  if not parser:
@@ -1491,22 +1520,9 @@ def detect(text: str) -> Select:
1491
1520
  text = text[:begin] + new_name + '(' + text[end:]
1492
1521
  count -= 1
1493
1522
  query_list = Select.parse(text, parser)
1523
+ if not join_queries:
1524
+ return query_list
1494
1525
  result = query_list[0]
1495
1526
  for query in query_list[1:]:
1496
1527
  result += query
1497
1528
  return result
1498
-
1499
-
1500
- if __name__ == '__main__':
1501
- p, c, a = Select.parse('''
1502
- Professor(?nome="Júlio Cascalles", id)
1503
- <- Curso@disciplina(professor, aluno) ->
1504
- Aluno(id ^count$qtd_alunos)
1505
- ''', CypherParser)
1506
- query = p + c + a
1507
- print('#######################################')
1508
- print(query)
1509
- print('***************************************')
1510
- query.optimize([RuleReplaceJoinBySubselect])
1511
- print(query)
1512
- print('#######################################')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.25.113
3
+ Version: 1.25.1301
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
@@ -554,12 +554,18 @@ It consists of the inverse process of parsing: From a Select object, it returns
554
554
  ---
555
555
  ### 14 - Window Function
556
556
 
557
- Aggregation functions (Avg, Min, Max, Sum, Count) have the **over** method...
557
+ Aggregation functions (Avg, Min, Max, Sum, Count) -- or Window functions (Lead, Lag, Row_Number, Rank) -- have the **over** method...
558
558
 
559
559
  query=Select(
560
560
  'Enrollment e',
561
561
  payment=Sum().over(
562
- partition='student_id', order='due_date'
562
+ student_id=Partition, due_date=OrderBy,
563
+ # _=Rows(Current(), Following(5)),
564
+ # ^^^-------> ROWS BETWEEN CURRENT ROW AND 5 FOLLOWING
565
+ # _=Rows(Preceding(3), Following()),
566
+ # ^^^-------> ROWS BETWEEN 3 PRECEDING AND UNBOUNDED FOLLOWING
567
+ # _=Rows(Preceding(3))
568
+ # ^^^-------> ROWS 3 PRECEDING
563
569
  ).As('sum_per_student')
564
570
  )
565
571
 
@@ -0,0 +1,7 @@
1
+ sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
+ sql_blocks/sql_blocks.py,sha256=XDjB6YpjJ4ojsHylPt8jGCVt3dViFPKLzE_hbVJwNMo,50844
3
+ sql_blocks-1.25.1301.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
+ sql_blocks-1.25.1301.dist-info/METADATA,sha256=NqoWfNLGyyB32vgldi7qEC3xI6PiJ7Z25x6K5s8yyo0,15027
5
+ sql_blocks-1.25.1301.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ sql_blocks-1.25.1301.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
+ sql_blocks-1.25.1301.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
- sql_blocks/sql_blocks.py,sha256=Saj3MqmF0OHY60bhc_aSl8fL-PhXM2apmiPiE6KspOc,50553
3
- sql_blocks-1.25.113.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
- sql_blocks-1.25.113.dist-info/METADATA,sha256=td1IZl9O3m2U0rWFk6gyecqWnkr0cMDW94PfeqhzP8Y,14638
5
- sql_blocks-1.25.113.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- sql_blocks-1.25.113.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
- sql_blocks-1.25.113.dist-info/RECORD,,