{"id":15009872,"url":"https://github.com/seporaitis/mysqlparse","last_synced_at":"2025-04-09T17:52:27.622Z","repository":{"id":57444541,"uuid":"51595885","full_name":"seporaitis/mysqlparse","owner":"seporaitis","description":"Python library for parsing SQL statements","archived":false,"fork":false,"pushed_at":"2022-12-26T19:44:44.000Z","size":90,"stargazers_count":22,"open_issues_count":10,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-23T19:51:34.648Z","etag":null,"topics":["library","mysql","parser","python","python2","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seporaitis.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-12T15:10:47.000Z","updated_at":"2022-03-10T02:41:58.000Z","dependencies_parsed_at":"2023-01-31T00:50:19.268Z","dependency_job_id":null,"html_url":"https://github.com/seporaitis/mysqlparse","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seporaitis%2Fmysqlparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seporaitis%2Fmysqlparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seporaitis%2Fmysqlparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seporaitis%2Fmysqlparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seporaitis","download_url":"https://codeload.github.com/seporaitis/mysqlparse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248083320,"owners_count":21045072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","mysql","parser","python","python2","python3"],"created_at":"2024-09-24T19:28:59.582Z","updated_at":"2025-04-09T17:52:27.583Z","avatar_url":"https://github.com/seporaitis.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"==========\nmysqlparse\n==========\n\n.. image:: https://img.shields.io/pypi/v/mysqlparse.svg\n        :target: https://pypi.python.org/pypi/mysqlparse\n\n.. image:: https://img.shields.io/travis/seporaitis/mysqlparse/master.svg\n        :target: https://travis-ci.org/seporaitis/mysqlparse\n\n.. image:: https://readthedocs.org/projects/mysqlparse/badge/?version=latest\n        :target: http://mysqlparse.readthedocs.io/en/latest/?badge=latest\n\n\nA highly experimental attempt to have a sane parser library to parse MySQL statements.\n\nAt the moment - use it at your own risk!\n\n\nFeatures\n--------\n\n* Parses SOME SQL strings.\n\n\nExample\n-------\n\nSome properties that can be accessed.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import mysqlparse\n    \u003e\u003e\u003e sql = mysqlparse.parse(\"\"\"\n    ...     ALTER TABLE `django_user` ADD COLUMN `notes` LONGTEXT NOT NULL\n    ... \"\"\")\n    \u003e\u003e\u003e print(sql.statements[0].statement_type)\n    ALTER\n    \u003e\u003e\u003e print(sql.statements[0].table_name)\n    `django_user`\n    \u003e\u003e\u003e print(sql.statements[0].ignore)\n    False\n    \u003e\u003e\u003e print(sql.statements[0].alter_specification[0].alter_action)\n    ADD COLUMN\n    \u003e\u003e\u003e print(sql.statements[0].alter_specification[0].column_name)\n    `notes`\n    \u003e\u003e\u003e print(sql.statements[0].alter_specification[0].data_type)\n    LONGTEXT\n    \u003e\u003e\u003e print(sql.statements[0].alter_specification[0].null)\n    False\n    \u003e\u003e\u003e print(sql.statements[0].alter_specification[0].column_position)\n    LAST\n\nChecking that the alter statement is backwards compatible with a\nprevious version of SOME code, which does not know how to save\n``notes`` as ``NOT NULL``:\n\n.. code-block:: python\n\n    for statement in sql.statements:\n        if statement != 'ALTER':\n            continue\n        for column in statement.alter_specification:\n            if column.data_type == 'LONGTEXT':\n                if column.null is False and column.default != 'NULL':\n                    print \"{s.table_name}.{c.column_name} is `LONGTEXT NOT NULL` which may break the production system. Use `LONGTEXT DEFAULT NULL` instead.\".format(\n                        s=statement,\n                        c=column,\n                    )\n\n\nHow can you help?\n-----------------\n\nA short list of things that would help (from relatively easiest):\n\n* Raise an issue with an edge case statement that **should** parse,\n  but doesn't.\n\n* Raise an issue with how you would like to use this library.\n\n* Document the available properties in the parsed object.\n\n* Add a missing test case or suggest a way to avoid so much repetition\n  in tests checking the same statement, but with variations.\n\n* Suggest how to use ``pyparsing`` to do statement validation.\n\n* Maybe it is possible to generate ``pyparsing`` parser from the MySQL\n  source code?\n\n* Add ability to unparse the parse (sub)trees back into valid SQL.\n\n\nWhy?\n----\n\nOut of frustration for lack of a better tool.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseporaitis%2Fmysqlparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseporaitis%2Fmysqlparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseporaitis%2Fmysqlparse/lists"}