# pg-generator

> Template Based Scaffolding Tool for PostgreSQL.

Latest version **4.8.3** (published 2020-04-28) · MIT license · 0 weekly downloads

## Install

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

Provides the command `pgen`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.8.3 |
| Published | 2020-04-28 |
| First published | 2015-11-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 13 |
| Unpacked size | 1.2 MB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 92 |
| Author | Özüm Eldoğan |
| Maintainers | ozum |
| Keywords | pg, postgresql, reverse engineer, auto generate, sequelize, orm, scaffold |

## Links

- npm: https://www.npmjs.com/package/pg-generator
- Repository: https://github.com/ozum/pg-generator
- Homepage: http://www.pg-generator.com
- Issues: https://github.com/ozum/pg-generator/issues
- npm.io page: https://npm.io/package/pg-generator

## Dependencies (13)

- [pg](https://npm.io/package/pg.md) ^7.10.0
- [klaw](https://npm.io/package/klaw.md) ^1.x
- [chalk](https://npm.io/package/chalk.md) ^1.x
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [winston](https://npm.io/package/winston.md) ^2.4.4
- [inquirer](https://npm.io/package/inquirer.md) ^0
- [nunjucks](https://npm.io/package/nunjucks.md) ^3.2.0
- [commander](https://npm.io/package/commander.md) ^2.20.0
- [fs-promise](https://npm.io/package/fs-promise.md) ^2.x
- [inflection](https://npm.io/package/inflection.md) ^1.x
- [js-beautify](https://npm.io/package/js-beautify.md) ^1.9.1
- [eslint-fixer](https://npm.io/package/eslint-fixer.md) ^0.1.5
- [pg-structure](https://npm.io/package/pg-structure.md) ^4.2.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.8.3 (latest) — 2020-04-28
- 5.0.0-alpha.9 (alpha) — 2021-03-13
- 5.0.0-alpha.8 — 2021-03-13
- 5.0.0-alpha.7 — 2021-03-13
- 5.0.0-alpha.6 — 2021-03-08
- 5.0.0-alpha.5 — 2021-02-25
- 5.0.0-alpha.4 — 2021-02-25
- 5.0.0-alpha.3 — 2021-02-25
- 5.0.0-alpha.2 — 2021-02-25
- 5.0.0-alpha.1 — 2021-02-25
- 4.8.2 — 2019-04-29
- 4.8.0 — 2018-09-08
- 4.7.7 — 2018-09-06
- 4.7.5 — 2018-06-27
- 4.7.4 — 2018-06-23
- … 94 more at https://npm.io/package/pg-generator/versions

## README

# Template Based Scaffolding for PostgreSQL 

<div style="font-size:1.4em; color:#444466; margin-bottom:15px;"><strong><a href="http://www.pg-generator.com">pg-generator</a></strong> is a command line utility which generates files for each table and schema of a PostgreSQL database.</div>

 * Reverse engineers PostgreSQL database,
 * Executes [nunjucks](https://mozilla.github.io/nunjucks/) templates for each table, schema and for database,
 * Makes database objects available to templates using [pg-structure](http://www.pg-structure.com).

[pg-generator](http://www.pg-generator.com) takes your burden of manually creating ORM files or any other files which are based on database structure.

## Installation

    $ npm install -g pg-generator

## Sequelize Example

See [sequelize template](http://www.pg-generator.com/builtin-templates/sequelize/) for usage and details.

    $ pgen template sequelize -t sequelize-template
    $ pgen exec sequelize-template -d our_crm -u user -p tOpSeCrEt -t model --fix

First command copies one of the builtin templates (sequelize) into target directory (sequelize-template). Second command generates files based on given template (sequelize-template) into target directory (model).  

You may change generated templates according to your requirements, also **you should add generated templates to your repository**.

## Basic Usage

1. Use `pgen template` to copy one of the builtin templates or create your own template. (You can use base template for starting up.)
1. Use `pgen exec` to create files based on your template.

You can access CLI options and their description via `-h` or `--help` arguments.

    $ pgen --help
    $ pgen template --help
    $ pgen exec --help

## Template

Creating a template from scratch is easy. Execute command below:

    $ pgen template base -t my-template

To see a basic example execute following command from shell and examine files in tutorial-example directory. 

    $ pgen template tutorial -t tutorial-template
    
For a full fledged example which we use at Ozcorp, see Sequelize Example above. 

## For Low Level Direct Access: [pg-structure](http://www.pg-structure.com)
    
If you prefer lower level methods to directly access PostgreSQL structure to build your own generators. You can check [pg-structure](http://www.pg-structure.com) module which is used to build this module and provides direct access to database structure. 
    
## Full Documentation

Documentation is available on [pg-generator.com](http://www.pg-generator.com)

## Special Thanks

Documentation is auto generated thanks to:

* [MkDocs](http://www.mkdocs.org/) using a [theme](https://github.com/snide/sphinx_rtd_theme) provided by [Read the Docs](https://readthedocs.org/).
* Markdown is generated by [jsdoc-to-markdown](https://www.npmjs.com/package/jsdoc-to-markdown)

## Contributions

* For contribution please send pull requests with tests on [GitHub](https://github.com/ozum/pg-generator.git).

## BUG REPORTS

Without necessary information, it is hard to impossible to debug every error for every database.

Please include details below in your bug reports.
 
1. `pg-generator` and PostgreSQL version,
1. DDL (Database creation script),
1. `pgen` commands you executed,
1. JS code you executed if it is a runtime bug,
1. Error message.

Send bug reports and feature requests to [GitHub Issues](https://github.com/ozum/pg-generator/issues).

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