sql-blocks 0.2.1__tar.gz → 0.2.2__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.2.1
3
+ Version: 0.2.2
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
@@ -62,11 +62,13 @@ You can specify your own alias: `a = Select('Actor a')`
62
62
  * field=gt(value) - ...the field is GREATER than the value;
63
63
  * field=lt(value) - ...the field is LESS than the value;
64
64
 
65
- 3.1 -- If you want to filter the field on a range of values:
66
-
67
- `a = Select( 'Actor a', age=Between(45, 69) )`
65
+ > You may use Where.**eq**, Where.**gt**, Where.**lt** ... or simply **eq**, **gt**, **lt** ... 😉
66
+
67
+ 3.1 -- If you want to filter the field on a range of values:
68
+
69
+ `a = Select( 'Actor a', age=Between(45, 69) )`
68
70
 
69
- 3.2 -- Sub-queries:
71
+ 3.2 -- Sub-queries:
70
72
  ```
71
73
  query = Select('Movie m', title=Field,
72
74
  id=SelectIN(
@@ -47,11 +47,13 @@ You can specify your own alias: `a = Select('Actor a')`
47
47
  * field=gt(value) - ...the field is GREATER than the value;
48
48
  * field=lt(value) - ...the field is LESS than the value;
49
49
 
50
- 3.1 -- If you want to filter the field on a range of values:
51
-
52
- `a = Select( 'Actor a', age=Between(45, 69) )`
50
+ > You may use Where.**eq**, Where.**gt**, Where.**lt** ... or simply **eq**, **gt**, **lt** ... 😉
51
+
52
+ 3.1 -- If you want to filter the field on a range of values:
53
+
54
+ `a = Select( 'Actor a', age=Between(45, 69) )`
53
55
 
54
- 3.2 -- Sub-queries:
56
+ 3.2 -- Sub-queries:
55
57
  ```
56
58
  query = Select('Movie m', title=Field,
57
59
  id=SelectIN(
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sql_blocks"
3
- version = "0.2.1"
3
+ version = "0.2.2"
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.2.1',
6
+ version = '0.2.2',
7
7
  author = 'Júlio Cascalles',
8
8
  author_email = 'julio.cascalles@outlook.com',
9
9
  packages = ['sql_blocks'],
@@ -4,15 +4,14 @@ import re
4
4
 
5
5
  PATTERN_PREFIX = '([^0-9 ]+[.])'
6
6
  PATTERN_SUFFIX = '( [A-Za-z_]+)'
7
- SUFFIX_AND_PRE = f'{PATTERN_SUFFIX}|{PATTERN_PREFIX}'
8
- DISTINCT_PREFX = f'(DISTINCT|distinct)|{PATTERN_PREFIX}'
7
+ DISTINCT_PREFX = '(DISTINCT|distinct)'
9
8
 
10
9
  KEYWORD = {
11
10
  'SELECT': (',{}', 'SELECT *', DISTINCT_PREFX),
12
11
  'FROM': ('{}', '', PATTERN_SUFFIX),
13
12
  'WHERE': ('{}AND ', '', ''),
14
- 'GROUP BY': (',{}', '', SUFFIX_AND_PRE),
15
- 'ORDER BY': (',{}', '', SUFFIX_AND_PRE),
13
+ 'GROUP BY': (',{}', '', PATTERN_SUFFIX),
14
+ 'ORDER BY': (',{}', '', PATTERN_SUFFIX),
16
15
  'LIMIT': (' ', '', ''),
17
16
  }
18
17
  # ^ ^ ^
@@ -69,16 +68,18 @@ class SQLObject:
69
68
  appendix = {WHERE: 'and|', FROM: 'join|JOIN'}
70
69
  return KEYWORD[key][0].format(appendix.get(key, ''))
71
70
 
72
- def diff(self, key: str, search_list: list, symmetrical: bool=False) -> set:
71
+ def diff(self, key: str, search_list: list, exact: bool=False) -> set:
73
72
  def cleanup(fld: str) -> str:
74
- if symmetrical:
73
+ if exact:
75
74
  fld = fld.lower()
76
75
  return fld.strip()
77
76
  def is_named_field(fld: str) -> bool:
78
77
  return key == SELECT and re.search(' as | AS ', fld)
79
78
  pattern = KEYWORD[key][2]
80
- if key == WHERE and symmetrical:
81
- pattern = f'{PATTERN_PREFIX}| '
79
+ if exact:
80
+ if key == WHERE:
81
+ pattern = ' '
82
+ pattern += f'|{PATTERN_PREFIX}'
82
83
  separator = self.get_separator(key)
83
84
  def field_set(source: list) -> set:
84
85
  return set(
@@ -91,7 +92,7 @@ class SQLObject:
91
92
  )
92
93
  s1 = field_set(search_list)
93
94
  s2 = field_set(self.values.get(key, []))
94
- if symmetrical:
95
+ if exact:
95
96
  return s1.symmetric_difference(s2)
96
97
  return s1 - s2
97
98
 
@@ -646,7 +647,7 @@ class RuleLogicalOp(Rule):
646
647
  ))
647
648
  for i, condition in enumerate(target.values.get(WHERE, [])):
648
649
  expr = re.sub('\n|\t', ' ', condition)
649
- if not re.search(r'\b(NOT|not)\b', expr):
650
+ if not re.search(r'\b(NOT|not).*[<>=]', expr):
650
651
  continue
651
652
  tokens = [t.strip() for t in re.split(r'NOT\b|not\b|(<|>|=)', expr) if t]
652
653
  op = ''.join(tokens[1: len(tokens)-1])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 0.2.1
3
+ Version: 0.2.2
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
@@ -62,11 +62,13 @@ You can specify your own alias: `a = Select('Actor a')`
62
62
  * field=gt(value) - ...the field is GREATER than the value;
63
63
  * field=lt(value) - ...the field is LESS than the value;
64
64
 
65
- 3.1 -- If you want to filter the field on a range of values:
66
-
67
- `a = Select( 'Actor a', age=Between(45, 69) )`
65
+ > You may use Where.**eq**, Where.**gt**, Where.**lt** ... or simply **eq**, **gt**, **lt** ... 😉
66
+
67
+ 3.1 -- If you want to filter the field on a range of values:
68
+
69
+ `a = Select( 'Actor a', age=Between(45, 69) )`
68
70
 
69
- 3.2 -- Sub-queries:
71
+ 3.2 -- Sub-queries:
70
72
  ```
71
73
  query = Select('Movie m', title=Field,
72
74
  id=SelectIN(
File without changes
File without changes