sql-blocks 0.2.0__tar.gz → 0.2.1__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.0
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, like this...
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=like("Oscar")
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=contains(['space', 'monster', 'gore'])
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 like this:
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],
@@ -9,7 +9,7 @@ _Note that an alias "act" has been added._
9
9
  You can specify your own alias: `a = Select('Actor a')`
10
10
 
11
11
  ---
12
- ### 2 - You can also add a field, like this...
12
+ ### 2 - You can also add a field, contains this...
13
13
 
14
14
  * a = Select('Actor a', **name=Field**)
15
15
 
@@ -78,7 +78,7 @@ query = Select('Movie m', title=Field,
78
78
  ```
79
79
  OR=Options(
80
80
  genre=eq("Sci-Fi"),
81
- awards=like("Oscar")
81
+ awards=contains("Oscar")
82
82
  )
83
83
  ```
84
84
  > Could be AND=Options(...)
@@ -90,7 +90,7 @@ based_on_book=Not.is_null()
90
90
 
91
91
  3.5 -- List of values
92
92
  ```
93
- hash_tag=contains(['space', 'monster', 'gore'])
93
+ hash_tag=inside(['space', 'monster', 'gore'])
94
94
  ```
95
95
 
96
96
  ---
@@ -98,7 +98,7 @@ hash_tag=contains(['space', 'monster', 'gore'])
98
98
 
99
99
  * m = Select('Movie m' release_date=[Field, OrderBy])
100
100
  - This means that the field will appear in the results and also that the query will be ordered by that field.
101
- * Applying **GROUP BY** to item 3.2, it would look like this:
101
+ * Applying **GROUP BY** to item 3.2, it would look contains this:
102
102
  ```
103
103
  SelectIN(
104
104
  'Review r', movie=[GroupBy, Distinct],
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sql_blocks"
3
- version = "0.2.0"
3
+ version = "0.2.1"
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.0',
6
+ version = '0.2.1',
7
7
  author = 'Júlio Cascalles',
8
8
  author_email = 'julio.cascalles@outlook.com',
9
9
  packages = ['sql_blocks'],
@@ -247,7 +247,7 @@ class Where:
247
247
  return cls.__constructor('=', value)
248
248
 
249
249
  @classmethod
250
- def like(cls, value: str):
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 contains(cls, values):
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, like, gt, gte, lt, lte, is_null, contains = (
285
+ eq, contains, gt, gte, lt, lte, is_null, inside = (
286
286
  getattr(Where, method) for method in
287
- ('eq', 'like', 'gt', 'gte', 'lt', 'lte', 'is_null', 'contains')
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
- if self.table_name.lower() == other.table_name.lower():
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
- self.update_values(key, other.values.get(key, []))
453
- return self
454
- foreign_field, primary_key = ForeignKey.find(self, other)
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, self)
458
+ foreign_field, primary_key = ForeignKey.find(other, query)
457
459
  if foreign_field:
458
460
  if primary_key:
459
- PrimaryKey.add(primary_key, self)
460
- self.add(foreign_field, other)
461
+ PrimaryKey.add(primary_key, query)
462
+ query.add(foreign_field, other)
461
463
  return other
462
- raise ValueError(f'No relationship found between {self.table_name} and {other.table_name}.')
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, self)
466
- return self
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.contains(self).add(name, main)
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.0
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, like this...
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=like("Oscar")
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=contains(['space', 'monster', 'gore'])
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 like this:
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],
File without changes
File without changes