Use pudo / dataset written in python.
$ pip install --local dataset
Here, by specifying the --local
option, the datafreeze
command is installed in ~ / .local / bin
in the home directory.
Please set the PATH appropriately.
common:
database: "mysql://[email protected]/information_schema"
exports:
- query: "SELECT * FROM COLLATIONS"
filename: "collations.json"
format: json
$ datafreeze config.yaml
cat collations.json
[{"COLLATION_NAME": "big5_chinese_ci", "CHARACTER_SET_NAME": "big5", "ID": 1, "IS_DEFAULT": "Yes", ...
You can also use it by importing it as a library.
import dataset
db = dataset.connect('mysql://[email protected]/information_schema')
for table in db.tables:
result = db[table].all()
dataset.freeze(result, format='json', filename='{0}.json'.format(table))
See also There is an official document with cute characters. dataset: databases for lazy people
Internally, SQLAlchemy is used.
I also wrote an article about the dataset itself. Python-Super easy OR mapper dataset for lazy people-Qiita
Recommended Posts