Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhangyuan/sqlupy
https://github.com/zhangyuan/sqlupy
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/zhangyuan/sqlupy
- Owner: zhangyuan
- License: mit
- Created: 2022-06-29T06:34:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-04T15:01:07.000Z (over 2 years ago)
- Last Synced: 2024-10-27T14:35:27.839Z (3 months ago)
- Language: Rust
- Size: 35.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sqlupy
## Install
```
pip install sqlupy
```## Example
```
>>> import sqlupy
>>> sqlupy.parse("pg", "select * from users")
[{'Query': {'body': {'Select': {'cluster_by': [], 'distinct': False, 'distribute_by': [], 'from': [{'joins': [], 'relation': {'Table': {'alias': None, 'args': None, 'name': [{'quote_style': None, 'value': 'users'}], 'with_hints': []}}}], 'group_by': [], 'having': None, 'into': None, 'lateral_views': [], 'projection': ['Wildcard'], 'qualify': None, 'selection': None, 'sort_by': [], 'top': None}}, 'fetch': None, 'limit': None, 'lock': None, 'offset': None, 'order_by': [], 'with': None}}]
>>> sqlupy.parse("pg", "SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary DESC) from empsalary")
[{'Query': {'body': {'Select': {'cluster_by': [], 'distinct': False, 'distribute_by': [], 'from': [{'joins': [], 'relation': {'Table': {'alias': None, 'args': None, 'name': [{'quote_style': None, 'value': 'empsalary'}], 'with_hints': []}}}], 'group_by': [], 'having': None, 'into': None, 'lateral_views': [], 'projection': [{'UnnamedExpr': {'Identifier': {'quote_style': None, 'value': 'depname'}}}, {'UnnamedExpr': {'Identifier': {'quote_style': None, 'value': 'empno'}}}, {'UnnamedExpr': {'Identifier': {'quote_style': None, 'value': 'salary'}}}, {'UnnamedExpr': {'Function': {'args': [], 'distinct': False, 'name': [{'quote_style': None, 'value': 'rank'}], 'over': {'order_by': [{'asc': False, 'expr': {'Identifier': {'quote_style': None, 'value': 'salary'}}, 'nulls_first': None}], 'partition_by': [{'Identifier': {'quote_style': None, 'value': 'depname'}}], 'window_frame': None}}}}], 'qualify': None, 'selection': None, 'sort_by': [], 'top': None}}, 'fetch': None, 'limit': None, 'lock': None, 'offset': None, 'order_by': [], 'with': None}}]
```