如何将 Google Cloud Functions 连接到外部托管数据库 (Planetscale)?
How to connect Google Cloud Functions to an external managed DB (Planetscale)?
我想将我的 GCP Cloud Functions 连接到 Planetscale。
来自 what I understand, the best way to do this would be utilizing Connection strings.
可能吗?我还没有找到任何有关如何执行此操作的示例。
我所要做的就是 npm install mysql2
,然后使用连接字符串 运行 查询:
const mysql = require('mysql2');
const DATABASE_URL = 'mysql://.....';
const connection = mysql.createConnection(DATABASE_URL);
console.log('Connected to PlanetScale!');
connection.query(`SELECT * from users`, function (err, results, fields) {
console.log(results);
})
connection.end();
我想将我的 GCP Cloud Functions 连接到 Planetscale。
来自 what I understand, the best way to do this would be utilizing Connection strings.
可能吗?我还没有找到任何有关如何执行此操作的示例。
我所要做的就是 npm install mysql2
,然后使用连接字符串 运行 查询:
const mysql = require('mysql2');
const DATABASE_URL = 'mysql://.....';
const connection = mysql.createConnection(DATABASE_URL);
console.log('Connected to PlanetScale!');
connection.query(`SELECT * from users`, function (err, results, fields) {
console.log(results);
})
connection.end();