Snake case naming strategy for typeorm. Determines table and column names from class and property names.

Hierarchy

  • DefaultNamingStrategy
    • SnakeNamingStrategy

Implements

  • NamingStrategyInterface

Constructors

Properties

materializedPathColumnName: string

Column name for materialized paths.

nestedSetColumnNames: { left: string; right: string }

Column names for nested sets.

Methods

  • Gets the name of the check constraint.

    "isEnum" parameter is used to indicate if this check constraint used to handle "simple-enum" type for databases that are not supporting "enum" type out of the box. If "true", constraint is ignored during CHECK constraints synchronization.

    Parameters

    • tableOrName: string | Table
    • expression: string
    • OptionalisEnum: boolean

    Returns string

  • Creates a table name for a junction table of a closure table.

    Parameters

    • originalClosureTableName: string

      Name of the closure table which owns this junction table.

    Returns string

  • Create a column name from a property name.

    Parameters

    • propertyName: string

      The property name of the entity

    • OptionalcustomName: string

      The custom column name

    • embeddedPrefixes: string[] = []

      The embedded prefixes

    Returns string

    The table column name

    @Entity()
    class User {
    @Column()
    firstName: string; // returns 'first_name'

    @Column('custom_last_name')
    lastName: string; // returns 'custom_last_name'
    }
  • Gets the table's default constraint name from the given table name and column name.

    Parameters

    • tableOrName: string | Table
    • columnName: string

    Returns string

  • Parameters

    • alias: string
    • propertyPath: string

    Returns string

  • Gets the name of the exclusion constraint.

    Parameters

    • tableOrName: string | Table
    • expression: string

    Returns string

  • Create a foreign key name.

    Parameters

    • tableOrName: string | Table

      The table or table name

    • columnNames: string[]

      The column names

    Returns string

    The foreign key name

    @Entity()
    class User {
    @PrimaryColumn()
    id: string;
    }
    @Entity()
    class Post {
    @PrimaryColumn()
    id: string;

    @ManyToOne(() => User, user => user.posts)
    user: User;
    }

    // returns 'fk_posts__user_id__users__id'
  • Parameters

    • tableOrName: string | Table

    Returns string

  • Create an index name.

    Parameters

    • tableOrName: string | Table

      The table or table name

    • columnNames: string[]

      The column names

    Returns string

    The index name

    @Entity()
    class User {
    @Index()
    @Column()
    email: string;
    }
    // returns 'idx_users__email'
  • Parameters

    • relationName: string
    • referencedColumnName: string

    Returns string

  • Columns in join tables can have duplicate names in case of self-referencing. This method provide a resolution for such column names.

    Parameters

    • columnName: string
    • index: number

    Returns string

  • Parameters

    • tableName: string
    • propertyName: string
    • OptionalcolumnName: string

    Returns string

  • Gets the name of the column used for columns in the junction tables from the invers side of the relationship.

    Parameters

    • tableName: string
    • propertyName: string
    • OptionalcolumnName: string

    Returns string

  • Create join table name for many-to-many relations.

    Parameters

    • firstTableName: string
    • secondTableName: string

    Returns string

    join table name

    @Entity()
    class Post {
    @ManyToMany(() => Theme) // post_to_theme
    themes: Theme[];
  • Adds globally set prefix to the table name. This method is executed no matter if prefix was set or not. Table name is either user's given table name, either name generated from entity target. Note that table name comes here already normalized by #tableName method.

    Parameters

    • prefix: string
    • tableName: string

    Returns string

  • Create a primary key name.

    Parameters

    • tableOrName: string | Table

      The table or table name

    • columnNames: string[]

      The column names

    Returns string

    The primary key name

    @Entity()
    class User {
    @PrimaryColumn()
    id: string;
    }

  • Gets the relation constraint (UNIQUE or UNIQUE INDEX) name from the given table name, column names and WHERE condition, if UNIQUE INDEX used.

    Parameters

    • tableOrName: string | Table
    • columnNames: string[]
    • Optionalwhere: string

    Returns string

  • Parameters

    • propertyName: string

    Returns string

  • Create a table name from a class name.

    Parameters

    • className: string

      The class name of the entity

    • OptionalcustomName: string

      The custom table name

    Returns string

    The table name

    @Entity()
    class User {}
    // returns 'users'

    @Entity('custom_table_name')
    class User {}
    // returns 'custom_table_name'
  • Create a unique constraint name.

    Parameters

    • tableOrName: string | Table

      The table or table name

    • columnNames: string[]

      The column names

    Returns string

    The unique constraint name

    @Entity()
    class User {
    @Unique()
    @Column()
    email: string;
    }
    // returns 'uq_users__email'