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

https://github.com/ozum/pg-generator

Template Based Scaffolding Tool for PostgreSQL. Create files and ORM models automatically.
https://github.com/ozum/pg-generator

Last synced: about 1 month ago
JSON representation

Template Based Scaffolding Tool for PostgreSQL. Create files and ORM models automatically.

Awesome Lists containing this project

README

        

# Template Based Scaffolding for PostgreSQL


pg-generator is a command line utility which generates files for each table and schema of a PostgreSQL database.

* 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).