npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

better-typeorm-naming-strategies

v1.0.2

Published

Better naming strategies for typeorm

Downloads

18

Readme

✨ Better TypeORM Naming Strategies

npm version License: MIT

A modern, drop-in naming strategy for TypeORM that makes your database schema more readable and consistent. Say goodbye to cryptic, auto-generated database names and hello to clean, snake_cased tables and columns, and human-readable constraint names.

This package provides a BetterNamingStrategy that can be configured to your needs.

🤔 Why?

TypeORM's default naming strategy can lead to database schemas that are hard to read. For example, it preserves camelCase from your entity definitions and generates long, unreadable hash-based names for foreign keys and indices.

This package fixes that by providing two main features:

  • 🐍 snake_case everything: Automatically transforms your camelCase entity properties into snake_case table and column names.
  • 🏷️ Readable constraints: Generates clear, descriptive names for your primary keys, foreign keys, and indices based on the tables and columns they affect.

🚀 Installation

Install with your favorite package manager:

# npm
npm install better-typeorm-naming-strategies

# yarn
yarn add better-typeorm-naming-strategies

# pnpm
pnpm add better-typeorm-naming-strategies

Usage

Import and add BetterNamingStrategy to your TypeORM data source options.

With a DataSource instance:

import { DataSource } from 'typeorm';
import { BetterNamingStrategy } from 'better-typeorm-naming-strategies';

const myDataSource = new DataSource({
  // ... other options
  namingStrategy: new BetterNamingStrategy(),
});

With an ormconfig file:

For a CommonJS ormconfig.js file:

const { BetterNamingStrategy } = require('better-typeorm-naming-strategies');

module.exports = {
  // ... other options
  namingStrategy: new BetterNamingStrategy(),
};

For an ES Modules ormconfig.ts file:

import { BetterNamingStrategy } from 'better-typeorm-naming-strategies';
import { DataSourceOptions } from 'typeorm';

const config: DataSourceOptions = {
  // ... other options
  namingStrategy: new BetterNamingStrategy(),
};

export default config;

The strategy works out of the box with sensible defaults, but you can configure it to your liking.

⚙️ Options

The BetterNamingStrategy constructor accepts an options object:

new BetterNamingStrategy(options?: {
  snakeCase?: boolean;
  betterConstraintAndIndexNames?: boolean;
});

| Option | Description | Default | | ------------------------------- | ----------------------------------------------- | :-----: | | snakeCase | Use snake_case for tables and columns. | true | | betterConstraintAndIndexNames | Use readable names for constraints and indices. | true |

Example Configuration

// This will ONLY enable snake_case naming
const strategy = new BetterNamingStrategy({
  snakeCase: true,
  betterConstraintAndIndexNames: false,
});

✨ Features in Detail

🐍 snake_case

When snakeCase: true, your entity's camelCase properties are automatically converted to snake_case in the database.

Before: An entity like this...

@Entity()
export class UserProfile {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  displayName: string;

  @Column()
  photoUrl: string;
}

...would create a table named user_profile with columns display_name and photo_url.

🏷️ Readable Constraint and Index Names

When betterConstraintAndIndexNames: true, your constraints and indices get simple, readable names.

Example: Consider these two related entities:

// User.ts
@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true })
  email: string;

  @OneToOne(() => UserProfile, (profile) => profile.user)
  profile: UserProfile;
}

// UserProfile.ts
@Entity()
@Index(['displayName']) // Example for a simple index
export class UserProfile {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  displayName: string;

  @OneToOne(() => User)
  @JoinColumn() // Creates a 'userId' foreign key column
  user: User;
}

Before (default TypeORM): Your constraints would have cryptic, generated names.

  • Foreign Key on userId: FK_b75a68b1ca018c3daa0bb77731b
  • Unique Constraint on email: UQ_e12875dfb3b1d92d7d7c5377e22
  • Index on displayName: IDX_f8ade2f823f9b1e3b3b1c6d3b3

After (with BetterNamingStrategy): The names become clear and predictable.

  • Foreign Key on userId: FK_user_profile_user_id
  • Unique Constraint on email: UQ_user_email
  • Index on displayName: IDX_user_profile_display_name

No more guessing what a constraint does!

🙏 Acknowledgements

This package is heavily inspired by the great work done in typeorm-naming-strategies by tonivj5. This version modernizes the package, adds more flexible configuration, and depends on latest TypeORM version.

License

This project is licensed under the MIT License.