0.3.0 • Published 4 years ago

@coopersystem-fsd/typeorm-naming-strategy v0.3.0

Weekly downloads
8
License
MIT
Repository
-
Last release
4 years ago

Coopersystem Naming Strategy for TypeORM

GitHub Workflow Status

This package provide a custom naming strategies. The generated names are based on the column names.

Examples

ContraintTableColumn(s)Result
Primary KeyuseridPK_user
Foreign Keyuser -> photophoto_id (user) -> id (photo)FK_user_photo
Unique Constraintuseremail, social_securityUK_user_email_social_security
Indexuserfirst_name, last_nameIDX_user_first_name_last_name
DefaultuseractiveDF_user_active

Installation

:warning: Attention: Under the hood we are using the package typeorm-naming-strategies extending the strategy SnakeNamingStrategy.

yarn add @coopersystem-fsd/typeorm-naming-strategy

or with npm

npm i @coopersystem-fsd/typeorm-naming-strategy

Usage

In your database configuration file, add the option namingStrategy informing the CustomNamingStrategy class. And, That's all.

:warning: Attention: For use namingStrategy option, it is necessary to implement the connection settings in a separate file so that it is possible to pass it as a parameter in the execution of TypeORM commands by cli.

import * as dotenv from 'dotenv';
import { ConnectionOptions } from 'typeorm';

import { CustomNamingStrategy } from '@coopersystem-fsd/custom-naming-strategy';

const env = dotenv.parse('../../');
dotenv.config(env);

const config: ConnectionOptions = {
  type: 'postgres',
  host: process.env.DB_HOST,
  port: parseInt(process.env.DB_PORT),
  username: process.env.DB_USERNAME,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_DATABASE,
  namingStrategy: new CustomNamingStrategy(),
  entities: ['dist/modules/**/*.entity{.ts,.js}'],
  migrations: ['dist/database/migrations/*.js'],
  cli: {
    migrationsDir: 'src/database/migrations',
  },
};

module.exports = config;

To Do

  • Generate check constraint names
0.3.0

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago