sql-blocks 0.2.0__py3-none-any.whl → 0.2.1__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 +17 -15
- {sql_blocks-0.2.0.dist-info → sql_blocks-0.2.1.dist-info}/METADATA +5 -5
- sql_blocks-0.2.1.dist-info/RECORD +7 -0
- sql_blocks-0.2.0.dist-info/RECORD +0 -7
- {sql_blocks-0.2.0.dist-info → sql_blocks-0.2.1.dist-info}/LICENSE +0 -0
- {sql_blocks-0.2.0.dist-info → sql_blocks-0.2.1.dist-info}/WHEEL +0 -0
- {sql_blocks-0.2.0.dist-info → sql_blocks-0.2.1.dist-info}/top_level.txt +0 -0
sql_blocks/sql_blocks.py
CHANGED
@@ -247,7 +247,7 @@ class Where:
|
|
247
247
|
return cls.__constructor('=', value)
|
248
248
|
|
249
249
|
@classmethod
|
250
|
-
def
|
250
|
+
def contains(cls, value: str):
|
251
251
|
return cls(f"LIKE '%{value}%'")
|
252
252
|
|
253
253
|
@classmethod
|
@@ -271,7 +271,7 @@ class Where:
|
|
271
271
|
return cls('IS NULL')
|
272
272
|
|
273
273
|
@classmethod
|
274
|
-
def
|
274
|
+
def inside(cls, values):
|
275
275
|
if isinstance(values, list):
|
276
276
|
values = ','.join(quoted(v) for v in values)
|
277
277
|
return cls(f'IN ({values})')
|
@@ -282,9 +282,9 @@ class Where:
|
|
282
282
|
))
|
283
283
|
|
284
284
|
|
285
|
-
eq,
|
285
|
+
eq, contains, gt, gte, lt, lte, is_null, inside = (
|
286
286
|
getattr(Where, method) for method in
|
287
|
-
('eq', '
|
287
|
+
('eq', 'contains', 'gt', 'gte', 'lt', 'lte', 'is_null', 'inside')
|
288
288
|
)
|
289
289
|
|
290
290
|
|
@@ -447,23 +447,25 @@ class Select(SQLObject):
|
|
447
447
|
main.update_values(key, self.values.get(key, []))
|
448
448
|
|
449
449
|
def __add__(self, other: SQLObject):
|
450
|
-
|
450
|
+
from copy import deepcopy
|
451
|
+
query = deepcopy(self)
|
452
|
+
if query.table_name.lower() == other.table_name.lower():
|
451
453
|
for key in USUAL_KEYS:
|
452
|
-
|
453
|
-
return
|
454
|
-
foreign_field, primary_key = ForeignKey.find(
|
454
|
+
query.update_values(key, other.values.get(key, []))
|
455
|
+
return query
|
456
|
+
foreign_field, primary_key = ForeignKey.find(query, other)
|
455
457
|
if not foreign_field:
|
456
|
-
foreign_field, primary_key = ForeignKey.find(other,
|
458
|
+
foreign_field, primary_key = ForeignKey.find(other, query)
|
457
459
|
if foreign_field:
|
458
460
|
if primary_key:
|
459
|
-
PrimaryKey.add(primary_key,
|
460
|
-
|
461
|
+
PrimaryKey.add(primary_key, query)
|
462
|
+
query.add(foreign_field, other)
|
461
463
|
return other
|
462
|
-
raise ValueError(f'No relationship found between {
|
464
|
+
raise ValueError(f'No relationship found between {query.table_name} and {other.table_name}.')
|
463
465
|
elif primary_key:
|
464
466
|
PrimaryKey.add(primary_key, other)
|
465
|
-
other.add(foreign_field,
|
466
|
-
return
|
467
|
+
other.add(foreign_field, query)
|
468
|
+
return query
|
467
469
|
|
468
470
|
def __str__(self) -> str:
|
469
471
|
TABULATION = '\n\t' if self.break_lines else ' '
|
@@ -590,7 +592,7 @@ class SelectIN(Select):
|
|
590
592
|
|
591
593
|
def add(self, name: str, main: SQLObject):
|
592
594
|
self.break_lines = False
|
593
|
-
self.condition_class.
|
595
|
+
self.condition_class.inside(self).add(name, main)
|
594
596
|
|
595
597
|
SubSelect = SelectIN
|
596
598
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.1
|
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
|
@@ -24,7 +24,7 @@ _Note that an alias "act" has been added._
|
|
24
24
|
You can specify your own alias: `a = Select('Actor a')`
|
25
25
|
|
26
26
|
---
|
27
|
-
### 2 - You can also add a field,
|
27
|
+
### 2 - You can also add a field, contains this...
|
28
28
|
|
29
29
|
* a = Select('Actor a', **name=Field**)
|
30
30
|
|
@@ -93,7 +93,7 @@ query = Select('Movie m', title=Field,
|
|
93
93
|
```
|
94
94
|
OR=Options(
|
95
95
|
genre=eq("Sci-Fi"),
|
96
|
-
awards=
|
96
|
+
awards=contains("Oscar")
|
97
97
|
)
|
98
98
|
```
|
99
99
|
> Could be AND=Options(...)
|
@@ -105,7 +105,7 @@ based_on_book=Not.is_null()
|
|
105
105
|
|
106
106
|
3.5 -- List of values
|
107
107
|
```
|
108
|
-
hash_tag=
|
108
|
+
hash_tag=inside(['space', 'monster', 'gore'])
|
109
109
|
```
|
110
110
|
|
111
111
|
---
|
@@ -113,7 +113,7 @@ hash_tag=contains(['space', 'monster', 'gore'])
|
|
113
113
|
|
114
114
|
* m = Select('Movie m' release_date=[Field, OrderBy])
|
115
115
|
- This means that the field will appear in the results and also that the query will be ordered by that field.
|
116
|
-
* Applying **GROUP BY** to item 3.2, it would look
|
116
|
+
* Applying **GROUP BY** to item 3.2, it would look contains this:
|
117
117
|
```
|
118
118
|
SelectIN(
|
119
119
|
'Review r', movie=[GroupBy, Distinct],
|
@@ -0,0 +1,7 @@
|
|
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,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
-
sql_blocks/sql_blocks.py,sha256=Fg7yPeASygx7c7Nct5yKurxRrnjVGsvp4RnR93Wwems,21519
|
3
|
-
sql_blocks-0.2.0.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
-
sql_blocks-0.2.0.dist-info/METADATA,sha256=CU4oSLqoycnvhkPROx_SSbj9zJjCwwz4JoePIgk4wSE,8794
|
5
|
-
sql_blocks-0.2.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
sql_blocks-0.2.0.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
-
sql_blocks-0.2.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|