sql-blocks 1.25.30011644__py3-none-any.whl → 1.25.30012339__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 +24 -23
- {sql_blocks-1.25.30011644.dist-info → sql_blocks-1.25.30012339.dist-info}/METADATA +5 -8
- sql_blocks-1.25.30012339.dist-info/RECORD +7 -0
- sql_blocks-1.25.30011644.dist-info/RECORD +0 -7
- {sql_blocks-1.25.30011644.dist-info → sql_blocks-1.25.30012339.dist-info}/LICENSE +0 -0
- {sql_blocks-1.25.30011644.dist-info → sql_blocks-1.25.30012339.dist-info}/WHEEL +0 -0
- {sql_blocks-1.25.30011644.dist-info → sql_blocks-1.25.30012339.dist-info}/top_level.txt +0 -0
sql_blocks/sql_blocks.py
CHANGED
@@ -1457,33 +1457,34 @@ class NotSelectIN(SelectIN):
|
|
1457
1457
|
condition_class = Not
|
1458
1458
|
|
1459
1459
|
|
1460
|
-
class CTE:
|
1460
|
+
class CTE(Select):
|
1461
1461
|
prefix = ''
|
1462
1462
|
|
1463
|
-
def __init__(self,
|
1464
|
-
|
1463
|
+
def __init__(self, table_name: str, query_list: list[Select]):
|
1464
|
+
super().__init__(table_name)
|
1465
1465
|
for query in query_list:
|
1466
1466
|
query.break_lines = False
|
1467
1467
|
self.query_list = query_list
|
1468
1468
|
|
1469
|
-
def format(self, query: Select) -> str:
|
1470
|
-
LINE_MAX_SIZE = 50
|
1471
|
-
result, line = [], ''
|
1472
|
-
for word in str(query).split(' '):
|
1473
|
-
if len(line) >= LINE_MAX_SIZE and word in KEYWORD:
|
1474
|
-
result.append(line)
|
1475
|
-
line = ''
|
1476
|
-
line += word + ' '
|
1477
|
-
if line:
|
1478
|
-
result.append(line)
|
1479
|
-
return '\n\t'.join(result)
|
1480
|
-
|
1481
1469
|
def __str__(self) -> str:
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
)
|
1470
|
+
# ---------------------------------------------------------
|
1471
|
+
def justify(query: Select) -> str:
|
1472
|
+
LINE_MAX_SIZE = 50
|
1473
|
+
result, line = [], ''
|
1474
|
+
for word in str(query).split(' '):
|
1475
|
+
if len(line) >= LINE_MAX_SIZE and word in KEYWORD:
|
1476
|
+
result.append(line)
|
1477
|
+
line = ''
|
1478
|
+
line += word + ' '
|
1479
|
+
if line:
|
1480
|
+
result.append(line)
|
1481
|
+
return '\n\t'.join(result)
|
1482
|
+
# ---------------------------------------------------------
|
1483
|
+
return 'WITH {}{} AS (\n\t{}\n){}'.format(
|
1484
|
+
self.prefix, self.table_name,
|
1485
|
+
'\nUNION ALL\n\t'.join(
|
1486
|
+
justify(q) for q in self.query_list
|
1487
|
+
), super().__str__()
|
1487
1488
|
)
|
1488
1489
|
|
1489
1490
|
class Recursive(CTE):
|
@@ -1491,8 +1492,8 @@ class Recursive(CTE):
|
|
1491
1492
|
|
1492
1493
|
def __str__(self) -> str:
|
1493
1494
|
if len(self.query_list) > 1:
|
1494
|
-
|
1495
|
-
|
1495
|
+
self.query_list[-1].values[FROM].append(
|
1496
|
+
f', {self.table_name} {self.alias}')
|
1496
1497
|
return super().__str__()
|
1497
1498
|
|
1498
1499
|
|
@@ -1623,7 +1624,7 @@ def detect(text: str, join_queries: bool = True) -> Select | list[Select]:
|
|
1623
1624
|
continue
|
1624
1625
|
pos = [ f.span() for f in re.finditer(fr'({table})[(]', text) ]
|
1625
1626
|
for begin, end in pos[::-1]:
|
1626
|
-
new_name = f'{table}_{count}' # See set_table (line
|
1627
|
+
new_name = f'{table}_{count}' # See set_table (line 55)
|
1627
1628
|
Select.EQUIVALENT_NAMES[new_name] = table
|
1628
1629
|
text = text[:begin] + new_name + '(' + text[end:]
|
1629
1630
|
count -= 1
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 1.25.
|
3
|
+
Version: 1.25.30012339
|
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
|
@@ -98,10 +98,7 @@ query = Select('Movie m', title=Field,
|
|
98
98
|
awards=contains("Oscar")
|
99
99
|
)
|
100
100
|
AND=Options(
|
101
|
-
..., name=
|
102
|
-
'Chris',
|
103
|
-
Position.StartsWith
|
104
|
-
)
|
101
|
+
..., name=startswith('Chris')
|
105
102
|
)
|
106
103
|
```
|
107
104
|
|
@@ -175,8 +172,8 @@ FROM
|
|
175
172
|
artist.name as artist_name,
|
176
173
|
album.year_recorded
|
177
174
|
FROM
|
178
|
-
|
179
|
-
,
|
175
|
+
Album album
|
176
|
+
,Singer artist
|
180
177
|
WHERE
|
181
178
|
(album.artist_id = artist.id)
|
182
179
|
|
@@ -412,7 +409,7 @@ m2 = Select(
|
|
412
409
|
query = Select(
|
413
410
|
'Installments i', due_date=Field, customer=Select(
|
414
411
|
'Customer c', id=PrimaryKey,
|
415
|
-
name=
|
412
|
+
name=endswith('Smith')
|
416
413
|
)
|
417
414
|
)
|
418
415
|
print(query)
|
@@ -0,0 +1,7 @@
|
|
1
|
+
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
+
sql_blocks/sql_blocks.py,sha256=TSrqjpP41uyocxLpTePI2JzSJorxbFB_jjLfWkHmnJ0,54584
|
3
|
+
sql_blocks-1.25.30012339.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
+
sql_blocks-1.25.30012339.dist-info/METADATA,sha256=0nqWca0uwfqNns6xVIJAB_uR1KMjPnUUgrJHvBPX7bg,16753
|
5
|
+
sql_blocks-1.25.30012339.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
sql_blocks-1.25.30012339.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
+
sql_blocks-1.25.30012339.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
-
sql_blocks/sql_blocks.py,sha256=2R4VoSZUHTb1gSZwKjtNfkjxeH8G1dKYuDpuKv-UP7E,54430
|
3
|
-
sql_blocks-1.25.30011644.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
-
sql_blocks-1.25.30011644.dist-info/METADATA,sha256=2Q1naQygxXqw87DTc70LyLjs8uWK95v0CWu5B9qHLlQ,16884
|
5
|
-
sql_blocks-1.25.30011644.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
sql_blocks-1.25.30011644.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
-
sql_blocks-1.25.30011644.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|