sql-blocks 0.2.1__py3-none-any.whl → 0.2.2__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 +11 -10
- {sql_blocks-0.2.1.dist-info → sql_blocks-0.2.2.dist-info}/METADATA +7 -5
- sql_blocks-0.2.2.dist-info/RECORD +7 -0
- sql_blocks-0.2.1.dist-info/RECORD +0 -7
- {sql_blocks-0.2.1.dist-info → sql_blocks-0.2.2.dist-info}/LICENSE +0 -0
- {sql_blocks-0.2.1.dist-info → sql_blocks-0.2.2.dist-info}/WHEEL +0 -0
- {sql_blocks-0.2.1.dist-info → sql_blocks-0.2.2.dist-info}/top_level.txt +0 -0
sql_blocks/sql_blocks.py
CHANGED
@@ -4,15 +4,14 @@ import re
|
|
4
4
|
|
5
5
|
PATTERN_PREFIX = '([^0-9 ]+[.])'
|
6
6
|
PATTERN_SUFFIX = '( [A-Za-z_]+)'
|
7
|
-
|
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': (',{}', '',
|
15
|
-
'ORDER BY': (',{}', '',
|
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,
|
71
|
+
def diff(self, key: str, search_list: list, exact: bool=False) -> set:
|
73
72
|
def cleanup(fld: str) -> str:
|
74
|
-
if
|
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
|
81
|
-
|
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
|
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)
|
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.
|
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
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
71
|
+
3.2 -- Sub-queries:
|
70
72
|
```
|
71
73
|
query = Select('Movie m', title=Field,
|
72
74
|
id=SelectIN(
|
@@ -0,0 +1,7 @@
|
|
1
|
+
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
+
sql_blocks/sql_blocks.py,sha256=uzMAPjx1d7CAb5WLoel_RcC91Onx3cFVQzGaww-VYEc,21552
|
3
|
+
sql_blocks-0.2.2.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
+
sql_blocks-0.2.2.dist-info/METADATA,sha256=izh5P3AG_LTwdBJyqpPwntbFXVlolK2kmhVKPmr_6dk,8892
|
5
|
+
sql_blocks-0.2.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
sql_blocks-0.2.2.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
+
sql_blocks-0.2.2.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
-
sql_blocks/sql_blocks.py,sha256=5WBEFqik86gcV4WwPHx4R2e2vMeA1D_et1C9oEMnoQw,21600
|
3
|
-
sql_blocks-0.2.1.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
-
sql_blocks-0.2.1.dist-info/METADATA,sha256=g5YLLFr736iWjO8dD0pO7nph5xEbyG6fynoAKo9-XtI,8804
|
5
|
-
sql_blocks-0.2.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
sql_blocks-0.2.1.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
-
sql_blocks-0.2.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|