Skip to content

An example of a Google Cloud Function that uses Prisma to connect to a Cloud SQL instance.

Notifications You must be signed in to change notification settings

wlemahieu/prisma-google-cloud-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Database Connected GCF

Prisma + Google Cloud Function

Connect your GCF to Prisma and make Cloud SQL interactions simpler & cleaner!

Cloud Account Prerequisites:

General Knowledge Prerequisites:

Local Tool Recommendations:

  • VSCode
  • NPX (npm install -g npx)
  • NVM (or a similar node manager)

To test a GCF locally:

  1. nvm use 16 - Switch to Node 16 (nvm install 16.5.1 if not installed)
  2. npm install - Install all node_modules for the GCF
  3. **DATABASE_URL=mysql://<user>:<pass>@localhost/<database> npx prisma migrate dev --name init - Run migrations to create tables inside the database.
  4. DATABASE_URL=mysql://<user>:<pass>@localhost/<database> npx @google-cloud/functions-framework --target=run - Serve the example GCF locally
  5. http://localhost:8080/ - Visit the locally served GCF
*A note on easily moving ready components from local to the cloud:

After cloning this repository, you can upload a zip of the example GCF directory directly to a created Cloud Function. Alternatively, you can manually create & copy GCF files and their contents into your created Cloud Function.

*A note on Prisma schema datasource and reconciling localhost issues.

The url property for the datasource object is typically set to env("DATABASE_URL"). This requires your Cloud Function to have access to a stored secret named DATABASE_URL. This variable is formatted as such for MySQL: mysql://<user>:<pass>@localhost/<database>

*TODO: Determine a cleaner way to pass DATABASE_URL into functions-framework for local testing.

About

An example of a Google Cloud Function that uses Prisma to connect to a Cloud SQL instance.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published