initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
pip
|
||||
@@ -0,0 +1,175 @@
|
||||
Metadata-Version: 2.5
|
||||
Name: sqlparse
|
||||
Version: 0.6.0
|
||||
Summary: A non-validating SQL parser.
|
||||
Project-URL: Home, https://github.com/andialbrecht/sqlparse
|
||||
Project-URL: Documentation, https://sqlparse.readthedocs.io/
|
||||
Project-URL: Release Notes, https://sqlparse.readthedocs.io/en/latest/changes.html
|
||||
Project-URL: Source, https://github.com/andialbrecht/sqlparse
|
||||
Project-URL: Tracker, https://github.com/andialbrecht/sqlparse/issues
|
||||
Author-email: Andi Albrecht <albrecht.andi@gmail.com>
|
||||
License-File: AUTHORS
|
||||
License-File: LICENSE
|
||||
Classifier: Development Status :: 5 - Production/Stable
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: License :: OSI Approved :: BSD License
|
||||
Classifier: Operating System :: OS Independent
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python :: 3 :: Only
|
||||
Classifier: Programming Language :: Python :: 3.10
|
||||
Classifier: Programming Language :: Python :: 3.11
|
||||
Classifier: Programming Language :: Python :: 3.12
|
||||
Classifier: Programming Language :: Python :: 3.13
|
||||
Classifier: Programming Language :: Python :: 3.14
|
||||
Classifier: Programming Language :: Python :: Implementation :: CPython
|
||||
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
||||
Classifier: Topic :: Database
|
||||
Classifier: Topic :: Software Development
|
||||
Requires-Python: >=3.10
|
||||
Provides-Extra: dev
|
||||
Requires-Dist: build; extra == 'dev'
|
||||
Provides-Extra: doc
|
||||
Requires-Dist: furo; extra == 'doc'
|
||||
Requires-Dist: sphinx; extra == 'doc'
|
||||
Description-Content-Type: text/markdown
|
||||
|
||||
# sqlparse
|
||||
|
||||
[](https://github.com/andialbrecht/sqlparse/actions/workflows/python-app.yml)
|
||||
[](https://codecov.io/gh/andialbrecht/sqlparse)
|
||||
[](https://sqlparse.readthedocs.io/en/latest/)
|
||||
[](https://pypi.org/project/sqlparse)
|
||||
[](https://pypi.org/project/sqlparse)
|
||||
[](https://opensource.org/licenses/BSD-3-Clause)
|
||||
|
||||
A non-validating SQL parser for Python. Split scripts into statements, format
|
||||
them, and walk their token tree.
|
||||
|
||||
sqlparse tokenizes SQL text and groups the parts it recognizes into a tree of
|
||||
statements, clauses, identifiers and expressions. It accepts any input without
|
||||
validating it, and makes no assumptions about a particular SQL dialect, so
|
||||
vendor extensions and templated SQL parse too. It is a building block for
|
||||
formatters, linters, editors and query analysis tools.
|
||||
|
||||
Licensed under the
|
||||
[New BSD license](https://opensource.org/licenses/BSD-3-Clause).
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
pip install sqlparse
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Three module-level functions cover most needs: `split()`, `format()` and
|
||||
`parse()`.
|
||||
|
||||
### Split a script into statements
|
||||
|
||||
```python
|
||||
import sqlparse
|
||||
|
||||
sqlparse.split("select * from foo; select * from bar;")
|
||||
# ['select * from foo;', 'select * from bar;']
|
||||
```
|
||||
|
||||
### Format a statement
|
||||
|
||||
```python
|
||||
print(sqlparse.format("select id,name from users where active=1",
|
||||
reindent=True, keyword_case="upper"))
|
||||
```
|
||||
|
||||
```sql
|
||||
SELECT id,
|
||||
name
|
||||
FROM users
|
||||
WHERE active=1
|
||||
```
|
||||
|
||||
`format()` accepts the same options as the command line, among them
|
||||
`reindent`, `keyword_case`, `strip_comments` and `indent_width`.
|
||||
|
||||
### Parse and inspect a statement
|
||||
|
||||
```python
|
||||
statement = sqlparse.parse("select id, name from users where active = 1")[0]
|
||||
|
||||
print(statement.get_type())
|
||||
for token in statement.tokens:
|
||||
if not token.is_whitespace:
|
||||
print(f"{token.ttype or type(token).__name__!s:20} {token!s}")
|
||||
```
|
||||
|
||||
```
|
||||
SELECT
|
||||
Token.Keyword.DML select
|
||||
IdentifierList id, name
|
||||
Token.Keyword from
|
||||
Identifier users
|
||||
Where where active = 1
|
||||
```
|
||||
|
||||
Tokens with a `ttype` are leaves. The others are groups you can descend into,
|
||||
which is how nested constructs like subqueries and `CASE` expressions are
|
||||
represented. See
|
||||
[Analyzing SQL statements](https://sqlparse.readthedocs.io/en/latest/analyzing.html)
|
||||
for the traversal API.
|
||||
|
||||
## Command line
|
||||
|
||||
Installing sqlparse also provides the `sqlformat` command. It reads from stdin
|
||||
when the filename is `-`, writes to stdout by default, and rewrites files in
|
||||
place with `--in-place`:
|
||||
|
||||
```bash
|
||||
sqlformat --reindent --keywords upper query.sql
|
||||
```
|
||||
|
||||
Run `sqlformat --help` for all formatting options.
|
||||
|
||||
## Pre-commit hook
|
||||
|
||||
Format SQL files on commit with [pre-commit](https://pre-commit.com/):
|
||||
|
||||
```yaml
|
||||
repos:
|
||||
- repo: https://github.com/andialbrecht/sqlparse
|
||||
rev: 0.5.5 # use the latest release
|
||||
hooks:
|
||||
- id: sqlformat
|
||||
args: [--in-place, --reindent, --keywords, upper]
|
||||
```
|
||||
|
||||
The hook defaults to `--in-place --reindent`. When overriding `args`, keep
|
||||
`--in-place`, or the hook writes to stdout and leaves your files unchanged.
|
||||
|
||||
## Links
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| Documentation | <https://sqlparse.readthedocs.io/> |
|
||||
| Release notes | <https://sqlparse.readthedocs.io/en/latest/changes.html> |
|
||||
| Issues | <https://github.com/andialbrecht/sqlparse/issues> |
|
||||
| Discussions | <https://github.com/andialbrecht/sqlparse/discussions> |
|
||||
| Online demo | <https://sqlformat.org/> |
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) to get
|
||||
started.
|
||||
|
||||
sqlparse is maintained in spare time, so it can take a while before an issue or
|
||||
pull request gets a reply. Thanks for your patience. A pull request that comes
|
||||
with tests for the behavior it changes is usually the quickest to review.
|
||||
|
||||
For security issues, please follow [SECURITY.md](SECURITY.md) rather than
|
||||
opening a public issue.
|
||||
|
||||
## License
|
||||
|
||||
sqlparse is licensed under the New BSD license; see [LICENSE](LICENSE) for the
|
||||
full text. Parts of the code are based on [Pygments](https://pygments.org/),
|
||||
written by Georg Brandl and others.
|
||||
@@ -0,0 +1,51 @@
|
||||
../../../bin/sqlformat,sha256=JIJpxczSTGygpR_GM6aMDDu8ZDkyWx0eEWIT0bO65PU,267
|
||||
sqlparse-0.6.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
sqlparse-0.6.0.dist-info/METADATA,sha256=5mAnULQhYTXZp4isU8TKr59FNPn4NHunP5LjdQmxsk8,6048
|
||||
sqlparse-0.6.0.dist-info/RECORD,,
|
||||
sqlparse-0.6.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
||||
sqlparse-0.6.0.dist-info/entry_points.txt,sha256=caB1VVIDXYzEjsQD0qpaPl2CfDFIKnRSPpsK88ne_4M,53
|
||||
sqlparse-0.6.0.dist-info/licenses/AUTHORS,sha256=_uMwpbUWrUmoRTsOpoE8icuOxODzQAeUb276vQJx45k,3648
|
||||
sqlparse-0.6.0.dist-info/licenses/LICENSE,sha256=wZOCNbgNOekxOOrontw69n4Y7LxA0mZSn6V7Lc5CYxA,1537
|
||||
sqlparse/__init__.py,sha256=NK6O9gdzuneDgBbU4D3FegICrqBiJJBDDIpaNMhfIxI,2495
|
||||
sqlparse/__main__.py,sha256=1jhVFLHlZs4NUJoAuHvQQKWgykPVTdgeE8V4XB5WQzw,610
|
||||
sqlparse/__pycache__/__init__.cpython-312.pyc,,
|
||||
sqlparse/__pycache__/__main__.cpython-312.pyc,,
|
||||
sqlparse/__pycache__/cli.cpython-312.pyc,,
|
||||
sqlparse/__pycache__/exceptions.cpython-312.pyc,,
|
||||
sqlparse/__pycache__/formatter.cpython-312.pyc,,
|
||||
sqlparse/__pycache__/keywords.cpython-312.pyc,,
|
||||
sqlparse/__pycache__/lexer.cpython-312.pyc,,
|
||||
sqlparse/__pycache__/sql.cpython-312.pyc,,
|
||||
sqlparse/__pycache__/tokens.cpython-312.pyc,,
|
||||
sqlparse/__pycache__/utils.cpython-312.pyc,,
|
||||
sqlparse/cli.py,sha256=LM_AymzzVAtLEeTCaR-nj4-8uTZyxaN7z1gy1KqldNc,7191
|
||||
sqlparse/engine/__init__.py,sha256=rdtl7F1cvrkbE3ngWkzFhB8rgcYAZJghbCi0L5N24IY,447
|
||||
sqlparse/engine/__pycache__/__init__.cpython-312.pyc,,
|
||||
sqlparse/engine/__pycache__/filter_stack.cpython-312.pyc,,
|
||||
sqlparse/engine/__pycache__/grouping.cpython-312.pyc,,
|
||||
sqlparse/engine/__pycache__/statement_splitter.cpython-312.pyc,,
|
||||
sqlparse/engine/filter_stack.py,sha256=qA0MlaTSN3rDa3aUTsW-G5yXbZt6xnCZlEsKTGMO-Uk,1600
|
||||
sqlparse/engine/grouping.py,sha256=tNer7vxHuwNqjP71BbNXZMT-fGdlUMSDVevRu0aLMqA,16238
|
||||
sqlparse/engine/statement_splitter.py,sha256=msnCtszmRM4jMWtFcmw3boFRjgz9cI2dw0C_BX9GAAg,7732
|
||||
sqlparse/exceptions.py,sha256=QyZ9TKTvzgcmuQ1cJkxAj9SoAw4M02-Bf0CSUNWNDKM,342
|
||||
sqlparse/filters/__init__.py,sha256=GSm3rXN4qsQDz4J4NExWF9WM0VrHdsY0SVl7F9vqKPk,1134
|
||||
sqlparse/filters/__pycache__/__init__.cpython-312.pyc,,
|
||||
sqlparse/filters/__pycache__/aligned_indent.cpython-312.pyc,,
|
||||
sqlparse/filters/__pycache__/others.cpython-312.pyc,,
|
||||
sqlparse/filters/__pycache__/output.cpython-312.pyc,,
|
||||
sqlparse/filters/__pycache__/reindent.cpython-312.pyc,,
|
||||
sqlparse/filters/__pycache__/right_margin.cpython-312.pyc,,
|
||||
sqlparse/filters/__pycache__/tokens.cpython-312.pyc,,
|
||||
sqlparse/filters/aligned_indent.py,sha256=A3SeP-45UTIfY7MsrDysqa2av_XllioKZ79JnUO2C-0,5115
|
||||
sqlparse/filters/others.py,sha256=_K1K7wXzbsY928pc2HErkZXdcCLU6h6Cgb4Tw6OlC8c,6689
|
||||
sqlparse/filters/output.py,sha256=9mArvDbaEKVlmRYS_B2be4mX2GF41urTf1poTx4vzhc,4305
|
||||
sqlparse/filters/reindent.py,sha256=RRsvXMNIwaYOwaNhsyQGcXjtctOtR6vGEBbFyL0UxD4,12009
|
||||
sqlparse/filters/right_margin.py,sha256=sr-nI-JLomWOQLQJglXkQTO9S9J0rrJzb1vHVRh4UZA,1555
|
||||
sqlparse/filters/tokens.py,sha256=CZwDwMzzOdq0qvTRIIic7w59g54QhwFgM2Op9932Zvk,1553
|
||||
sqlparse/formatter.py,sha256=XxnpUFnf91eZN24XPbWDRYk30u4nnsPkdTn0ZriDVio,7686
|
||||
sqlparse/keywords.py,sha256=aBk51CTGD-cOubVD1uS0qI0UF9TuG6maCN5B5sShqbM,35039
|
||||
sqlparse/lexer.py,sha256=hsMt0l4ycxSfbGoWPI_Q29rjmd5JSy4r3-yfT73lgXw,6648
|
||||
sqlparse/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||
sqlparse/sql.py,sha256=no54qw8lwsx0VsgyGMXRTxZWBw7mDDK3Akaia7oQ0Ak,21051
|
||||
sqlparse/tokens.py,sha256=g9iwZMLGboSuRQUHfVLSddC5dv43PkxJOu4-tkhMs0o,1779
|
||||
sqlparse/utils.py,sha256=bKFkat1Ko5wfEIPhD_FvZRMBGG9OJtv9dQLBoZKnboc,3475
|
||||
@@ -0,0 +1,4 @@
|
||||
Wheel-Version: 1.0
|
||||
Generator: hatchling 1.32.0
|
||||
Root-Is-Purelib: true
|
||||
Tag: py3-none-any
|
||||
@@ -0,0 +1,2 @@
|
||||
[console_scripts]
|
||||
sqlformat = sqlparse.__main__:main
|
||||
@@ -0,0 +1,92 @@
|
||||
python-sqlparse is written and maintained by Andi Albrecht <albrecht.andi@gmail.com>.
|
||||
|
||||
This module contains code (namely the lexer and filter mechanism) from
|
||||
the pygments project that was written by Georg Brandl.
|
||||
|
||||
This module contains code (Python 2/3 compatibility) from the six
|
||||
project: https://bitbucket.org/gutworth/six.
|
||||
|
||||
Alphabetical list of contributors:
|
||||
* Adam Greenhall <agreenhall@lyft.com>
|
||||
* Adam Johnson <me@adamj.eu>
|
||||
* Aki Ariga <chezou+github@gmail.com>
|
||||
* Alexander Beedie <ayembee@gmail.com>
|
||||
* Alexey Malyshev <nostrict@gmail.com>
|
||||
* alhudz <al.hudz.k@gmail.com>
|
||||
* ali-tny <aliteeney@googlemail.com>
|
||||
* andrew deryabin <github@djsf.com>
|
||||
* Andrew Tipton <andrew.tipton@compareglobalgroup.com>
|
||||
* atronah <atronah.ds@gmail.com>
|
||||
* casey <casey@cloudera.com>
|
||||
* Cauê Beloni <cbeloni@gmail.com>
|
||||
* Christian Clauss <cclauss@me.com>
|
||||
* chuenchen309 <48723787+chuenchen309@users.noreply.github.com>
|
||||
* circld <circld1@gmail.com>
|
||||
* Corey Zumar <corey.zumar@databricks.com>
|
||||
* Cristian Orellana <cristiano@groupon.com>
|
||||
* Dag Wieers <dag@wieers.com>
|
||||
* Daniel Harding <dharding@living180.net>
|
||||
* Darik Gamble <darik.gamble@gmail.com>
|
||||
* Demetrio92 <Demetrio.Rodriguez.T@gmail.com>
|
||||
* Dennis Taylor <dennis.taylor@clio.com>
|
||||
* Dvořák Václav <Vaclav.Dvorak@ysoft.com>
|
||||
* Erik Cederstrand <erik@adamatics.com>
|
||||
* Florian Bauer <florian.bauer@zmdi.com>
|
||||
* Fredy Wijaya <fredy.wijaya@gmail.com>
|
||||
* Gavin Wahl <gwahl@fusionbox.com>
|
||||
* Georg Traar <georg@crate.io>
|
||||
* griff <70294474+griffatrasgo@users.noreply.github.com>
|
||||
* Hugo van Kemenade <hugovk@users.noreply.github.com>
|
||||
* hurcy <cinyoung.hur@gmail.com>
|
||||
* Ian Robertson <ian.robertson@capitalone.com>
|
||||
* Igor Khrol <igor.khrol@automattic.com>
|
||||
* JacekPliszka <Jacek.Pliszka@gmail.com>
|
||||
* JavierPan <PeterSandwich@users.noreply.github.com>
|
||||
* Jean-Martin Archer <jm@jmartin.ca>
|
||||
* Jesús Leganés Combarro "Piranna" <piranna@gmail.com>
|
||||
* Johannes Hoff <johshoff@gmail.com>
|
||||
* John Bodley <john.bodley@airbnb.com>
|
||||
* Jon Dufresne <jon.dufresne@gmail.com>
|
||||
* Josh Soref <jsoref@users.noreply.github.com>
|
||||
* Kevin Jing Qiu <kevin.jing.qiu@gmail.com>
|
||||
* koljonen <koljonen@outlook.com>
|
||||
* Likai Liu <liulk@likai.org>
|
||||
* Long Le Xich <codenamelxl@users.noreply.github.com>
|
||||
* mathilde.oustlant <mathilde.oustlant@ext.cdiscount.com>
|
||||
* Michael Schuller <chick@mschuller.net>
|
||||
* Mike Amy <cocoade@googlemail.com>
|
||||
* mulos <daniel.strackbein@gmail.com>
|
||||
* Oleg Broytman <phd@phdru.name>
|
||||
* osmnv <80402144+osmnv@users.noreply.github.com>
|
||||
* Patrick Schemitz <patrick.schemitz@digitalbriefkasten.de>
|
||||
* Pi Delport <pjdelport@gmail.com>
|
||||
* Prudhvi Vatala <pvatala@gmail.com>
|
||||
* quest <quest@wonky.windwards.net>
|
||||
* Robert Nix <com.github@rnix.org>
|
||||
* Rocky Meza <rmeza@fusionbox.com>
|
||||
* Romain Rigaux <romain.rigaux@gmail.com>
|
||||
* Rowan Seymour <rowanseymour@gmail.com>
|
||||
* Ryan Wooden <rygwdn@gmail.com>
|
||||
* saaj <id@saaj.me>
|
||||
* Sergei Stropysh <stropysh@gmail.com>
|
||||
* Shen Longxing <shenlongxing2012@gmail.com>
|
||||
* Simon Heisterkamp <she@delegate.dk>
|
||||
* Sjoerd Job Postmus
|
||||
* skryzh <sergeikryzh95@gmail.com>
|
||||
* Soloman Weng <soloman1124@gmail.com>
|
||||
* spigwitmer <itgpmc@gmail.com>
|
||||
* Stefan Warnat <ich@stefanwarnat.de>
|
||||
* Tao Wang <twang2218@gmail.com>
|
||||
* Tenghuan <tenghuanhe@gmail.com>
|
||||
* Tim Graham <timograham@gmail.com>
|
||||
* tonghuaroot <tonghuaroot@users.noreply.github.com>
|
||||
* Victor Hahn <info@victor-hahn.de>
|
||||
* Victor Uriarte <vmuriart@gmail.com>
|
||||
* Ville Skyttä <ville.skytta@iki.fi>
|
||||
* Vincent Gao <gaobing1230@gmail.com>
|
||||
* vthriller <farreva232@yandex.ru>
|
||||
* wayne.wuw <wayne.wuw@alibaba-inc.com>
|
||||
* Will Jones <willjones127@gmail.com>
|
||||
* William Ivanski <william.ivanski@gmail.com>
|
||||
* Yago Riveiro <yago.riveiro@gmail.com>
|
||||
* Zi-Xuan Fu <r33s3n6@gmail.com>
|
||||
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2016, Andi Albrecht <albrecht.andi@gmail.com>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the authors nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Reference in New Issue
Block a user