When the metadata of a Cloud SQL instance is fetched via the connectSettings API, the connector caches all IP addresses and types. Thus it has the information required to connect via either Public or Private IP.
The Node Connector currently incorrectly errors when a user switches IP types between consecutive calls... this PR removes the incorrect erroring and allows for the following usage:
import mysql from 'mysql2/promise';
import { Connector } from '@google-cloud/cloud-sql-connector';
const connector = new Connector();
// establish connection via Public IP
var clientOpts = await connector.getOptions({
instanceConnectionName: 'my-project:us-central1:my-instance',
ipType: 'PUBLIC',
});
const conn = await mysql.createConnection({
...clientOpts,
user: 'root',
password: 'my-password',
database: 'my-database',
});
const [result] = await conn.query(`SELECT NOW();`);
// establish connection via Private IP
var clientOpts = await connector.getOptions({
instanceConnectionName: 'my-project:us-central1:my-instance',
ipType: 'PRIVATE',
});
const conn2 = await mysql.createConnection({
...clientOpts,
user: 'root',
password: 'my-password',
database: 'my-database',
});
const [result2] = await conn.query(`SELECT NOW();`);
connector.close()
When the metadata of a Cloud SQL instance is fetched via the
connectSettings
API, the connector caches all IP addresses and types. Thus it has the information required to connect via either Public or Private IP.The Node Connector currently incorrectly errors when a user switches IP types between consecutive calls... this PR removes the incorrect erroring and allows for the following usage:
Fixes #305