diff --git a/website/docs/index.mdx b/website/docs/index.mdx index 90cda8cd0b..f9d69207e1 100644 --- a/website/docs/index.mdx +++ b/website/docs/index.mdx @@ -105,6 +105,9 @@ try { } catch (err) { console.log(err); } + +// Close the connection +await connection.end(); ``` @@ -138,6 +141,9 @@ connection.query( console.log(results); } ); + +// Close the connection +connection.end(); ``` @@ -161,9 +167,11 @@ MySQL2 provides `execute` helper which will prepare and query the statement. You ```js import mysql from 'mysql2/promise'; +let connection; + try { // create the connection to database - const connection = await mysql.createConnection({ + connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test', @@ -179,6 +187,8 @@ try { console.log(fields); // fields contains extra meta data about results, if available } catch (err) { console.log(err); +} finally { + connection.end() } ``` @@ -204,6 +214,9 @@ connection.execute( console.log(fields); // fields contains extra meta data about results, if available } ); + +// Close the connection +connection.end(); ```