-
-
Notifications
You must be signed in to change notification settings - Fork 629
Add connection.end()
call to quickstart documentation
#2543
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
Comments
Hey @neoncube2, would you like to contribute? 🙋🏻♂️ It could be included in the first example (for both the promise and the callback), closing the connection at the end of the examples:
node-mysql2/website/docs/index.mdx Lines 75 to 107 in a9c6c3e
node-mysql2/website/docs/index.mdx Lines 114 to 140 in a9c6c3e
|
@wellwelwel Sure, I'd be happy to! :) I'm thinking I'd use a // Get the client
import mysql from 'mysql2/promise';
// Create the connection to database
const connection = await mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'test',
});
try {
// A simple SELECT query
try {
const [results, fields] = await connection.query(
'SELECT * FROM `table` WHERE `name` = "Page" AND `age` > 45'
);
console.log(results); // results contains rows returned by server
console.log(fields); // fields contains extra meta data about results, if available
} catch (err) {
console.log(err);
}
// Using placeholders
try {
const [results] = await connection.query(
'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',
['Page', 45]
);
console.log(results);
} catch (err) {
console.log(err);
}
} finally {
connection.end()
} |
Thanks, @neoncube2 🤝 I think we can keep it simple for the quick examples: // Get the client
import mysql from 'mysql2/promise';
// Create the connection to database
const connection = await mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'test',
});
// A simple SELECT query
try {
const [results, fields] = await connection.query(
'SELECT * FROM `table` WHERE `name` = "Page" AND `age` > 45'
);
console.log(results); // results contains rows returned by server
console.log(fields); // fields contains extra meta data about results, if available
} catch (err) {
console.log(err);
}
// Using placeholders
try {
const [results] = await connection.query(
'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',
['Page', 45]
);
console.log(results);
} catch (err) {
console.log(err);
}
// Close the connection
await connection.end(); What do you think? 🙋🏻♂️ |
The quickstart examples (https://sidorares.github.io/node-mysql2/docs) don't yet document that people should call either
connection.end()
orconnection.close()
one they're finished with their connection.The text was updated successfully, but these errors were encountered: