sql-blocks 0.1.2__tar.gz → 0.1.4__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: 0.1.2
3
+ Version: 0.1.4
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sql_blocks"
3
- version = "0.1.2"
3
+ version = "0.1.4"
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 = '0.1.2',
6
+ version = '0.1.4',
7
7
  author = 'Júlio Cascalles',
8
8
  author_email = 'julio.cascalles@outlook.com',
9
9
  packages = ['sql_blocks'],
@@ -5,10 +5,10 @@ import re
5
5
  PATTERN_PREFIX = '([^0-9 ]+[.])'
6
6
  PATTERN_SUFFIX = '( [A-Za-z_]+)'
7
7
  SUFFIX_AND_PRE = f'{PATTERN_SUFFIX}|{PATTERN_PREFIX}'
8
- DISTINCT_SF_PR = f'(DISTINCT|distinct)|{SUFFIX_AND_PRE}'
8
+ DISTINCT_PREFX = f'(DISTINCT|distinct)|{PATTERN_PREFIX}'
9
9
 
10
10
  KEYWORD = {
11
- 'SELECT': (',{}', 'SELECT *', DISTINCT_SF_PR),
11
+ 'SELECT': (',{}', 'SELECT *', DISTINCT_PREFX),
12
12
  'FROM': ('{}', '', PATTERN_SUFFIX),
13
13
  'WHERE': ('{}AND ', '', ''),
14
14
  'GROUP BY': (',{}', '', SUFFIX_AND_PRE),
@@ -74,13 +74,18 @@ class SQLObject:
74
74
  if symmetrical:
75
75
  fld = fld.lower()
76
76
  return fld.strip()
77
+ def is_named_field(fld: str) -> bool:
78
+ return key == SELECT and re.search(' as | AS ', fld)
77
79
  pattern = KEYWORD[key][2]
78
80
  if key == WHERE and symmetrical:
79
81
  pattern = f'{PATTERN_PREFIX}| '
80
82
  separator = self.get_separator(key)
81
83
  def field_set(source: list) -> set:
82
84
  return set(
83
- re.sub(pattern, '', cleanup(fld))
85
+ (
86
+ fld if is_named_field(fld) else
87
+ re.sub(pattern, '', cleanup(fld))
88
+ )
84
89
  for string in source
85
90
  for fld in re.split(separator, string)
86
91
  )
@@ -405,8 +410,6 @@ class Select(SQLObject):
405
410
  self.break_lines = True
406
411
 
407
412
  def update_values(self, key: str, new_values: list):
408
- if key == SELECT:
409
- new_values = [re.split(' as | AS ', val)[-1] for val in new_values]
410
413
  for value in self.diff(key, new_values):
411
414
  self.values.setdefault(key, []).append(value)
412
415
 
@@ -639,15 +642,3 @@ class RuleDateFuncReplace(Rule):
639
642
  temp = Select(f'{target.table_name} {target.alias}')
640
643
  Between(f'{year}-01-01', f'{year}-12-31').add(field, temp)
641
644
  target.values[WHERE][i] = ' AND '.join(temp.values[WHERE])
642
-
643
-
644
- if __name__ == "__main__":
645
- query = Select(
646
- 'Cast c',
647
- actor_id=Select(
648
- 'Actor a',
649
- name=NamedField('actors_name'),
650
- id=PrimaryKey
651
- )
652
- )
653
- print(query)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 0.1.2
3
+ Version: 0.1.4
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
File without changes
File without changes
File without changes