queryparser
===========
**Tool for parsing and processing of MySQL/PostgreSQL and translation of
ADQL SELECT-like queries**
Designed to be used in conjunction with [django-daiquri](https://github.com/django-daiquiri/daiquiri)
as a query processing backend but it can be easily used as a stand-alone tool
or integrated into another project.
[![pytest Workflow Status](https://github.com/aipescience/queryparser/actions/workflows/pytest.yml/badge.svg)](https://github.com/aipescience/queryparser/actions/workflows/pytest.yml)
[![Coverage Status](https://coveralls.io/repos/aipescience/queryparser/badge.svg?branch=master&service=github)](https://coveralls.io/github/aipescience/queryparser?branch=master)
[![License](http://img.shields.io/badge/license-APACHE-blue.svg?style=flat)](https://github.com/aipescience/queryparser/blob/master/LICENSE)
[![Latest Version](https://img.shields.io/pypi/v/queryparser-python3.svg?style=flat)](https://pypi.org/project/queryparser-python3/)
Installation
------------
The easiest way to install the package is by using the pip tool:
```bash
pip install queryparser-python3
```
Alternatively, you can clone the repository and install it from there.
However, this step also requires generating the parser which is a slightly
more elaborate process (see below).
Generating the parser from the git repository
---------------------------------------------
To generate the parsers you need `python3` , `java` above version
7, and `antlr4` (`antlr-4.*-complete.jar` has to be installed inside the
`/usr/local/lib/` or `/usr/local/bin/` directories).
After cloning the project run
```bash
make
```
and a `lib` directory will be created. After that, run
```bash
python setup.py install
```
to install the generated parser in your virtual environment.
Parsing MySQL and PostgreSQL
----------------------------
Parsing and processing of MySQL queries can be done by creating an instance
of the `MySQLQueryProcessor` class
```python
from queryparser.mysql import MySQLQueryProcessor
qp = MySQLQueryProcessor()
```
feeding it a MySQL query
```python
sql = "SELECT a FROM db.tab;"
qp.set_query(sql)
```
and running it with
```python
qp.process_query()
```
After the processing is completed, the processor object `qp` will include
tables, columns, functions, and keywords used in the query or will raise a
`QuerySyntaxError` if there are any syntax errors in the query.
Alternatively, passing the query at initialization automatically processes it.
PostgreSQL parsing is very similar to MySQL, except it requires importing
the `PostgreSQLProcessor` class:
```python
from queryparser.postgresql import PostgreSQLQueryProcessor
qp = PostgreSQLQueryProcessor()
```
The rest of the functionality remains the same.
Translating ADQL
----------------
Translation of ADQL queries is done similarly by first creating an instance of
the `ADQLQueryTranslator` class
```python
from queryparser.adql import ADQLQueryTranslator
adql = "SELECT TOP 100 POINT('ICRS', ra, de) FROM db.tab;"
adt = ADQLQueryTranslator(adql)
```
and calling
```python
adt.to_mysql()
```
which returns a translated string representing a valid MySQL query if
the ADQL query had no errors. The MySQL query can then be parsed with the
`MySQLQueryProcessor` in the same way as shown above.
Testing
-------
First, install `pytest`
```bash
pip install pytest
```
then run the test suite for a version of python you would like to test with
```bash
pytest lib/
```
More elaborate testing procedures can be found in the development notes.
Raw data
{
"_id": null,
"home_page": "https://github.com/aipescience/queryparser",
"name": "queryparser-python3",
"maintainer": "Gal Matijevic",
"docs_url": null,
"requires_python": "",
"maintainer_email": "gmatijevic@aip.de",
"keywords": "",
"author": "Gal Matijevic",
"author_email": "gmatijevic@aip.de",
"download_url": "https://files.pythonhosted.org/packages/1e/fe/247cbac00320e06218e5f399c63b37d9467ec8f6b9e43c12f32d46c9188e/queryparser-python3-0.6.1.tar.gz",
"platform": null,
"description": "queryparser\n===========\n\n**Tool for parsing and processing of MySQL/PostgreSQL and translation of\nADQL SELECT-like queries**\n\nDesigned to be used in conjunction with [django-daiquri](https://github.com/django-daiquiri/daiquiri)\nas a query processing backend but it can be easily used as a stand-alone tool\nor integrated into another project.\n\n\n[![pytest Workflow Status](https://github.com/aipescience/queryparser/actions/workflows/pytest.yml/badge.svg)](https://github.com/aipescience/queryparser/actions/workflows/pytest.yml)\n[![Coverage Status](https://coveralls.io/repos/aipescience/queryparser/badge.svg?branch=master&service=github)](https://coveralls.io/github/aipescience/queryparser?branch=master)\n[![License](http://img.shields.io/badge/license-APACHE-blue.svg?style=flat)](https://github.com/aipescience/queryparser/blob/master/LICENSE)\n[![Latest Version](https://img.shields.io/pypi/v/queryparser-python3.svg?style=flat)](https://pypi.org/project/queryparser-python3/)\n\n\n\nInstallation\n------------\n\nThe easiest way to install the package is by using the pip tool:\n\n```bash\n\n pip install queryparser-python3\n\n```\n\nAlternatively, you can clone the repository and install it from there.\nHowever, this step also requires generating the parser which is a slightly\nmore elaborate process (see below).\n\n\nGenerating the parser from the git repository\n---------------------------------------------\n\nTo generate the parsers you need `python3` , `java` above version\n7, and `antlr4` (`antlr-4.*-complete.jar` has to be installed inside the\n`/usr/local/lib/` or `/usr/local/bin/` directories).\n\nAfter cloning the project run\n\n```bash\n make\n```\n\nand a `lib` directory will be created. After that, run\n\n```bash\n python setup.py install\n```\n\nto install the generated parser in your virtual environment.\n\n\nParsing MySQL and PostgreSQL\n----------------------------\n\nParsing and processing of MySQL queries can be done by creating an instance\nof the `MySQLQueryProcessor` class\n\n```python\n from queryparser.mysql import MySQLQueryProcessor\n qp = MySQLQueryProcessor()\n```\n\nfeeding it a MySQL query\n\n```python\n sql = \"SELECT a FROM db.tab;\"\n qp.set_query(sql)\n```\n\nand running it with\n\n```python\n qp.process_query()\n```\n\nAfter the processing is completed, the processor object `qp` will include\ntables, columns, functions, and keywords used in the query or will raise a\n`QuerySyntaxError` if there are any syntax errors in the query.\n\nAlternatively, passing the query at initialization automatically processes it.\n\nPostgreSQL parsing is very similar to MySQL, except it requires importing\nthe `PostgreSQLProcessor` class:\n\n```python\n from queryparser.postgresql import PostgreSQLQueryProcessor\n qp = PostgreSQLQueryProcessor()\n```\n\nThe rest of the functionality remains the same.\n\n\nTranslating ADQL\n----------------\n\nTranslation of ADQL queries is done similarly by first creating an instance of\nthe `ADQLQueryTranslator` class\n\n```python\n from queryparser.adql import ADQLQueryTranslator\n adql = \"SELECT TOP 100 POINT('ICRS', ra, de) FROM db.tab;\"\n adt = ADQLQueryTranslator(adql)\n```\n\nand calling\n\n```python\n adt.to_mysql()\n```\n\nwhich returns a translated string representing a valid MySQL query if\nthe ADQL query had no errors. The MySQL query can then be parsed with the\n`MySQLQueryProcessor` in the same way as shown above.\n\n\nTesting\n-------\n\nFirst, install `pytest`\n\n```bash\n pip install pytest\n```\n\nthen run the test suite for a version of python you would like to test with\n\n```bash\n pytest lib/\n```\n\nMore elaborate testing procedures can be found in the development notes.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Parses PostgreSQL/MySQL and translates ADQL to PostgreSQL/MySQL.",
"version": "0.6.1",
"project_urls": {
"Homepage": "https://github.com/aipescience/queryparser"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7bff18bf75739b2a6c4e41a9aa128d673fbe272910381e2794565ba3efe8e6e6",
"md5": "501d18624cf60cf600f7d2774f4a7498",
"sha256": "20edd1d7c117f6d4536db8e0fa265ede89906055c956a7a141293e507dc39ad6"
},
"downloads": -1,
"filename": "queryparser_python3-0.6.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "501d18624cf60cf600f7d2774f4a7498",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 268030,
"upload_time": "2022-11-17T13:15:42",
"upload_time_iso_8601": "2022-11-17T13:15:42.447781Z",
"url": "https://files.pythonhosted.org/packages/7b/ff/18bf75739b2a6c4e41a9aa128d673fbe272910381e2794565ba3efe8e6e6/queryparser_python3-0.6.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1efe247cbac00320e06218e5f399c63b37d9467ec8f6b9e43c12f32d46c9188e",
"md5": "2a052fffbb40994803aa7cb320eb15ee",
"sha256": "38882e341cbb69536cfb1a5e51ad92d15079c13e662833a2bcd044f4539c1901"
},
"downloads": -1,
"filename": "queryparser-python3-0.6.1.tar.gz",
"has_sig": false,
"md5_digest": "2a052fffbb40994803aa7cb320eb15ee",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 262630,
"upload_time": "2022-11-17T13:15:47",
"upload_time_iso_8601": "2022-11-17T13:15:47.345620Z",
"url": "https://files.pythonhosted.org/packages/1e/fe/247cbac00320e06218e5f399c63b37d9467ec8f6b9e43c12f32d46c9188e/queryparser-python3-0.6.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-11-17 13:15:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aipescience",
"github_project": "queryparser",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "queryparser-python3"
}