Skip to content

Feature: expose option.database as Sequelize.getDatabaseName() #9924

@zypA13510

Description

@zypA13510

When I use raw queries (read use case below), I need to include database/schema name in the query. I noticed that I can retrieve it from sequelize.config.database, but this is not documented thus a rather dangerous approach I suppose. So I'm requesting if it is possible to expose the option as a function.

Of course, I know that I can just pass the string along from where the options are supplied, but I think it would be more convenient if we can retrieve it from the sequelize instance since we have it already?

Dialect: MySQL (I'm not sure if this is dialect specific)

My use case

Get current AUTO_INCREMENT value of a table from information_schema:

let databaseName// = ???
let tableName = sequelize.models.MyTable.name
let autoIncrementValue
sequelize.query(`
  SELECT AUTO_INCREMENT
  FROM information_schema.TABLES
  WHERE
    TABLE_SCHEMA = '${databaseName}'
    AND TABLE_NAME = '${tableName}'
`, {
  type: Sequelize.QueryTypes.SELECT
}).then(result => {
  autoIncrementValue = result
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueFor issues. An issue that is a good choice for first-time contributors.type: featureDEPRECATED: replace with the "feature" issue type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions