【问题标题】:How to connect Google Cloud Functions to an external managed DB (Planetscale)?如何将 Google Cloud Functions 连接到外部托管数据库 (Planetscale)?
【发布时间】:2023-01-24 09:09:11
【问题描述】:

我想将我的 GCP Cloud Functions 连接到 Planetscale。
来自what I understand,最好的方法是使用Connection strings。
是否可以?我还没有找到任何有关如何执行此操作的示例。

【问题讨论】:

    标签: mysql google-cloud-platform google-cloud-functions


    【解决方案1】:

    我所要做的就是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();
    

    【讨论】:

      【解决方案2】:

      这是 node.js 吗?我无法让它运行。抱歉是新手

      【讨论】:

      猜你喜欢
      • 2021-10-21
      • 2019-07-11
      • 2020-02-16
      • 1970-01-01
      • 2017-08-18
      • 2021-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多