Skip to content
New issue

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

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

Already on GitHub? Sign in 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:[email protected]/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'

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

No branches or pull requests

3 participants