Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the Application Name for a Sequelize application

I've got a nodejs application that uses Sequelize as it's ORM. I've successfully got Sequelize connected to the database, but I haven't found anything in the documentation that explains how to set the application name. To clarify I'm looking to set a unique Application Name attribute for my app's connection string. That way when a DBA is looking at traffic they can pick out my application's queries from the rest.

Is this something that Sequelize can even do? Or does this need to be done at the tedious level? Failing that, is there a way in nodejs to specify connection string attributes?

like image 866
OrwellHindenberg Avatar asked Oct 15 '25 20:10

OrwellHindenberg


2 Answers

Tedious allows setting the app name with the appName config param. You should be able to set this via the dialectOptions object when creating your Sequelize connection:

var conn = new Sequelize('my_db', 'my_user', 'my_pass', {
  host: 'my_server',
  dialect: 'mssql',

  dialectOptions: {
    appName: 'my_app_name'
  }
});
like image 165
Tom Jardine-McNamara Avatar answered Oct 17 '25 12:10

Tom Jardine-McNamara


For those finding this when they're looking for how to set the name for Postgres, you use application_name in the dialectOptions, eg

{
    username: process.env.DB_USER,
    password: process.env.DB_PASS,
    database: process.env.DB_NAME,
    port: process.env.DB_PORT,
    host: DB_HOST,
    dialect: 'postgresql',
    dialectOptions: {
        application_name: 'My Node App',
    },
},
like image 37
ChrisJ Avatar answered Oct 17 '25 13:10

ChrisJ