sql-blocks 0.0.5__tar.gz → 0.0.6__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.0.5/sql_blocks.egg-info → sql_blocks-0.0.6}/PKG-INFO +3 -3
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/README.md +2 -2
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/pyproject.toml +1 -1
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/setup.py +1 -1
- sql_blocks-0.0.6/sql_blocks/__init__.py +1 -0
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/sql_blocks/sql_blocks.py +0 -29
- {sql_blocks-0.0.5 → sql_blocks-0.0.6/sql_blocks.egg-info}/PKG-INFO +3 -3
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/tests/tests.py +18 -7
- sql_blocks-0.0.5/sql_blocks/__init__.py +0 -1
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/LICENSE +0 -0
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/setup.cfg +0 -0
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/sql_blocks.egg-info/SOURCES.txt +0 -0
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/sql_blocks.egg-info/dependency_links.txt +0 -0
- {sql_blocks-0.0.5 → sql_blocks-0.0.6}/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.0.
|
3
|
+
Version: 0.0.6
|
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
|
@@ -306,9 +306,9 @@ m2 = Select(
|
|
306
306
|
Select(
|
307
307
|
'Product',
|
308
308
|
label=Case('price').when(
|
309
|
-
lt(50), 'cheap'
|
309
|
+
Where.lt(50), 'cheap'
|
310
310
|
).when(
|
311
|
-
gt(100), 'expensive'
|
311
|
+
Where.gt(100), 'expensive'
|
312
312
|
).else_value(
|
313
313
|
'normal'
|
314
314
|
)
|
@@ -0,0 +1 @@
|
|
1
|
+
from sql_blocks.sql_blocks import *
|
@@ -511,32 +511,3 @@ SubSelect = SelectIN
|
|
511
511
|
|
512
512
|
class NotSelectIN(SelectIN):
|
513
513
|
condition_class = Not
|
514
|
-
|
515
|
-
|
516
|
-
if __name__ == "__main__":
|
517
|
-
query_list = Select.parse("""
|
518
|
-
SELECT
|
519
|
-
cas.role,
|
520
|
-
m.title,
|
521
|
-
m.release_date,
|
522
|
-
a.name as actors_name
|
523
|
-
FROM
|
524
|
-
Actor a
|
525
|
-
LEFT JOIN Cast cas ON (a.cast = cas.id)
|
526
|
-
LEFT JOIN Movie m ON (cas.movie = m.id)
|
527
|
-
WHERE
|
528
|
-
m.genre NOT in (SELECT g.id from Genres g where g.name in ('sci-fi', 'horror', 'distopia'))
|
529
|
-
AND (m.hashtag = '#cult' OR m.awards LIKE '%Oscar%')
|
530
|
-
AND m.id IN (select DISTINCT r.movie FROM Review r GROUP BY r.movie HAVING Avg(r.rate) > 4.5)
|
531
|
-
AND a.age <= 69 AND a.age >= 45
|
532
|
-
ORDER BY
|
533
|
-
m.release_date
|
534
|
-
""")
|
535
|
-
for query in query_list:
|
536
|
-
descr = ' {} ({}) '.format(
|
537
|
-
query.table_name,
|
538
|
-
query.__class__.__name__
|
539
|
-
)
|
540
|
-
print(descr.center(50, '-'))
|
541
|
-
print(query)
|
542
|
-
print('='*50)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.6
|
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
|
@@ -306,9 +306,9 @@ m2 = Select(
|
|
306
306
|
Select(
|
307
307
|
'Product',
|
308
308
|
label=Case('price').when(
|
309
|
-
lt(50), 'cheap'
|
309
|
+
Where.lt(50), 'cheap'
|
310
310
|
).when(
|
311
|
-
gt(100), 'expensive'
|
311
|
+
Where.gt(100), 'expensive'
|
312
312
|
).else_value(
|
313
313
|
'normal'
|
314
314
|
)
|
@@ -4,8 +4,8 @@ from sql_blocks.sql_blocks import *
|
|
4
4
|
Select.join_type = JoinType.LEFT
|
5
5
|
OrderBy.sort = SortType.DESC
|
6
6
|
|
7
|
-
def best_movies() ->
|
8
|
-
return
|
7
|
+
def best_movies() -> SelectIN:
|
8
|
+
return SelectIN(
|
9
9
|
'Review r', movie=[GroupBy, Distinct], rate=Having.avg(Where.gt(4.5))
|
10
10
|
)
|
11
11
|
|
@@ -35,7 +35,7 @@ def query_reference() -> Select:
|
|
35
35
|
'Movie m', title=Field,
|
36
36
|
release_date=[OrderBy, Field],
|
37
37
|
id=[
|
38
|
-
|
38
|
+
SelectIN(
|
39
39
|
'Review r', movie=[GroupBy, Distinct],
|
40
40
|
rate=Having.avg(Where.gt(4.5))
|
41
41
|
),
|
@@ -48,8 +48,15 @@ def query_reference() -> Select:
|
|
48
48
|
name=NamedField('actors_name'),
|
49
49
|
) # ----------- Actor
|
50
50
|
|
51
|
-
|
52
|
-
|
51
|
+
SINGLE_CONDITION_GENRE = "( m.genre = 'Sci-Fi' OR m.awards LIKE '%Oscar%' )"
|
52
|
+
SUB_QUERIES_CONDITIONS = """
|
53
|
+
m.genre NOT in (SELECT g.id from Genres g where g.name in ('sci-fi', 'horror', 'distopia'))
|
54
|
+
AND (m.hashtag = '#cult' OR m.awards LIKE '%Oscar%')
|
55
|
+
AND m.id IN (select DISTINCT r.movie FROM Review r GROUP BY r.movie HAVING Avg(r.rate) > 4.5)
|
56
|
+
"""
|
57
|
+
|
58
|
+
def single_text_to_objects(conditions: str=SINGLE_CONDITION_GENRE):
|
59
|
+
return Select.parse(f'''
|
53
60
|
SELECT
|
54
61
|
cas.role,
|
55
62
|
m.title,
|
@@ -60,7 +67,7 @@ def single_text_to_objects():
|
|
60
67
|
LEFT JOIN Cast cas ON (a.cast = cas.id)
|
61
68
|
LEFT JOIN Movie m ON (cas.movie = m.id)
|
62
69
|
WHERE
|
63
|
-
|
70
|
+
{conditions}
|
64
71
|
AND a.age <= 69 AND a.age >= 45
|
65
72
|
ORDER BY
|
66
73
|
m.release_date DESC
|
@@ -96,4 +103,8 @@ def select_product() -> Select:
|
|
96
103
|
Product=Table('name,promotional,stock_amount,expiration_date'),
|
97
104
|
category=[Where.list([6,14,29,35,78]),Field], EAN=[Field, OrderBy],
|
98
105
|
price=[Where.lt(357.46),Field], status=Where('= Last_st')
|
99
|
-
)
|
106
|
+
)
|
107
|
+
|
108
|
+
def extract_subqueries() -> dict:
|
109
|
+
query_list = single_text_to_objects(SUB_QUERIES_CONDITIONS)
|
110
|
+
return {query.table_name: query for query in query_list}
|
@@ -1 +0,0 @@
|
|
1
|
-
from sql_blocks import *
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|