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

Attribute "promise" does not exist on type "Connection" #1936

Closed
tomoat opened this issue Apr 7, 2023 · 5 comments
Closed

Attribute "promise" does not exist on type "Connection" #1936

tomoat opened this issue Apr 7, 2023 · 5 comments

Comments

@tomoat
Copy link

tomoat commented Apr 7, 2023

Attribute "promise" does not exist on type "Connection"

import mysql from 'mysql2'
import util from 'util'

const conn = mysql.createConnection({
host: '127.0.0.1',
user: 'root',
password: '12345678',
port: 3306,
database: 'domain',
rowsAsArray: true,
})

const db = conn.promise() // This line reported an error
export { db }

@gtavos
Copy link

gtavos commented Apr 13, 2023

Even from mysql2/promise the promise() option is not available in Connection class. Is it available in 3.2.0 or lower versions?

@sidorares
Copy link
Owner

Looks like #1949 should fix the issue

@newtoncodes
Copy link

Doesn't seem right.
Here is the code: https://github.com/sidorares/node-mysql2/blob/master/lib/connection.js#L155
It should not return a promise. All my implementations require createConnection and .promise() to directly return a connection instance. Seems like the code is right, but the typings are wrong in the new version as well.

@wellwelwel
Copy link
Collaborator

@tomoat, can you try it in version ^3.3.5?

@wellwelwel
Copy link
Collaborator

After version ^3.3.5, you can follow this example:

const db = mysql.createConnection(access).promise();
{
/** Overload: execute(sql) */
const [results, fields] = await db.execute(sql);
console.log(results, fields);
}


I'm closing this Issue, but feel free to ask anything 🙋🏻‍♂️

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

No branches or pull requests

5 participants