sql-blocks 0.0.8__tar.gz → 0.0.9__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.8/sql_blocks.egg-info → sql_blocks-0.0.9}/PKG-INFO +15 -1
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/README.md +14 -0
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/pyproject.toml +1 -1
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/setup.py +1 -1
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/sql_blocks/sql_blocks.py +12 -3
- {sql_blocks-0.0.8 → sql_blocks-0.0.9/sql_blocks.egg-info}/PKG-INFO +15 -1
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/LICENSE +0 -0
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/setup.cfg +0 -0
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/sql_blocks/__init__.py +0 -0
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/sql_blocks.egg-info/SOURCES.txt +0 -0
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/sql_blocks.egg-info/dependency_links.txt +0 -0
- {sql_blocks-0.0.8 → sql_blocks-0.0.9}/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.9
|
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
|
@@ -38,6 +38,20 @@ You can specify your own alias: `a = Select('Actor a')`
|
|
38
38
|
name=NamedField('actors_name', Distinct)
|
39
39
|
)
|
40
40
|
|
41
|
+
|
42
|
+
2.1 -- Using expression as a field:
|
43
|
+
```
|
44
|
+
Select(
|
45
|
+
'Product',
|
46
|
+
due_date=NamedField(
|
47
|
+
'YEAR_ref',
|
48
|
+
ExpressionField('extract(year from %)') # <<---
|
49
|
+
)
|
50
|
+
)
|
51
|
+
```
|
52
|
+
...should return:
|
53
|
+
**SELECT extract(year from due_date) as YEAR_ref...**
|
54
|
+
|
41
55
|
---
|
42
56
|
|
43
57
|
### 3 - To set conditions, use **Where**:
|
@@ -23,6 +23,20 @@ You can specify your own alias: `a = Select('Actor a')`
|
|
23
23
|
name=NamedField('actors_name', Distinct)
|
24
24
|
)
|
25
25
|
|
26
|
+
|
27
|
+
2.1 -- Using expression as a field:
|
28
|
+
```
|
29
|
+
Select(
|
30
|
+
'Product',
|
31
|
+
due_date=NamedField(
|
32
|
+
'YEAR_ref',
|
33
|
+
ExpressionField('extract(year from %)') # <<---
|
34
|
+
)
|
35
|
+
)
|
36
|
+
```
|
37
|
+
...should return:
|
38
|
+
**SELECT extract(year from due_date) as YEAR_ref...**
|
39
|
+
|
26
40
|
---
|
27
41
|
|
28
42
|
### 3 - To set conditions, use **Where**:
|
@@ -141,19 +141,28 @@ class Distinct(Field):
|
|
141
141
|
class NamedField:
|
142
142
|
def __init__(self, alias: str, class_type = Field):
|
143
143
|
self.alias = alias
|
144
|
-
if class_type not in [Field] + Field.__subclasses__():
|
145
|
-
raise TypeError('class_type must be a Field (sub)class.')
|
146
144
|
self.class_type = class_type
|
147
145
|
|
148
146
|
def add(self, name: str, main: SQLObject):
|
149
147
|
main.values.setdefault(SELECT, []).append(
|
150
148
|
'{} as {}'.format(
|
151
149
|
self.class_type.format(name, main),
|
152
|
-
self.alias
|
150
|
+
self.alias # --- field alias
|
153
151
|
)
|
154
152
|
)
|
155
153
|
|
156
154
|
|
155
|
+
class ExpressionField:
|
156
|
+
def __init__(self, expr: str):
|
157
|
+
self.expr = expr
|
158
|
+
|
159
|
+
def add(self, name: str, main: SQLObject):
|
160
|
+
main.values.setdefault(SELECT, []).append(self.format)
|
161
|
+
|
162
|
+
def format(self, name: str, main: SQLObject) -> str:
|
163
|
+
return self.expr.replace('%', Field.format(name, main))
|
164
|
+
|
165
|
+
|
157
166
|
class Table:
|
158
167
|
def __init__(self, fields: list | str=[]):
|
159
168
|
if isinstance(fields, str):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.9
|
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
|
@@ -38,6 +38,20 @@ You can specify your own alias: `a = Select('Actor a')`
|
|
38
38
|
name=NamedField('actors_name', Distinct)
|
39
39
|
)
|
40
40
|
|
41
|
+
|
42
|
+
2.1 -- Using expression as a field:
|
43
|
+
```
|
44
|
+
Select(
|
45
|
+
'Product',
|
46
|
+
due_date=NamedField(
|
47
|
+
'YEAR_ref',
|
48
|
+
ExpressionField('extract(year from %)') # <<---
|
49
|
+
)
|
50
|
+
)
|
51
|
+
```
|
52
|
+
...should return:
|
53
|
+
**SELECT extract(year from due_date) as YEAR_ref...**
|
54
|
+
|
41
55
|
---
|
42
56
|
|
43
57
|
### 3 - To set conditions, use **Where**:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|