An open API service indexing awesome lists of open source software.

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.

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": [
"",
// ...
],
},
// ...
],
},
// ...
]
```