Skip to content

Commit

Permalink
Update docs index
Browse files Browse the repository at this point in the history
  • Loading branch information
kristiandupont committed Feb 7, 2024
1 parent aa81b15 commit bf8d530
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions docs-src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ This package is used by [Kanel](https://github.com/kristiandupont/kanel) to gene
npm i extract-pg-schema
```

## Usage
## Library Usage

You give it a [postgres connection config object](https://node-postgres.com/apis/client) and some options and it will connect to your database and generate

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

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

const result = await extractSchemas(connection);
Expand All @@ -33,3 +33,28 @@ run();
```

The generated output is a record of schemas, described with the [Schema](/api/extract-pg-schema.schema.html) type.

## 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.

```bash
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](https://www.postgresql.org/docs/current/app-pgdump.html) takes. You can also use the [environment variables](https://node-postgres.com/features/connecting#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)
```

0 comments on commit bf8d530

Please sign in to comment.