Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Is there no way to create a connection pool using a database URI? #1669

Closed
cmmartin opened this issue Nov 6, 2022 · 3 comments
Closed

Is there no way to create a connection pool using a database URI? #1669

cmmartin opened this issue Nov 6, 2022 · 3 comments

Comments

@cmmartin
Copy link
Contributor

cmmartin commented Nov 6, 2022

I'm using planetscale which injects a DATABASE_URL env variable. createConnection accepts a connection string, but createPool does not. Is there any way to create a connection pool with a database url?

@rafipiccolo
Copy link

What makes you think it doesnt work ?

they both work :

const connectionstring = 'mysql://xxxxxx:xxxxx@xxxxxx.fr/xxxx?charset=utf8mb4&connectionLimit=10'
const pool = mysql.createPool(connectionstring);
const connection = mysql.createConnection(connectionstring);

@sidorares
Copy link
Owner

PoolConfig does accept string argument:

return new Pool({ config: new PoolConfig(config) });

options = ConnectionConfig.parseUrl(options);

@cmmartin
Copy link
Contributor Author

cmmartin commented Nov 7, 2022

@rafipiccolo @sidorares You're right it does work. But according to the typescript types in the promise package, createConnection can take a string or config, but createPool can only take a config...

https://github.com/sidorares/node-mysql2/blob/master/promise.d.ts#L144-L148

export function createConnection(connectionUri: string): Promise<Connection>;
export function createConnection(
  config: ConnectionOptions
): Promise<Connection>;
export function createPool(config: PoolOptions): Pool;

So you get a typescript error if you pass it a connection string: Type 'string' has no properties in common with type 'PoolOptions'

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants