🚀 Socket Launch Week 🚀 Day 4: Introducing Historical Analytics.Learn More
Socket
Sign inDemoInstall
Socket

typeorm-naming-strategy

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeorm-naming-strategy

Custom naming strategies for typeorm

2.0.13
latest
Source
npm
Version published
Weekly downloads
1.1K
25.53%
Maintainers
1
Weekly downloads
 
Created
Source

Typeorm naming strategy

ci Latest Version on NPM Software License npm npm

This package provides a few (one, at the moment) useful custom naming strategies. It alliterates the name of columns, relations, and other fields in the 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-naming-strategy --save

Or using yarn

yarn add typeorm-naming-strategy

Usage

import { createConnection } from 'typeorm'
// import { SnakeNamingStrategy } from 'typeorm-naming-strategy';
import SnakeNamingStrategy from 'typeorm-naming-strategy'

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

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

// Use require instead of import
// const SnakeNamingStrategy = require("typeorm-naming-strategy").SnakeNamingStrategy
const SnakeNamingStrategy = require('typeorm-naming-strategy')

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

Or you can use it in combination with a ormconfig.ts

import SnakeNamingStrategy from 'typeorm-naming-strategy'

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

Use with NestJs configuration

import type { MysqlConnectionOptions } from 'typeorm/driver/mysql/MysqlConnectionOptions'
import { registerAs } from '@nestjs/config'
import { SnakeNamingStrategy } from 'typeorm-naming-strategy'

export default registerAs('database', (): MysqlConnectionOptions => ({
  // ...
  namingStrategy: new SnakeNamingStrategy(),
  // ...
}))

Keywords

typeorm

FAQs

Package last updated on 08 Apr 2025

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