# pg-doc

> Produce schema documentation for your Postgres database in markdown format

Latest version **0.2.2** (published 2023-01-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install pg-doc
pnpm add pg-doc
yarn add pg-doc
bun add pg-doc
```

Provides the command `pg-doc`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2023-01-23 |
| First published | 2019-08-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 70.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Eleftherios Chetzakis |
| Maintainers | elchetz |
| Keywords | postgres, markdown, database, documentation |

## Links

- npm: https://www.npmjs.com/package/pg-doc
- Repository: https://github.com/echetzakis/pg-doc
- Homepage: https://github.com/echetzakis/pg-doc#readme
- Issues: https://github.com/echetzakis/pg-doc/issues
- npm.io page: https://npm.io/package/pg-doc

## Dependencies (4)

- [pg](https://npm.io/package/pg.md) ^8.8.0
- [knex](https://npm.io/package/knex.md) ^2.4.2
- [yargs](https://npm.io/package/yargs.md) ^17.6.2
- [time-span](https://npm.io/package/time-span.md) ^4.0.0

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2023-01-23
- 0.1.1 — 2020-12-13
- 0.1.1-beta.4 — 2020-04-21
- 0.1.1-beta.3 — 2019-08-14
- 0.1.1-beta.2 — 2019-08-14
- 0.1.1-beta.1 — 2019-08-13
- 0.1.1-beta.0 — 2019-08-11

## README

<img src="icon.png" align="right" />

[![npm version](https://badge.fury.io/js/pg-doc.svg)](https://badge.fury.io/js/pg-doc)

# pg-doc

Produce **markdown** schema documentation for your **Postgres** database.

# Installation
```
npm i pg-doc
```
or globally:

```
npm i -g pg-doc
```

# Usage

```
Usage: pg-doc [options]

Options:
  --version                Show version number                         [boolean]
  --connection, --db       Database Connection URL           [string] [required]
  --out, -o                The file name of the output                  [string]
  --title, -t              The title of the document                    [string]
  --excluded, --ex         Tables to be excluded                         [array]
  --toc                    Add a table of contents (TOC) section
                                                       [boolean] [default: true]
  --split-by-initial, -s   Split TOC by initial letter                 [boolean]
  --split-limit, --sl      Split TOC only if number of tables is greater that
                           this limit                     [number] [default: 20]
  --no-descriptions, --nd  Don't output table/column descriptions      [boolean]
  --help                   Show help                                   [boolean]
```

# Configuration
  
There are 2 alternative ways to pass configuration options appart from the command line.

## Options file
You can put your options in a `.pg-doc.json` file in your project:

```
{
    "connection": <postgres connection url>,
    "excluded": <string array>,
    "noDescriptions": <boolean>,
    "toc": <boolean>,
    "splitByInitial": <boolean>,
    "splitLimit": <number>,
    "title": <string>,
    "out": <filename>
}
```

## Environment variables
Use the following variables to pass options to `pg-doc`:
```
PGDOC_CONNECTION=<postgres connection url> 
PGDOC_OUT=<filename>
PGDOC_TITLE=<string>
PGDOC_EXCLUDED=<comma separated strings>
PGDOC_SPLIT_LIMIT=<number>
PGDOC_SPLIT_BY_INITIAL=<boolean>
PGDOC_NO_DESCRIPTIONSL=<boolean>
PGDOC_TOC=<boolean>
```
## Precedence
Configuration options are applied in the following order (from lowest to highest precedence):

`.pg-doc.json --> env variables --> command line options`

# Table and Column descriptions
By default `pg-doc` will show the description you have defined as table/column comments in your database, ie:
```
sql> COMMENT ON TABLE foo IS 'This is my foo table.';
```
will be rendered as
> ...
> 
> |# |Table Name| Description|
> |--:|----------|------------|
> |1| foo | This is my foo table. |
> 
> ## Details 
> ### table1
> This is my foo table.
> 
> ...

If you have no comments defined you can either disable this by setting the `noDescriptions` option to `true` or provide your descriptions by adding a `descriptions` section in your `.pg-doc.json` file like so:
```
{
    "descriptions": {
        "tableName": "this is my tableName description",
        "tableName.columnName": "this is my columnName description"
    }
}
```

---
_Source: https://npm.io/package/pg-doc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
