Skip to content

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

Closed

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
})

Activity

  1. added
    type: feature
    good first issue
    on Sep 17, 2018
  2. sushantdhiman commented on Sep 19, 2018

    @sushantdhiman
    Contributor

    Implemented in #9937

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

    good first issuetype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions