https://github.com/chop-dbhi/sql-schema-exporter
Utility to export schema information from a relational database to JSON.
https://github.com/chop-dbhi/sql-schema-exporter
export information-schema schema sql
Last synced: 3 months ago
JSON representation
Utility to export schema information from a relational database to JSON.
- Host: GitHub
- URL: https://github.com/chop-dbhi/sql-schema-exporter
- Owner: chop-dbhi
- Created: 2017-08-15T18:00:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-15T18:44:13.000Z (over 8 years ago)
- Last Synced: 2024-12-29T23:54:49.783Z (over 1 year ago)
- Topics: export, information-schema, schema, sql
- Language: Python
- Homepage:
- Size: 2.93 KB
- Stars: 4
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SQL Schema Exporter
This program exports table schema information from a relational database.
## Install
```
pip install -r requirements.txt
```
## Usage
The only argument is the URI of the database. The schema (as an array of tables) is emitted to stdout as JSON.
```bash
python main.py 'postgresql://postgres:secret@127.0.0.1:5432/data' > schema.json
```
Supported databases:
- PostgreSQL
- Oracle (requires instantclient libraries to be installed)
- MySQL
- SQLite
### Docker
A pre-baked Docker image is available which includes the Oracle driver.
```
docker run --rm dbhi/sql-schema-exporter 'postgresql://postgres:secret@127.0.0.1:5432/data' > schema.json
```
To build the Docker image locally, the instantclient-* libraries must be in this directly. See the Dockerfile for the file names.
## Data Model
```js
[
{
"schema": "",
"table": "",
"columns": [
{
"name": "",
"nullable": ,
"type": ""
},
// ...
],
"primary_key": [
"",
// ...
],
"foreign_keys": [
{
"constrained_columns": [
"",
// ...
],
"referred_schema": "",
"referred_table": "",
"referred_columns": [
"",
// ...
]
},
//...
],
"unique_constraints": [
{
"name": "",
"columns": [
"",
// ...
],
},
// ...
],
},
// ...
]
```