5.1.1 • Published 1 month ago

extract-pg-schema v5.1.1

Weekly downloads
1,348
License
MIT
Repository
github
Last release
1 month ago

Extract Schema from Postgres Database

Reads various metadata from your postgres database and return a Javascript object. This package is used by Kanel to generate Typescript types and Schemalint to provide linting of database schemas.

View the documentation here

Installation

npm i extract-pg-schema

Library Usage

You give it a postgres connection config object and some options and it will connect to your database and generate

const { extractSchemas } = require('extract-pg-schema');

async function run() {
  const connection = {
    host: 'localhost',
    database: 'postgres',
    user: 'postgres',
    password: 'postgres',
  };

  const result = await extractSchemas(connection);

  console.log(result);
}

run();

For an example of a generated object, take a look at dvdrental.json file which is generated from the sample Database from PostgreSQLTutorial.com.

CLI Usage

You can also use the CLI to extract the schemas from a database and write it to the console or a file in JSON format.

npx extract-pg-schema -h localhost -p 5432 -U postgres -d postgres > schemas.json

The CLI takes a small subset of the options that pg_dump takes. You can also use the environment variables starting with PG to set the connection parameters.

Usage: extract-pg-schema [options] [DBNAME]

Extract all schemas from a PostgreSQL database and print them as JSON.

Options:
    --help                      show this help
    -h, --host=HOSTNAME         database server host or socket directory
    -p, --port=PORT             database server port
    -U, --username=USERNAME     database user name
    -d, --dbname=DBNAME         database name to connect to
    -n, --schema=SCHEMA         include schema regular expression (may be given multiple times)
    -N, --exclude-schema=SCHEMA exclude schema regular expression (may be given multiple times)

Contributors

Made with contrib.rocks.

5.1.1

1 month ago

5.1.0

1 month ago

5.0.0

3 months ago

4.7.0

3 months ago

4.6.0

3 months ago

4.5.0

3 months ago

4.4.0

4 months ago

4.3.2

5 months ago

4.3.1

5 months ago

4.2.5

5 months ago

4.3.0

5 months ago

4.2.3

7 months ago

4.2.4

7 months ago

4.2.2

11 months ago

4.2.1

11 months ago

4.2.0

1 year ago

4.1.1

1 year ago

4.1.0

2 years ago

3.1.8

2 years ago

3.2.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.2

2 years ago

3.1.7

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.9.0

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.1.1

5 years ago

0.1.0

5 years ago