sql-blocks 0.1.1__tar.gz → 0.1.3__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.
- {sql_blocks-0.1.1/sql_blocks.egg-info → sql_blocks-0.1.3}/PKG-INFO +5 -5
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/README.md +4 -4
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/pyproject.toml +1 -1
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/setup.py +1 -1
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/sql_blocks/sql_blocks.py +16 -6
- {sql_blocks-0.1.1 → sql_blocks-0.1.3/sql_blocks.egg-info}/PKG-INFO +5 -5
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/LICENSE +0 -0
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/setup.cfg +0 -0
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/sql_blocks/__init__.py +0 -0
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/sql_blocks.egg-info/SOURCES.txt +0 -0
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/sql_blocks.egg-info/dependency_links.txt +0 -0
- {sql_blocks-0.1.1 → sql_blocks-0.1.3}/sql_blocks.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
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
|
@@ -45,7 +45,7 @@ You can specify your own alias: `a = Select('Actor a')`
|
|
45
45
|
'Product',
|
46
46
|
due_date=NamedField(
|
47
47
|
'YEAR_ref',
|
48
|
-
ExpressionField('extract(year from
|
48
|
+
ExpressionField('extract(year from {f})') # <<---
|
49
49
|
)
|
50
50
|
)
|
51
51
|
```
|
@@ -302,7 +302,7 @@ best_movies = SelectIN(
|
|
302
302
|
rate=[GroupBy, Having.avg(Where.gt(4.5))]
|
303
303
|
)
|
304
304
|
m1 = Select(
|
305
|
-
Movie=Table('title,release_date),
|
305
|
+
Movie=Table('title,release_date'),
|
306
306
|
id=best_movies
|
307
307
|
)
|
308
308
|
|
@@ -320,9 +320,9 @@ m2 = Select(
|
|
320
320
|
Select(
|
321
321
|
'Product',
|
322
322
|
label=Case('price').when(
|
323
|
-
lt(50), 'cheap'
|
323
|
+
Where.lt(50), 'cheap'
|
324
324
|
).when(
|
325
|
-
gt(100), 'expensive'
|
325
|
+
Where.gt(100), 'expensive'
|
326
326
|
).else_value(
|
327
327
|
'normal'
|
328
328
|
)
|
@@ -30,7 +30,7 @@ You can specify your own alias: `a = Select('Actor a')`
|
|
30
30
|
'Product',
|
31
31
|
due_date=NamedField(
|
32
32
|
'YEAR_ref',
|
33
|
-
ExpressionField('extract(year from
|
33
|
+
ExpressionField('extract(year from {f})') # <<---
|
34
34
|
)
|
35
35
|
)
|
36
36
|
```
|
@@ -287,7 +287,7 @@ best_movies = SelectIN(
|
|
287
287
|
rate=[GroupBy, Having.avg(Where.gt(4.5))]
|
288
288
|
)
|
289
289
|
m1 = Select(
|
290
|
-
Movie=Table('title,release_date),
|
290
|
+
Movie=Table('title,release_date'),
|
291
291
|
id=best_movies
|
292
292
|
)
|
293
293
|
|
@@ -305,9 +305,9 @@ m2 = Select(
|
|
305
305
|
Select(
|
306
306
|
'Product',
|
307
307
|
label=Case('price').when(
|
308
|
-
lt(50), 'cheap'
|
308
|
+
Where.lt(50), 'cheap'
|
309
309
|
).when(
|
310
|
-
gt(100), 'expensive'
|
310
|
+
Where.gt(100), 'expensive'
|
311
311
|
).else_value(
|
312
312
|
'normal'
|
313
313
|
)
|
@@ -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
|
-
|
8
|
+
DISTINCT_PREFX = f'(DISTINCT|distinct)|{PATTERN_PREFIX}'
|
9
9
|
|
10
10
|
KEYWORD = {
|
11
|
-
'SELECT': (',{}', 'SELECT *',
|
11
|
+
'SELECT': (',{}', 'SELECT *', DISTINCT_PREFX),
|
12
12
|
'FROM': ('{}', '', PATTERN_SUFFIX),
|
13
13
|
'WHERE': ('{}AND ', '', ''),
|
14
14
|
'GROUP BY': (',{}', '', SUFFIX_AND_PRE),
|
@@ -74,6 +74,7 @@ class SQLObject:
|
|
74
74
|
if symmetrical:
|
75
75
|
fld = fld.lower()
|
76
76
|
return fld.strip()
|
77
|
+
# if key == SELECT and re.search(' as | AS ', fld)
|
77
78
|
pattern = KEYWORD[key][2]
|
78
79
|
if key == WHERE and symmetrical:
|
79
80
|
pattern = f'{PATTERN_PREFIX}| '
|
@@ -160,11 +161,20 @@ class ExpressionField:
|
|
160
161
|
main.values.setdefault(SELECT, []).append(self.format(name, main))
|
161
162
|
|
162
163
|
def format(self, name: str, main: SQLObject) -> str:
|
163
|
-
|
164
|
+
"""
|
165
|
+
Replace special chars...
|
166
|
+
{af} or {a.f} or % = alias and field
|
167
|
+
{a} = alias
|
168
|
+
{f} = field
|
169
|
+
{t} = table name
|
170
|
+
"""
|
171
|
+
return re.sub('{af}|{a.f}|[%]', '{a}.{f}', self.expr).format(
|
172
|
+
a=main.alias, f=name, t=main.table_name
|
173
|
+
)
|
164
174
|
|
165
175
|
|
166
176
|
class Table:
|
167
|
-
def __init__(self, fields: list
|
177
|
+
def __init__(self, fields: list=[]):
|
168
178
|
if isinstance(fields, str):
|
169
179
|
fields = [f.strip() for f in fields.split(',')]
|
170
180
|
self.fields = fields
|
@@ -263,7 +273,7 @@ class Not(Where):
|
|
263
273
|
|
264
274
|
@classmethod
|
265
275
|
def eq(cls, value):
|
266
|
-
return Where
|
276
|
+
return Where(expr=f'<> {quoted(value)}')
|
267
277
|
|
268
278
|
|
269
279
|
class Case:
|
@@ -520,7 +530,7 @@ class Select(SQLObject):
|
|
520
530
|
if '=' in item:
|
521
531
|
a1, f1, a2, f2 = [r.strip() for r in re.split('[().=]', item) if r]
|
522
532
|
obj1: SQLObject = result[a1]
|
523
|
-
obj2:SQLObject = result[a2]
|
533
|
+
obj2: SQLObject = result[a2]
|
524
534
|
PrimaryKey.add(f2, obj2)
|
525
535
|
ForeignKey(obj2.table_name).add(f1, obj1)
|
526
536
|
else:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
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
|
@@ -45,7 +45,7 @@ You can specify your own alias: `a = Select('Actor a')`
|
|
45
45
|
'Product',
|
46
46
|
due_date=NamedField(
|
47
47
|
'YEAR_ref',
|
48
|
-
ExpressionField('extract(year from
|
48
|
+
ExpressionField('extract(year from {f})') # <<---
|
49
49
|
)
|
50
50
|
)
|
51
51
|
```
|
@@ -302,7 +302,7 @@ best_movies = SelectIN(
|
|
302
302
|
rate=[GroupBy, Having.avg(Where.gt(4.5))]
|
303
303
|
)
|
304
304
|
m1 = Select(
|
305
|
-
Movie=Table('title,release_date),
|
305
|
+
Movie=Table('title,release_date'),
|
306
306
|
id=best_movies
|
307
307
|
)
|
308
308
|
|
@@ -320,9 +320,9 @@ m2 = Select(
|
|
320
320
|
Select(
|
321
321
|
'Product',
|
322
322
|
label=Case('price').when(
|
323
|
-
lt(50), 'cheap'
|
323
|
+
Where.lt(50), 'cheap'
|
324
324
|
).when(
|
325
|
-
gt(100), 'expensive'
|
325
|
+
Where.gt(100), 'expensive'
|
326
326
|
).else_value(
|
327
327
|
'normal'
|
328
328
|
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|