sql-blocks 1.25.111__tar.gz → 1.25.112__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.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
 
@@ -599,6 +599,12 @@ You may use this functions:
599
599
  * Max
600
600
  * Sum
601
601
  * Count
602
+ * Lag
603
+ * Lead
604
+ * Row_Number
605
+ * Rank
606
+ * Coalesce
607
+ * Cast
602
608
  > Some of these functions may vary in syntax depending on the database.
603
609
  For example, if your query is going to run on Oracle, do the following:
604
610
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sql_blocks"
3
- version = "1.25.111"
3
+ version = "1.25.112"
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.25.111',
6
+ version = '1.25.112',
7
7
  author = 'Júlio Cascalles',
8
8
  author_email = 'julio.cascalles@outlook.com',
9
9
  packages = ['sql_blocks'],
@@ -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
 
File without changes
File without changes