sql-blocks 1.25.1301__py3-none-any.whl → 1.25.1801__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 +37 -8
- {sql_blocks-1.25.1301.dist-info → sql_blocks-1.25.1801.dist-info}/METADATA +1 -1
- sql_blocks-1.25.1801.dist-info/RECORD +7 -0
- sql_blocks-1.25.1301.dist-info/RECORD +0 -7
- {sql_blocks-1.25.1301.dist-info → sql_blocks-1.25.1801.dist-info}/LICENSE +0 -0
- {sql_blocks-1.25.1301.dist-info → sql_blocks-1.25.1801.dist-info}/WHEEL +0 -0
- {sql_blocks-1.25.1301.dist-info → sql_blocks-1.25.1801.dist-info}/top_level.txt +0 -0
sql_blocks/sql_blocks.py
CHANGED
@@ -121,7 +121,8 @@ class SQLObject:
|
|
121
121
|
|
122
122
|
SQL_CONST_SYSDATE = 'SYSDATE'
|
123
123
|
SQL_CONST_CURR_DATE = 'Current_date'
|
124
|
-
|
124
|
+
SQL_ROW_NUM = 'ROWNUM'
|
125
|
+
SQL_CONSTS = [SQL_CONST_SYSDATE, SQL_CONST_CURR_DATE, SQL_ROW_NUM]
|
125
126
|
|
126
127
|
|
127
128
|
class Field:
|
@@ -654,7 +655,7 @@ class Rule:
|
|
654
655
|
...
|
655
656
|
|
656
657
|
class QueryLanguage:
|
657
|
-
pattern = '{select}{_from}{where}{group_by}{order_by}'
|
658
|
+
pattern = '{select}{_from}{where}{group_by}{order_by}{limit}'
|
658
659
|
has_default = {key: bool(key == SELECT) for key in KEYWORD}
|
659
660
|
|
660
661
|
@staticmethod
|
@@ -682,13 +683,16 @@ class QueryLanguage:
|
|
682
683
|
def set_group(self, values: list) -> str:
|
683
684
|
return self.join_with_tabs(values, ',')
|
684
685
|
|
686
|
+
def set_limit(self, values: list) -> str:
|
687
|
+
return self.join_with_tabs(values, ' ')
|
688
|
+
|
685
689
|
def __init__(self, target: 'Select'):
|
686
|
-
self.KEYWORDS = [SELECT, FROM, WHERE, GROUP_BY, ORDER_BY]
|
690
|
+
self.KEYWORDS = [SELECT, FROM, WHERE, GROUP_BY, ORDER_BY, LIMIT]
|
687
691
|
self.TABULATION = '\n\t' if target.break_lines else ' '
|
688
692
|
self.LINE_BREAK = '\n' if target.break_lines else ' '
|
689
693
|
self.TOKEN_METHODS = {
|
690
694
|
SELECT: self.add_field, FROM: self.get_tables,
|
691
|
-
WHERE: self.extract_conditions,
|
695
|
+
WHERE: self.extract_conditions, LIMIT: self.set_limit,
|
692
696
|
ORDER_BY: self.sort_by, GROUP_BY: self.set_group,
|
693
697
|
}
|
694
698
|
self.result = {}
|
@@ -1337,10 +1341,21 @@ class Select(SQLObject):
|
|
1337
1341
|
return True
|
1338
1342
|
|
1339
1343
|
def limit(self, row_count: int=100, offset: int=0):
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
+
if Function.dialect == Dialect.SQL_SERVER:
|
1345
|
+
fields = self.values.get(SELECT)
|
1346
|
+
if fields:
|
1347
|
+
fields[0] = f'SELECT TOP({row_count}) {fields[0]}'
|
1348
|
+
else:
|
1349
|
+
self.values[SELECT] = [f'SELECT TOP({row_count}) *']
|
1350
|
+
return self
|
1351
|
+
if Function.dialect == Dialect.ORACLE:
|
1352
|
+
Where.gte(row_count).add(SQL_ROW_NUM, self)
|
1353
|
+
if offset > 0:
|
1354
|
+
Where.lte(row_count+offset).add(SQL_ROW_NUM, self)
|
1355
|
+
return self
|
1356
|
+
self.values[LIMIT] = ['{}{}'.format(
|
1357
|
+
row_count, f' OFFSET {offset}' if offset > 0 else ''
|
1358
|
+
)]
|
1344
1359
|
return self
|
1345
1360
|
|
1346
1361
|
def match(self, field: str, key: str) -> bool:
|
@@ -1526,3 +1541,17 @@ def detect(text: str, join_queries: bool = True) -> Select:
|
|
1526
1541
|
for query in query_list[1:]:
|
1527
1542
|
result += query
|
1528
1543
|
return result
|
1544
|
+
|
1545
|
+
|
1546
|
+
if __name__ == '__main__':
|
1547
|
+
for dialect in Dialect:
|
1548
|
+
Function.dialect = dialect
|
1549
|
+
print(f'--------------{dialect.name}--------------')
|
1550
|
+
query = Select(
|
1551
|
+
'Installments',
|
1552
|
+
_=DateDiff(
|
1553
|
+
Current_Date(),
|
1554
|
+
'due_date'
|
1555
|
+
).As('elapsed_time')
|
1556
|
+
).limit(10)
|
1557
|
+
print(query)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 1.25.
|
3
|
+
Version: 1.25.1801
|
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
|
@@ -0,0 +1,7 @@
|
|
1
|
+
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
+
sql_blocks/sql_blocks.py,sha256=iFS3drlQaazFkbBBFIH58RPZt4Lhe6R2Xqi_Ujef7Bg,51893
|
3
|
+
sql_blocks-1.25.1801.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
+
sql_blocks-1.25.1801.dist-info/METADATA,sha256=WnwFnhle4YXNyeC6dBVAnQmUqJiboT1CDhbvRHOmEQY,15027
|
5
|
+
sql_blocks-1.25.1801.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
sql_blocks-1.25.1801.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
+
sql_blocks-1.25.1801.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
-
sql_blocks/sql_blocks.py,sha256=XDjB6YpjJ4ojsHylPt8jGCVt3dViFPKLzE_hbVJwNMo,50844
|
3
|
-
sql_blocks-1.25.1301.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
-
sql_blocks-1.25.1301.dist-info/METADATA,sha256=NqoWfNLGyyB32vgldi7qEC3xI6PiJ7Z25x6K5s8yyo0,15027
|
5
|
-
sql_blocks-1.25.1301.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
sql_blocks-1.25.1301.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
-
sql_blocks-1.25.1301.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|