This major release of `sql-metadata` **brings a completely new parser and API** implemented by collerek on top of proposals from 83 and 98.
The gist of the changes is **the introduction of the `Parser` class** (see 121) that is later used to get the list columns, tables, aliases.
`CREATE TABLE` queries are now supported (35). Aliases handling has been greatly improved thanks to 131.
Code coverage has been improved and is now kept at 100%.
Example
python
from sql_metadata import Parser
parsed = Parser("SELECT test, id FROM foo, bar")
parsed.columns ['test', 'id']
parsed.tables ['foo', 'bar']
Migrating from `sql_metadata` 1.x
`sql_metadata.compat` module has been implemented to make the introduction of sql-metadata v2.0 smoother.
You can use it by simply changing the imports in your code from:
python
from sql_metadata import get_query_columns, get_query_tables
into:
python
from sql_metadata.compat import get_query_columns, get_query_tables
The following functions from the old API are available in the `sql_metadata.compat` module:
* `generalize_sql`
* `get_query_columns` (since 131 columns aliases ARE NOT returned by this function)
* `get_query_limit_and_offset`
* `get_query_tables`
* `get_query_tokens`
* `preprocess_query`
Changes
* 35 `enhancement` - Support for CREATE TABLE... statements (by sandeep-pareek)
* 83 `enhancement` - New API [draft]
* 85 `Postgres` - Support Postgres quoted identifiers (by LanDinh)
* 98 `internals` - Improve get_query_tokens iterator
* 103 `question` - Best way to get an array of values? (by jplock)
* 112 `bug` - missing tables returned by sql_metadata.get_query_tables (by tdebroc)
* 121 `enhancement` - New parser, bug fixes and new functionality. (by collerek)
* 125 `bug` - sql_metadata.get_query_columns result error (by chen-ABC)
* 126 `enhancement` - Add a support for CREATE TABLE queries
* 127 `pr` - Improved handling of custom SQL functions when getting the list of columns
* 128 `bug` - get_query_tables() is returning columns on WITH statements (by remisalmon)
* 129 `dependencies` - build(deps-dev): bump black from 21.4b2 to 21.5b0 (by dependabot[bot])
* 130 `dependencies` - build(deps-dev): bump pytest from 6.2.3 to 6.2.4 (by dependabot[bot])
* 131 `enhancement` - Column aliases support (by collerek)
* 133 `dependencies` - build(deps-dev): bump black from 21.5b0 to 21.5b1 (by dependabot[bot])
* 135 `internals` - tool.coverage.report: require 100% code coverage
* 136 `internals` - CI - use Makefile commands
* 137 `internals` - Introduce a compatibility layer for 1.x functions