sql-blocks 1.25.38021329__py3-none-any.whl → 1.25.312022057__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
@@ -244,6 +244,15 @@ class Function:
244
244
  params=self.separator.join(str(p) for p in self.params)
245
245
  )
246
246
 
247
+ @classmethod
248
+ def help(cls) -> str:
249
+ descr = ' '.join(B.__name__ for B in cls.__bases__)
250
+ params = cls.inputs or ''
251
+ return cls().get_pattern().format(
252
+ func_name=f'{descr} {cls.__name__}',
253
+ params=cls.separator.join(str(p) for p in params)
254
+ ) + f' Return {cls.output}'
255
+
247
256
  def set_main_param(self, name: str, main: SQLObject) -> bool:
248
257
  nested_functions = [
249
258
  param for param in self.params if isinstance(param, Function)
@@ -378,7 +387,8 @@ class Frame:
378
387
 
379
388
 
380
389
  class Aggregate(Frame):
381
- ...
390
+ inputs = [FLOAT]
391
+ output = FLOAT
382
392
 
383
393
  class Window(Frame):
384
394
  ...
@@ -397,13 +407,16 @@ class Count(Aggregate, Function):
397
407
 
398
408
  # ---- Window Functions: -----------------------------------
399
409
  class Row_Number(Window, Function):
400
- ...
410
+ output = INT
411
+
401
412
  class Rank(Window, Function):
402
- ...
413
+ output = INT
414
+
403
415
  class Lag(Window, Function):
404
- ...
416
+ output = ANY
417
+
405
418
  class Lead(Window, Function):
406
- ...
419
+ output = ANY
407
420
 
408
421
 
409
422
  # ---- Conversions and other Functions: ---------------------
@@ -1441,15 +1454,18 @@ class Select(SQLObject):
1441
1454
 
1442
1455
  def add(self, name: str, main: SQLObject):
1443
1456
  old_tables = main.values.get(FROM, [])
1444
- new_tables = set([
1445
- '{jt}JOIN {tb} {a2} ON ({a1}.{f1} = {a2}.{f2})'.format(
1457
+ if len(self.values[FROM]) > 1:
1458
+ old_tables += self.values[FROM][1:]
1459
+ new_tables = []
1460
+ row = '{jt}JOIN {tb} {a2} ON ({a1}.{f1} = {a2}.{f2})'.format(
1446
1461
  jt=self.join_type.value,
1447
1462
  tb=self.aka(),
1448
1463
  a1=main.alias, f1=name,
1449
1464
  a2=self.alias, f2=self.key_field
1450
1465
  )
1451
- ] + old_tables[1:])
1452
- main.values[FROM] = old_tables[:1] + list(new_tables)
1466
+ if row not in old_tables[1:]:
1467
+ new_tables.append(row)
1468
+ main.values[FROM] = old_tables[:1] + new_tables + old_tables[1:]
1453
1469
  for key in USUAL_KEYS:
1454
1470
  main.update_values(key, self.values.get(key, []))
1455
1471
 
@@ -1569,7 +1585,7 @@ class CTE(Select):
1569
1585
  result, line = [], ''
1570
1586
  keywords = '|'.join(KEYWORD)
1571
1587
  for word in re.split(fr'({keywords}|AND|OR|,)', str(query)):
1572
- if len(line) >= 60:
1588
+ if len(line) >= 50:
1573
1589
  result.append(line)
1574
1590
  line = ''
1575
1591
  line += word
@@ -1777,3 +1793,30 @@ def detect(text: str, join_queries: bool = True, format: str='') -> Select | lis
1777
1793
  result += query
1778
1794
  return result
1779
1795
  # ===========================================================================================//
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.38021329
3
+ Version: 1.25.312022057
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=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,,
@@ -1,7 +0,0 @@
1
- sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
- sql_blocks/sql_blocks.py,sha256=5LQPEOkvMylJJxoU2m1P6pAhfcMHVdsnTiYgfLLJ5bQ,59477
3
- sql_blocks-1.25.38021329.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
- sql_blocks-1.25.38021329.dist-info/METADATA,sha256=un6TFbAfNbyhIrjLzHpvG1Yy77jsyZCw2xy_i3tMw2k,20511
5
- sql_blocks-1.25.38021329.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- sql_blocks-1.25.38021329.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
- sql_blocks-1.25.38021329.dist-info/RECORD,,