Skip to content

Commit

Permalink
docs: fix docs compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ozum committed Mar 13, 2021
1 parent 5779d08 commit eceb41e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
32 changes: 21 additions & 11 deletions docs/v4/builtin-templates--nc,d1/sequelize.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ This template is successor of [sequelize-pg-generator](https://www.npmjs.com/pac

Create template and model files:

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

In your application, create a sequelize object and initialize models with it:

Expand Down Expand Up @@ -55,7 +57,9 @@ var model = require("./model/index.js"); // No init here, because it is initiali

Templates have passed a variable called `util` which provides some useful utilities.

type: {{ util.sequelizeType(column) }} -> type: DataTypes.INTEGER
```
type: {{ util.sequelizeType(column) }} -> type: DataTypes.INTEGER
```

<a name="uniqueRelatedTables"></a>

Expand Down Expand Up @@ -85,8 +89,10 @@ Returns Sequelize ORM data type for given column.

**Example**

{{ util.sequelizeType() }} // DataTypes.INTEGER(3)
{{ sequelizeType('Sequelize') }} // Sequelize.INTEGER(3)
```jinja2
{{ util.sequelizeType() }} // DataTypes.INTEGER(3)
{{ sequelizeType('Sequelize') }} // Sequelize.INTEGER(3)
```

## Relations

Expand Down Expand Up @@ -116,7 +122,9 @@ module.exports = {

This template uses table names or schema table names for model naming. For relations it uses foreign key names and relation names from your database. (You are naming your relations in database meaningfully right?) Default template is based on camelCase naming. You can easily change it to use snake_case or PascalCase by using provided filters. Naming conventions are based on Sequelize module suggestions and generated explicitly with 'as' parameter. Aliases can be turned of by providing a custom options file and setting `generateAliases` false.

module.exports = { generateAliases: false };
```js
module.exports = { generateAliases: false };
```

| Type of Object | Filters | Default Naming & Alias Rule |
| -------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -144,9 +152,9 @@ As an example for the schema above aliases are created as follows. Please note n

In your template;

- Rename _'sequelize/table/definition/{table.name}.js.nunj.html'_ as _'sequelize/table/definition/{table.schema.name}-{table.name}.js.nunj.html'_.
- Change <span style="font-family:monospace">modelName macro</span> in _'sequelize/table/definition/{table.schema.name}-{table.name}.js.nunj.html'_ as `{{ (table.schema.name + table.name) | classCase }}`.
- Add <span style="font-family:monospace">'{table.schema.name}-'</span> string to <span style="font-family:monospace">'sequelize.import'</span> and <span style="font-family:monospace">'require'</span> parts in _'sequelize/db/index.js.nunj.html'_ file to match new model file's names.
- Rename _'sequelize/table/definition/\{table.name\}.js.nunj.html'_ as _'sequelize/table/definition/\{table.schema.name\}-\{table.name\}.js.nunj.html'_.
- Change <span style="font-family:monospace">modelName macro</span> in _'sequelize/table/definition/\{table.schema.name\}-\{table.name\}.js.nunj.html'_ as `\{\{ (table.schema.name + table.name) | classCase \}\}`.
- Add <span style="font-family:monospace">'\{table.schema.name\}-'</span> string to <span style="font-family:monospace">'sequelize.import'</span> and <span style="font-family:monospace">'require'</span> parts in _'sequelize/db/index.js.nunj.html'_ file to match new model file's names.

#### I hate aliases that sequelize template generate. What can I do?

Expand Down Expand Up @@ -181,8 +189,10 @@ Account: {
#### \*.nunj.html file extension is ugly.
This is not a question. nunj.html extension is chosen because [nunjucks](https://mozilla.github.io/nunjucks/) command line tools expect files with extension **html**. However some IDE's struggle to auto complete/help/color [nunjucks](https://mozilla.github.io/nunjucks/), swig, twig, jinja files with html extension. We can define .nunj.html extension in IDE's to differentiate template files (_.nunj.html) and html (_.html) files correctly and make [nunjucks](https://mozilla.github.io/nunjucks/) command line tools happy.
nunj.html extension is chosen because [nunjucks](https://mozilla.github.io/nunjucks/) command line tools expect files with extension **html**. However some IDE's struggle to auto complete/help/color [nunjucks](https://mozilla.github.io/nunjucks/), swig, twig, jinja files with html extension. We can define .nunj.html extension in IDE's to differentiate template files (_.nunj.html) and html (_.html) files correctly and make [nunjucks](https://mozilla.github.io/nunjucks/) command line tools happy.
However if you really like to use another file extension in your templates create template filw tih your desired extension and use `--extension` option of `pgen`
$ pgen exec sequelize-template -d our_crm -u user -p tOpSeCrEt -t model --extension html
```bash
$ pgen exec sequelize-template -d our_crm -u user -p tOpSeCrEt -t model --extension html
```
36 changes: 26 additions & 10 deletions docs/v4/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,31 @@ For those using modified templates or their own templates, below are some steps

v2:

{% for column in table.columns -%}
```jinja2
{% for column in table.columns -%}
{% endfor %}
{% endfor %}
```

v3:

{% for column in table.columns.array -%}
````jinja2
{% for column in table.columns.array -%}
{% endfor %}
{% endfor %}
```jinja2
v2:
{{ relation.sourceConstraint.columns[0].name }}
```jinja2
{{ relation.sourceConstraint.columns[0].name }}
````

v3:

{{ relation.sourceConstraint.columns.array[0].name }}
```jinja2
{{ relation.sourceConstraint.columns.array[0].name }}
```

## Change `column#foreignKeyConstraint` to `column#foreignKeyConstraints.array`

Expand All @@ -34,20 +42,28 @@ below:

v2:

{{ column.foreignKeyConstraint }}
```jinja2
{{ column.foreignKeyConstraint }}
```

v3:

{{ column.foreignKeyConstraints.array[0] }}
```jinja2
{{ column.foreignKeyConstraints.array[0] }}
```

## Change `column#referencedColumn` to `column#referencedColumns.array`

Same reason above.

v2:

{{ column.referencedColumn }}
```jinja2
{{ column.referencedColumn }}
```

v3:

{{ column.referencedColumns.array[0] }}
```jinja2
{{ column.referencedColumns.array[0] }}
```
10 changes: 8 additions & 2 deletions docs/v4/templates--nc,d1/template-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

Filters are essentially functions that can be applied to variables. They are called with a pipe operator (|) and can take arguments. [nunjucks](https://mozilla.github.io/nunjucks/) filters alter output of variables in place. You can use all available builtin [nunjucks filters](https://mozilla.github.io/nunjucks/templating.html#builtin-filters).

{{ table.name | lower }} -> Converts name to lower case. (i.e. Member -> member)
```jinja2
{{ table.name | lower }} -> Converts name to lower case. (i.e. Member -> member)
```

They can be chained:

{{ table.name | plural | camelCase }} -> Converts name to plural in camel case. (i.e. member_name -> memberNames)
```jinja2
{{ table.name | plural | camelCase }} -> Converts name to plural in camel case. (i.e. member_name -> memberNames)
```

#### pg-generator filters

Expand Down Expand Up @@ -34,13 +38,15 @@ pg-generator offfers additional filters suitable for database scaffolding. Some

**\*** Footnotes

```jinja2
*1 {{ 'cart_cart_id' | stripPrefix('cart') }} -> cart_id
{{ 'cart_cart_id' | stripPrefix(cart_table) }} -> cart_id (Assuming cart_table.name equals cart)
{{ 'a_b_c_table' | stripPrefix('a', 'b') }} -> c_table
*2 {{ 'cart_id' | stripSuffix('id') }} -> cart
*3 {{ 'cart_product_id' | strip('product') }} -> cart_id
*4 {{ 'member' | padRight(10) }} -> member <- Space padded until here.
{{ 'member' | padRight(10, '_') }} -> member____
```

## API of Filter Functions

Expand Down

0 comments on commit eceb41e

Please sign in to comment.