sql-blocks 0.31.21__py3-none-any.whl → 0.31.89__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
@@ -369,10 +369,14 @@ class OrderBy:
369
369
  sort: SortType = SortType.ASC
370
370
  @classmethod
371
371
  def add(cls, name: str, main: SQLObject):
372
+ def is_function() -> bool:
373
+ diff = main.diff(SELECT, [name.lower()], True)
374
+ FUNCTION_CLASS = {f.__name__.lower(): f for f in Function.__subclasses__()}
375
+ return diff.intersection(FUNCTION_CLASS)
372
376
  found = re.findall(r'^_\d', name)
373
377
  if found:
374
378
  name = found[0].replace('_', '')
375
- elif main.alias:
379
+ elif main.alias and not is_function():
376
380
  name = f'{main.alias}.{name}'
377
381
  main.values.setdefault(ORDER_BY, []).append(name+cls.sort.value)
378
382
 
@@ -858,7 +862,11 @@ class CypherParser(Parser):
858
862
  else:
859
863
  if not curr.values.get(SELECT):
860
864
  raise IndexError(f'Foreign Key not found for {curr.table_name}.')
861
- foreign_fld = curr.values[SELECT][0].split('.')[-1]
865
+ fields = [
866
+ fld for fld in curr.values[SELECT]
867
+ if fld not in curr.values.get(GROUP_BY, [])
868
+ ]
869
+ foreign_fld = fields[0].split('.')[-1]
862
870
  curr.delete(foreign_fld, [SELECT])
863
871
  if curr.join_type == JoinType.RIGHT:
864
872
  pk_field, foreign_fld = foreign_fld, pk_field
@@ -1255,12 +1263,19 @@ def detect(text: str) -> Select:
1255
1263
 
1256
1264
 
1257
1265
  if __name__ == "__main__":
1258
- print('@'*100)
1259
- print( detect(
1266
+ print('░▒▓▒░'*20)
1267
+ p, c, a = Select.parse(
1260
1268
  '''
1261
- Company(?jobs > 10, id)
1262
- <- Person(work_at ^name, friend_of) ->
1263
- Person(id ?skill="pANDas")
1264
- ''' # ^^^---- Test for confusion with the AND operator
1265
- ) )
1266
- print('@'*100)
1269
+ Professor(?nome="Júlio Cascalles", id)
1270
+ <- Curso@disciplina(professor, aluno) ->
1271
+ Aluno(id ^count$qtd_alunos)
1272
+ ''', CypherParser
1273
+ )
1274
+ print(p)
1275
+ print('-'*50)
1276
+ print(c)
1277
+ print('-'*50)
1278
+ print(a)
1279
+ print('='*50)
1280
+ print(a + c + p)
1281
+ print('░▒▓▒░'*20)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 0.31.21
3
+ Version: 0.31.89
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
@@ -390,7 +390,7 @@ a, c, m = Select.parse(
390
390
  <- Cast(actor_id, movie_id) ->
391
391
  Movie(id ^title)
392
392
  """,
393
- Cypher
393
+ CypherParser
394
394
  # ^^^ recognizes syntax like Neo4J queries
395
395
  )
396
396
  ```
@@ -466,7 +466,7 @@ print(query)
466
466
  db.people.find({
467
467
  {
468
468
  $or: [
469
- status:{$eq:"B"},
469
+ {status:{$eq:"B"}},
470
470
  age:{$lt:50}
471
471
  ]
472
472
  },
@@ -0,0 +1,7 @@
1
+ sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
+ sql_blocks/sql_blocks.py,sha256=nsIT8JEeYHw3KIkzAUHUdzUAR_i2asJmdytsvW0hYKc,43342
3
+ sql_blocks-0.31.89.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
+ sql_blocks-0.31.89.dist-info/METADATA,sha256=xKHVfM76nzvZBr-TYC5_PN4bAvYW9oWoi5ChPIPdbDE,12202
5
+ sql_blocks-0.31.89.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ sql_blocks-0.31.89.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
+ sql_blocks-0.31.89.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
- sql_blocks/sql_blocks.py,sha256=jtK4yfyLCQZYrom2Aj_En6Hvlc3mbvAI1TOnC4AK72U,42823
3
- sql_blocks-0.31.21.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
- sql_blocks-0.31.21.dist-info/METADATA,sha256=lDrOFqAT1hC8lEp9plVXngNJ7m_2ZnJ8qRywx_PVUCo,12195
5
- sql_blocks-0.31.21.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- sql_blocks-0.31.21.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
- sql_blocks-0.31.21.dist-info/RECORD,,