node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

Feature Request: Allow setting connectionAttributes in the connectionConfig

Open mamof opened this issue 3 years ago • 4 comments

Trying to set the program_name value on the connection so I can define which program is accessing the database. Using JDBC it would be handled in the connection string: jdbc:mysql://localhost/database?connectionAttributes=program_name:Login Server,other_name:other Setting the attributes currently gives an invalid configuration warning about connectionAttributes not being supported. It would be helpful to be able to get these options in there. https://dev.mysql.com/doc/refman/5.7/en/performance-schema-connection-attribute-tables.html

mamof avatar Feb 03 '22 19:02 mamof

agree, that would be a useful feature. If I direct you to related parts of the code would you be able to contribute this?

sidorares avatar Feb 03 '22 22:02 sidorares

I'd be more than happy to give it a shot

mamof avatar Feb 03 '22 22:02 mamof

so we already have "connectAttributes" as a valid field in ConnectionConfig, when set it'll be passed as keys:values object during client handshake response. We probably need to add support for it in the parseUrl here https://github.com/sidorares/node-mysql2/blob/dadef383098b0823a90e07fbec18639bd612adfb/lib/connection_config.js#L251

Not sure if worth renaming to connectionAttributes but we could add it as an alias ( so that both connectAttributes and connectionAttributes mean the same )

sidorares avatar Feb 03 '22 22:02 sidorares

Awesome. I'll dig into it. Thanks for the pointer!

mamof avatar Feb 03 '22 23:02 mamof