Skip to content

Commit

Permalink
fix: fix empty returning relation name
Browse files Browse the repository at this point in the history
  • Loading branch information
ozum committed Mar 6, 2021
1 parent 3e58acb commit 715dd11
Show file tree
Hide file tree
Showing 19 changed files with 478 additions and 296 deletions.
12 changes: 6 additions & 6 deletions .yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"author.name": "Özüm Eldoğan",
"author.url": "https://www.ozum.net/",
"bugs": "https://github.com/ozum/pg-structure/issues",
"engines.node": ">= 12.0.0",
"engines.node": ">= 14.0.0",
"files": ["dist", "!dist/**/@(*.spec|*.test)*", "!dist/**/__test__", "module-files"],
"main": "dist/index.js",
"repository": "ozum/pg-structure",
Expand All @@ -43,8 +43,8 @@
"types": "dist/index.d.ts"
},
"normal": {
"devDependencies.@commitlint/cli": "^11.0.0",
"devDependencies.@commitlint/config-conventional": "^11.0.0",
"devDependencies.@commitlint/cli": "^12.0.1",
"devDependencies.@commitlint/config-conventional": "^12.0.1",
"devDependencies.@ozum/pinst": "^2.1.4",
"devDependencies.@types/jest": "^26.0.20",
"devDependencies.@types/node": "^14.14.31",
Expand All @@ -57,7 +57,7 @@
"devDependencies.concat-md": "^0.3.5",
"devDependencies.eslint": "^7.20.0",
"devDependencies.eslint-config-airbnb-base": "^14.1.0",
"devDependencies.eslint-config-prettier": "^7.2.0",
"devDependencies.eslint-config-prettier": "^8.1.0",
"devDependencies.eslint-plugin-import": "^2.22.0",
"devDependencies.eslint-plugin-jest": "^24.1.5",
"devDependencies.eslint-plugin-prettier": "^3.3.1",
Expand All @@ -71,10 +71,10 @@
"devDependencies.readmeasy": "^0.2.7",
"devDependencies.ts-jest": "^26.5.1",
"devDependencies.ts-node-dev": "^1.1.1",
"devDependencies.typedoc": "^0.20.27",
"devDependencies.typedoc": "^0.20.28",
"devDependencies.typedoc-neo-theme": "^1.1.0",
"devDependencies.typedoc-plugin-example-tag": "^1.0.2",
"devDependencies.typedoc-plugin-markdown": "^3.5.0",
"devDependencies.typedoc-plugin-markdown": "^3.6.0",
"devDependencies.typedoc-plugin-param-names": "^2.0.0",
"devDependencies.typescript": "^4.1.5",
"devDependencies.vuepress": "^1.8.2",
Expand Down
14 changes: 11 additions & 3 deletions docs/nav.01.guide/guide--nc/relation-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Whereas foreign keys are defined in DBMS and have names, relations are not prese

## Builtin Naming Modules

`pg-structure` provides two built-in modules: `short` and `descriptive`. They use foreign key names, join table names, and target table names to generate relation names.
`pg-structure` provides some built-in modules: `short`, `optimal` and `descriptive`. They use foreign key names, join table names, and target table names to generate relation names.

### Foreign Key Names

Expand All @@ -20,7 +20,15 @@ To use built-in functions effectively, foreign keys should be named as one of th
- **Tables & Optional Adjectives:** adjective_table1_adjective_table2 (i.e. `product_alternative_vendor`, `alternative_vendor_products` or `alternative_vendor_primary_products`)
- **Separator:** source,target or target,source (i.e. `item,supplier`, `supplier,items` or `item,alternative_supplier` )

Both `short` and `descriptive` functions are developed based on long experience in PostgreSQL, but they **do not guarantee** to produce unique names in all possible scenarios. `descriptive` function has less chance to cause name collisions compared to `short`.
Built-in functions are developed based on long experience in PostgreSQL, but they **do not guarantee** to produce unique names in all possible scenarios. `optimal``descriptive` function has less chance to cause name collisions compared to `short`.

Please note that `optimal` is not deterministic, whereas `short` and `descriptive` are. `optimal` uses `short` names where possible. If there are collisions using `short` names, `optimal` uses `descripive` names.

| Built-in Functions | Type | Features |
| ------------------ | ----------------- | --------------------------------------------------------------------------------------------------- |
| `short` | Deterministic | Produces short names, but may result with naming collisions, if databse contains complex relations. |
| `descriptive` | Deterministic | Produces long names especially if foreign keys are named well. Less chance of naming collisions. |
| `optimal` | Non-Deterministic | Produces short names where possible, otherwise produces descriptive names. |

## Example Results

Expand Down Expand Up @@ -57,7 +65,7 @@ Below are generated names for example. Differences between short and long are in

</div>

Provided built-in functions `short` and `descriptive` try to generate the shortest name possible considering the number of relations and number of join tables between same tables. `descriptive` adds adjectives more freely compared to `short`. Most of the time, they generate the same names.
Provided built-in functions `short` and `optimal` try to generate the shortest name possible considering the number of relations and number of join tables between same tables. `optimal` adds adjectives more freely compared to `short`. Most of the time, they generate the same names.

## Custom Modules or Functions

Expand Down
2 changes: 0 additions & 2 deletions module-files/configs/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = {
"eslint:recommended", // TURN ON ESLint recommended rules.
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended", // TURN ON TypeScript rules by using `typescript-eslint/typescript-eslint`.
"prettier/@typescript-eslint", // TURN OFF ESLint TypesSript rules which conflict with Prettier by using `prettier/eslint-config-prettier`.
],
plugins: ["@typescript-eslint"],
settings: {
Expand Down Expand Up @@ -63,7 +62,6 @@ module.exports = {
"plugin:jest/recommended", // TURN ON Jest rules by using "jest-community/eslint-plugin-jest".
"airbnb-base", // TURN ON airbnb-base rules.
"plugin:prettier/recommended", // RUN Prettier as ESLint rule by using `prettier/eslint-plugin-prettier` and TURN OFF ESLint rules which conflict with Prettier by using `prettier/eslint-config-prettier`.
"prettier/@typescript-eslint", // TURN OFF ESLint TypesSript rules which conflict with Prettier by using `prettier/eslint-config-prettier`.
],
},
],
Expand Down
Loading

0 comments on commit 715dd11

Please sign in to comment.