New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

typeorm-naming-strategies

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeorm-naming-strategies

Custom naming strategies for typeorm

  • 4.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
214K
increased by0.62%
Maintainers
1
Weekly downloads
 
Created

What is typeorm-naming-strategies?

The typeorm-naming-strategies npm package provides custom naming strategies for TypeORM, allowing developers to define how database table and column names are generated. This can be particularly useful for ensuring consistency and readability in database schemas.

What are typeorm-naming-strategies's main functionalities?

SnakeCaseNamingStrategy

The SnakeCaseNamingStrategy converts camelCase or PascalCase names to snake_case. This is useful for databases that prefer or require snake_case naming conventions.

const { SnakeNamingStrategy } = require('typeorm-naming-strategies');
const { createConnection } = require('typeorm');

createConnection({
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'test',
  password: 'test',
  database: 'test',
  entities: [__dirname + '/entity/*.js'],
  namingStrategy: new SnakeNamingStrategy()
}).then(connection => {
  // Here you can start to work with your entities
}).catch(error => console.log(error));

CustomNamingStrategy

The CustomNamingStrategy allows developers to define their own naming conventions. In this example, table names are suffixed with '_tbl' and column names are converted to lowercase.

const { DefaultNamingStrategy, Table } = require('typeorm');

class CustomNamingStrategy extends DefaultNamingStrategy {
  tableName(className, customName) {
    return customName ? customName : className.toLowerCase() + '_tbl';
  }

  columnName(propertyName, customName, embeddedPrefixes) {
    return (embeddedPrefixes.join('_') + (customName ? customName : propertyName)).toLowerCase();
  }
}

const { createConnection } = require('typeorm');

createConnection({
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'test',
  password: 'test',
  database: 'test',
  entities: [__dirname + '/entity/*.js'],
  namingStrategy: new CustomNamingStrategy()
}).then(connection => {
  // Here you can start to work with your entities
}).catch(error => console.log(error));

Other packages similar to typeorm-naming-strategies

Keywords

FAQs

Package last updated on 27 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc