Example usage of Google Cloud SQL Node.js Connector. This is an alternative approach for connecting to Google Cloud SQL instance without needing Google Cloud SQL Auth Proxy.
Examples include:
See terraform/README.adoc for instructions.
- Create Cloud SQL instance(s).
- (Optional) Configure private IP connectivity.
- (Optional) Enable flag for IAM authentication.
- (Optional) Create a service account for IAM authentication to the SQL instance.
- Assign
Cloud SQL Client
andCloud SQL Instance User
roles. - Download JSON key file, or use Application Default Credentials, or service account impersonation.
- Assign
## Install dependencies
## ~~~~~~~~~~~~~~~~~~~~
nvm install
npm install
## Configure environment for a DB that you want to test
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# If you used manual setup
cp .env.postgres.example .env # PostgreSQL
cp .env.mysql.example .env # MySQL
cp .env.sqlserver.example .env # SQL Server
vim .env
# If you used Terraform
cd terraform
terraform output -raw postgres_env > ../.env # PostgreSQL
terraform output -raw mysql_env > ../.env # MySQL
terraform output -raw sqlserver_env > ../.env # SQL Server
cd ..
## Run examples for each library
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## NOTE:
## If you are using IAM authentication, make sure to authenticate
## as that service account, either by using JSON key, Application
## Default Credentials, or service account impersonation.
npm run pg
npm run mysql2
npm run mssql
npm run knex
# { connected: 'True' }
npm run sequelize
# Executing (default): SELECT 1+1 AS result
npm run typeorm
# [ { connected: 'True' } ]
npm run prisma
# [ { connected: 'True' } ]