From 992236cbce1337daa175d763be97c5fdf9e2b1c2 Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Sat, 8 Feb 2025 14:25:02 +0100 Subject: [PATCH 1/2] feat: allow to specify ssl: true in connection options --- lib/base/connection.js | 5 +++++ typings/mysql/lib/Connection.d.ts | 2 +- website/docs/documentation/ssl.mdx | 4 ++-- website/docs/examples/connections/create-connection.mdx | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/base/connection.js b/lib/base/connection.js index d00ce8c1f6..391edc7105 100644 --- a/lib/base/connection.js +++ b/lib/base/connection.js @@ -37,6 +37,11 @@ class BaseConnection extends EventEmitter { constructor(opts) { super(); this.config = opts.config; + + if (typeof this.config.ssl === 'boolean' ) { + this.config.ssl = this.config.ssl === true ? {} : undefined; + } + // TODO: fill defaults // if no params, connect to /var/lib/mysql/mysql.sock ( /tmp/mysql.sock on OSX ) // if host is given, connect to host:3306 diff --git a/typings/mysql/lib/Connection.d.ts b/typings/mysql/lib/Connection.d.ts index d55ae7aa59..91ad7d0196 100644 --- a/typings/mysql/lib/Connection.d.ts +++ b/typings/mysql/lib/Connection.d.ts @@ -268,7 +268,7 @@ export interface ConnectionOptions { /** * object with ssl parameters or a string containing name of ssl profile */ - ssl?: string | SslOptions; + ssl?: string | boolean | SslOptions; /** * Return each row as an array, not as an object. diff --git a/website/docs/documentation/ssl.mdx b/website/docs/documentation/ssl.mdx index 59f6b07fa9..61882256b1 100644 --- a/website/docs/documentation/ssl.mdx +++ b/website/docs/documentation/ssl.mdx @@ -10,12 +10,12 @@ See full list of [SslOptions](https://github.com/sidorares/node-mysql2/blob/mast ## SSL Options -To enable SSL without manually providing certificates and assuming they are already trusted by the host machine, you can specify an empty object, for example: +To enable SSL without manually providing certificates and assuming they are already trusted by the host machine, you can specify `ssl: true` or `ssl: {}`, for example: ```ts const connection = await mysql.createConnection({ host: 'localhost', - ssl: {}, + ssl: true }); ``` diff --git a/website/docs/examples/connections/create-connection.mdx b/website/docs/examples/connections/create-connection.mdx index 9f6a3a6f71..5ab4b0abd9 100644 --- a/website/docs/examples/connections/create-connection.mdx +++ b/website/docs/examples/connections/create-connection.mdx @@ -180,7 +180,7 @@ const mysql = require('mysql2'); const connection = mysql.createConnection({ // ... - ssl: {}, + ssl: true, }); connection.addListener('error', (err) => { From b5e3a788e8a1325f421fdc9c0c3048f54f101b8d Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Sat, 8 Feb 2025 14:28:42 +0100 Subject: [PATCH 2/2] fix --- website/docs/documentation/ssl.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/documentation/ssl.mdx b/website/docs/documentation/ssl.mdx index 61882256b1..ee685c8334 100644 --- a/website/docs/documentation/ssl.mdx +++ b/website/docs/documentation/ssl.mdx @@ -15,7 +15,7 @@ To enable SSL without manually providing certificates and assuming they are alre ```ts const connection = await mysql.createConnection({ host: 'localhost', - ssl: true + ssl: true, }); ```