https://github.com/edosrecki/google-cloud-sql-nodejs-connector-example
Example of using Google Cloud SQL connector for Node.js.
https://github.com/edosrecki/google-cloud-sql-nodejs-connector-example
cloud-sql cloud-sql-proxy gcloud google-cloud google-cloud-sql javascript knex nodejs proxy sequelize sql typescript
Last synced: 3 months ago
JSON representation
Example of using Google Cloud SQL connector for Node.js.
- Host: GitHub
- URL: https://github.com/edosrecki/google-cloud-sql-nodejs-connector-example
- Owner: edosrecki
- Created: 2023-09-01T12:46:30.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-09T17:13:11.000Z (almost 2 years ago)
- Last Synced: 2025-04-15T09:37:20.358Z (6 months ago)
- Topics: cloud-sql, cloud-sql-proxy, gcloud, google-cloud, google-cloud-sql, javascript, knex, nodejs, proxy, sequelize, sql, typescript
- Language: TypeScript
- Homepage:
- Size: 339 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Google Cloud SQL Node.js Connector Example
Example usage of [Google Cloud SQL Node.js Connector][cloud-sql-connector-node]. This is an alternative approach for connecting to Google Cloud SQL instance without needing Google Cloud SQL Auth Proxy.
Examples include:
* Databases: MySQL, PostgreSQL, and SQL Server
* Libraries: [knex], [sequelize], [typeorm], [prisma][cloud-sql-connector-node]: https://github.com/GoogleCloudPlatform/cloud-sql-nodejs-connector
[knex]: https://knexjs.org/
[sequelize]: https://sequelize.org/
[typeorm]: https://typeorm.io/
[prisma]: https://www.prisma.io/## Google Cloud SQL Setup
### Terraform
See [terraform/README.adoc](terraform/README.adoc) for instructions.
### Manual
1. Create Cloud SQL instance(s).
1. (Optional) Configure private IP connectivity.
1. (Optional) Enable flag for IAM authentication.
3. (Optional) Create a service account for IAM authentication to the SQL instance.
1. Assign `Cloud SQL Client` and `Cloud SQL Instance User` roles.
2. Download JSON key file, or use Application Default Credentials, or service account impersonation.## Run
```sh
## 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 Servervim .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 mssqlnpm run knex
# { connected: 'True' }npm run sequelize
# Executing (default): SELECT 1+1 AS resultnpm run typeorm
# [ { connected: 'True' } ]npm run prisma
# [ { connected: 'True' } ]
```