node-mysql2
node-mysql2 copied to clipboard
Is it possible to create a pool from a connection string?
For example, to create a single connection using a connection string we do:
mysql.createConnection(connectionString);
I can't seem to find a way to do the same to create a pool, is it possible?
Ah - is this the uri property passed to the createPool function?
hm, I'd really like .createPool to match .createConnection in a way that it treats single string parameter as a connection uri
I'll keep this issue open as a place for discussion why this is a good or bad idea
actually I believe this is already behaviour for .createPool
https://github.com/sidorares/node-mysql2/blob/dbb344e89a1cc8bb457b24e67b07cdb3013fe844/index.js#L22
https://github.com/sidorares/node-mysql2/blob/dbb344e89a1cc8bb457b24e67b07cdb3013fe844/lib/pool_config.js#L8
What have you tried @rcoundon , what result you see and what you expected to see?
Thanks for getting back to me. What I ended up doing that works is to specify the URL as the uri property of the poolConfig. i.e.
const pool = mysql.createPool({
uri: connectionString,
})
When trying to pass a string to the createPool method TypeScript complains so it's probably a case that the types aren't quite right. I'll submit a PR to add a string as a possible option to the createPool method.
It looks like the types here haven't been touched in a long while and could be improved - e.g. there are lots of implicit any errors in the tests.
If you like, I'll work on improving them and bringing it all up-to-date but will commit this PR for this issue and pick up later as I have a bit of time pressure right now