Skip to content

Default to snake_case for table and column names #13896

Closed as not planned
Closed as not planned

Description

@sdepold

Historically, Sequelize has always been using CamelCase for table names and column names. Looking into the industry "standards", it seems that the majority prefer snake_case however making queries easier to read and also allowing to remove quotes in pg for example.

Example:

JS/TS:

define('User', {
  homeAddress: DataTypes.STRING
})

Database:

table name: users

columns:
id
home_address
created_at
updated_at

Activity

  1. added
    type: refactor
    on Jan 4, 2022
  2. ericyd commented on Jan 5, 2022

    @ericyd

    My understanding is that the underscored property is for. When true, this property uses snake_case for the database columns and camelCase in the ORM. Since JS convention is camelCase I think this is the preferred method if you want to use snake_case in the DB

  3. ephys commented on Jan 6, 2022

    @ephys
    Member

    It is what that property is for, the idea for v7 would be to turn it on by default to follow sql conventions. Could still be turned off if you'd rather have camelCase names in the database.

  4. mariusa commented on Mar 3, 2022

    @mariusa

    Could still be turned off

    Would you please specify how to turn it off? We prefer camelCase naming for db columns too.
    Hope it's not per model. If so, sequelize-auto should also support this flag when generating models.

  5. ephys commented on Mar 3, 2022

    @ephys
    Member

    It's just an API draft but I suppose you'd turn it off the same way you turn it on today: by setting the underscored option

    UserModel.init({}, {
      // disable auto-snake_case
      underscored: false,
    })

    It looks like underscored can't be configured globally right now but it shouldn't be too hard to add a way to do it:

    const sequelize = new Sequelize({
      // disable auto-snake_case for all models (except those that specifically turn it back on)
      underscored: false,
    });
  6. added
    type: feature
    breaking change
    and removed
    type: refactor
    on Apr 16, 2022
  7. ephys commented on Mar 27, 2024

    @ephys
    Member

    Because not all dialects follow the same conventions, I'll close in favor of #15312 which define how dialects could specify their default naming strategy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changetype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions