Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

typeorm-postgres-naming-strategies

nopain2110397MIT3.0.2TypeScript support: included

Strict snake case naming strategies for typeorm postgres

typeorm, naming, strategy, node, orm, naming strategy, snake strategy, typeorm snake, naming strategies, postgres strategy

readme

Typeorm naming strategies

This package provides a few (one, at the moment) useful custom naming strategies. It alterates the name of columns, relations and other fields in database.

For example, using the snake strategy, if you have a model like this:

class User {
  @Column()
  createdAt;
}

In the DB the createdAt field will be created_at

Naming strategies available

  • Snake

Installation

It's available as an npm package

npm install typeorm-postgres-naming-strategies --save

Or using yarn

yarn add typeorm-postgres-naming-strategies

Usage

import { createConnection } from 'typeorm';
import { PostgresNamingStrategy } from 'typeorm-postgres-naming-strategies';

await createConnection({
  ...
  namingStrategy: new PostgresNamingStrategy(), // Here you'r using the strategy!
});

Alternatively you can use it in combination with a ormconfig.js

// Use require instead of import
const PostgresNamingStrategy = require("typeorm-postgres-naming-strategies").PostgresNamingStrategy

module.exports = {
  ...
  namingStrategy: new PostgresNamingStrategy(),
}