Google Cloud SQL is a service that offers fully-managed SQL DBMS instances for use in cloud and non-cloud applications. It currently supports MySQL and PostgreSQL, and instance capacities ranging up to 64 CPU cores and 400 GB of RAM.
The Cloud SQL model comprises
This model allows multiple databases to be hosted in the same instance, and the same DB to be accessible via multiple users (similar to the model used by engines like MySQL).
Cloud SQL includes dynamic storage expansion (optional), data imports and exports, and advanced features like replication, automatic backups and scheduled maintenance.
From the developer’s point of view, cloud SQL ultimately boils down to SQL.
Sigma generates Cloud SQL code using a FaaS-friendly SQL wrapper library
slappforge-sdk-gcp
.
This allows you to easily run SQL queries and transactions within your serverless function against a desired instance,
while the library takes care of DB connection management transparently.
Cloud SQL is supported on all platforms.
NOTE:
slappforge-sdk-gcp
(and hence Sigma) currently only supports MySQL databases.end()
on the library-provided
connection
object.%
)
since we would be accessing it from cloud functions that do not have fixed hostnames/IP addresses.NOTE:
"JohnDoe"
) to denote literal strings.event.id
) to pass variables directly into the parameter list.@
notation ("@{person.first_name} @{person.last_name}"
) to generate composite strings.NOTE:
slappforge-sdk-gcp
uses an autogenerated file SqlConnMgr.js
to maintain connection configurations.
Do not modify this file, unless you know what you are doing!connection.end()
once your work is complete.Currently Sigma supports the following Cloud SQL operations.
Starts a new SQL transaction against the selected instance and database. This does not need any parameter configurations.
The callback function will receive either:
error
(first parameter) if the transaction could not be initiated, orconnection
(second parameter) on success, bound with an active transactionRuns a SQL query (read or update) against the selected instance and database
NOTE: If you already have a DB connection object (e.g. one that was obtained from a begin transaction call) you should pass it as the third parameter of the auto-generated code block in order to use it during the operation. If not, a new connection will be created for the selected DB instance. This is particularly important when you want to run queries inside a previously initiated transaction.
Field | Required | Supports Variables | Description |
---|---|---|---|
Query | The SQL query to run, can be parameterized if you want to pass external parameter values | ||
Inserts | Comma-separated list of parameters for the query (of any type, not only for inserts); use variables and literals as described under Adding a Cloud SQL Operation |
The callback function will receive (in that order):
error
if the query failedresults
object containing the results of the SQL query execution:
e.g. changedRows
for an UPDATE
, insertId
for an INSERT
, an array of results for a SELECT
, etc.;
refer mysql
client library docs
for more examplesconnection
object that was used in the queryNOTE: If you are inside a transaction, make sure to call connection.commit()
or connection.rollback()
appropriately within the callback.