1.0.18 • Published 4 years ago

@z-brain/typeorm-postgres-camelcase-naming-strategy v1.0.18

Weekly downloads
5
License
GPL-3.0
Repository
github
Last release
4 years ago

Z-Brain TypeORM PostgreSQL Camelcase Naming Strategy

Pascal/Camel Case naming for everything in the PostgreSQL

Notice: If you have any propositions feel free to make an issue or create a pull request.

Features

  • All constraint names appended with 8-char hash for uniqueness. Example: eed18e0e
  • All names trimmed to 63 bytes including 8-char hash if the name is too long (in most cases length === bytes number, however not always).
  • There is an ability to have some suffixes to entity classes and omit these suffixes in the DB table names.
    Example: PublicTradeEntity -> PublicTrades (default entity suffix is Entity)
  • There is an ability to have some in-db suffixes on entity classes that should not be pluralized and should be added as is to the DB table names.
    Example: PublicTradeZipEntity -> PublicTradesZip (default in-db suffix is Zip)
Naming entityCaseExamples
TablePascalCaseUsers, MySuperTable
ColumnCamelCaseid, mySuperColumn
Enum(not supported by TypeORM yet)
Primary KeyPK_{table}_{cols}_{hash}PK_Instruments_id_bd441074, PK_MySuperTable_email,pwdHash_d1d1d1d1
Unique ConstrainUQ_{table}_{cols}_{hash}UQ_Instruments_code_051d8d38, UQ_MySuperTable_firstName,lastName_d1d1d1d1
Default ConstrainDF_{table}_{col}_{hash}DF_Users_email_d1d1d1d1, DF_MySuperTable_firstName_d1d1d1d1
Relation ConstrainREL_{table}_{cols}_{where}_{hash}TODO example
Check ConstrainCHK_{table}_{expression}_{hash}TODO example
Exclusion ConstrainXCL_{table}_{expression}_{hash}TODO example
Foreign KeyFK_{table}_{targetTable}_{cols}_{targetCols}_{hash}FK_TradingPairs_Instruments_quotedInstrumentId_id_fc68de3f
IndexIDX_{table}_{cols}_{hash}IDX_Tickers_exchangeId,symbol_c8090854
Unique IndexUQIDX_{table}_{cols}_{hash}UQIDX_Tickers_exchangeId,symbol_c8090854

How to use

Installing

yarn add @z-brain/typeorm-postgres-camelcase-naming-strategy
or
npm i -s @z-brain/typeorm-postgres-camelcase-naming-strategy

Configuring

/ormconfig.ts

import { TypeORMPostgresCamelCaseNamingStrategy } from '@z-brain/typeorm-postgres-camelcase-naming-strategy';

// Store an instance separately for reuse methods in you app
export const typeORMNamingStrategy = new TypeORMPostgresCamelCaseNamingStrategy();

// TypeORM connection config for PostgreSQL
export const defaultConnection: ConnectionOptions = {
  // ...
  namingStrategy: typeORMNamingStrategy,
};

module.exports = [defaultConnection];

Development notes

Quick Start

cd /code/z-brain
git clone git@github.com:z-brain/typeorm-postgres-camelcase-naming-strategy.git
cd typeorm-postgres-camelcase-naming-strategy
yarn install

How to use NodeJS version from the .nvmrc

  1. Install NVM
  2. Use .nvmrc file one of the next ways:

    • Execute nvm use in the project root directory
    • Install NVM Loader and your .nvmrc will be loaded automatically when you open the terminal. NVM Loader demo

How to make a build

npm run build

How to run lint

  • Just show problems npm run lint
  • Fix problems if it is possible npm run lint:fix

How to run tests

  • All tests

    npm run test
    npm run test:watch

  • Specific tests

    npm run test -- src/my.spec.ts
    npm run test:watch -- src/my.spec.ts

How to build and publish NPM package

NPM Token: 367a...ce73

CI configuration details here: .github/workflows/npmpublish.yml

yarn run pre-push \
&& npm version patch -m 'Update package version version to %s' \
&& yarn run gen-public-package.json \
&& cp README.md dist/ \
&& npm publish dist --access public \
&& git push --no-verify && git push --tags --no-verify

Author

Anton Korniychuk
1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago