Parsing SQL Dumps to JSON Objects
Project description
README
Parsing SQL dumps into JSON objects. A tool for administrators, data scientists and hackers. The dump is not read entirely into RAM, so this utility can be used to process files of any size. And it can even parse corrupted dumps.
Supported DBMS: MySQL, SQL Server, PotsgreSQL and some other (not all formats).
Installation:
# install pipx via your favorite package manager
pipx install sqldump2json
For crappy distros like Ubuntu you need to do more steps:
- Install pyenv or asdf-vm.
- Install latest python version and make it global via pyenv or asdf-vm.
- Install sqldump2json.
- OR use Docker.
Insert statements are converted to JSON objects on each new line:
$ sqldump2json -i tests/dump.sql
{"table_name": "actor", "values": [1, "PENELOPE", "GUINESS", "2006-02-15 04:34:33"]}
{"table_name": "actor", "values": [2, "NICK", "WAHLBERG", "2006-02-15 04:34:33"]}
{"table_name": "actor", "values": [3, "ED", "CHASE", "2006-02-15 04:34:33"]}
...
Use jq to process JSON (sort, filter and etc):
$ sqldump2json -i tests/dump.sql | jq -r 'select(.table_name == "actor").values | @tsv'
1 PENELOPE GUINESS 2006-02-15 04:34:33
2 NICK WAHLBERG 2006-02-15 04:34:33
3 ED CHASE 2006-02-15 04:34:33
...
Hex strings are converted to base64:
sqldump2json -i tests/dump.sql | tail -4 | head -1 | jq -r '.values[4]' | base64 -d > image.png
Supports basic arifmetic and boolean operations (i know it's useless):
$ echo 'insert into test (result) values (-2 + 2 * 2);' | sqldump2json
{"table_name": "test", "values": {"result": 2}}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sqldump2json-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92a11c51a85722a83dec88d1c52e0b2adac969463cfb28aeaa140648e9c68d4d |
|
MD5 | e445ef96867ea608afc3d32b3449b21f |
|
BLAKE2b-256 | c7594631a4863cd8bd6057415bb6ad342b8abfa2ea2260486e77cea6d73c4b57 |