sql-blocks 1.25.111__py3-none-any.whl → 1.25.112__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
@@ -266,23 +266,38 @@ class Current_Date(Function):
266
266
  return super().get_pattern()
267
267
  # --------------------------------------------------------
268
268
 
269
- class Aggregate:
269
+ class Frame:
270
270
  break_lines: bool = True
271
271
 
272
272
  def over(self, **args):
273
- keywords = ' '.join(
274
- '{}{} BY {}'.format(
275
- '\n\t\t' if self.break_lines else '',
276
- key.upper(), args[key]
277
- ) for key in ('partition', 'order')
278
- if key in args
279
- )
273
+ """
274
+ How to use:
275
+ over(field1=OrderBy, field2=Partition)
276
+ """
277
+ keywords = ''
278
+ for field, obj in args.items():
279
+ is_valid = any([
280
+ obj is class_type # or isinstance(obj, class_type)
281
+ for class_type in (OrderBy, Partition)
282
+ ])
283
+ if not is_valid:
284
+ continue
285
+ keywords += '{}{} {}'.format(
286
+ '\n\t\t' if self.break_lines else ' ',
287
+ obj.cls_to_str(), field
288
+ )
280
289
  if keywords and self.break_lines:
281
290
  keywords += '\n\t'
282
291
  self.pattern = self.get_pattern() + f' OVER({keywords})'
283
292
  return self
284
293
 
285
294
 
295
+ class Aggregate(Frame):
296
+ ...
297
+
298
+ class Window(Frame):
299
+ ...
300
+
286
301
  # ---- Aggregate Functions: -------------------------------
287
302
  class Avg(Aggregate, Function):
288
303
  ...
@@ -295,6 +310,17 @@ class Sum(Aggregate, Function):
295
310
  class Count(Aggregate, Function):
296
311
  ...
297
312
 
313
+ # ---- Window Functions: -----------------------------------
314
+ class Row_Number(Window, Function):
315
+ ...
316
+ class Rank(Window, Function):
317
+ ...
318
+ class Lag(Window, Function):
319
+ ...
320
+ class Lead(Window, Function):
321
+ ...
322
+
323
+
298
324
  # ---- Conversions and other Functions: ---------------------
299
325
  class Coalesce(Function):
300
326
  ...
@@ -539,6 +565,16 @@ class OrderBy(Clause):
539
565
  name = cls.format(name, main)
540
566
  main.values.setdefault(ORDER_BY, []).append(name+cls.sort.value)
541
567
 
568
+ @classmethod
569
+ def cls_to_str(cls) -> str:
570
+ return ORDER_BY
571
+
572
+ PARTITION_BY = 'PARTITION BY'
573
+ class Partition:
574
+ @classmethod
575
+ def cls_to_str(cls) -> str:
576
+ return PARTITION_BY
577
+
542
578
 
543
579
  class GroupBy(Clause):
544
580
  @classmethod
@@ -1446,14 +1482,3 @@ def detect(text: str) -> Select:
1446
1482
  return result
1447
1483
 
1448
1484
 
1449
- if __name__ == "__main__":
1450
- query = Select(
1451
- 'Installments i', due_date=Field, customer=Select(
1452
- 'Customer c', id=PrimaryKey,
1453
- name=contains('Smith', Position.EndsWith)
1454
- )
1455
- )
1456
- print(query)
1457
- print('-----')
1458
- query.optimize([RuleReplaceJoinBySubselect])
1459
- print(query)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.25.111
3
+ Version: 1.25.112
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
@@ -614,6 +614,12 @@ You may use this functions:
614
614
  * Max
615
615
  * Sum
616
616
  * Count
617
+ * Lag
618
+ * Lead
619
+ * Row_Number
620
+ * Rank
621
+ * Coalesce
622
+ * Cast
617
623
  > Some of these functions may vary in syntax depending on the database.
618
624
  For example, if your query is going to run on Oracle, do the following:
619
625
 
@@ -0,0 +1,7 @@
1
+ sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
+ sql_blocks/sql_blocks.py,sha256=X13qSCvVhu-BVXdUmqXi48Z7H4THBvXHrP5zw2Hm4wM,49491
3
+ sql_blocks-1.25.112.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
+ sql_blocks-1.25.112.dist-info/METADATA,sha256=npxMGB0xgAFt4J_IgoIaaWmVFcVoNu5lq3qnUAjhb-A,14638
5
+ sql_blocks-1.25.112.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ sql_blocks-1.25.112.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
+ sql_blocks-1.25.112.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
- sql_blocks/sql_blocks.py,sha256=rARGbJxL3Di9mOXRBS4aEFvclO922-dzDOXPy1vSTGg,49018
3
- sql_blocks-1.25.111.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
- sql_blocks-1.25.111.dist-info/METADATA,sha256=Lm7JKPIdZSJT5dkWUc2K7fpY4r0MQ-TeTyv0pbiMy24,14581
5
- sql_blocks-1.25.111.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- sql_blocks-1.25.111.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
- sql_blocks-1.25.111.dist-info/RECORD,,