首页 > 解决方案 > Firebase Functions / Cloud SQL (mysql) / Knex 累积连接

问题描述

我们设置了 firebase 函数来连接到云 sql (mysql) 实例,除了与实例的连接没有池化之外,一切都按预期工作。我们发送到网站的连接越多,连接就会迅速攀升,直到达到 100 的限制。

lib/db.ts

import * as functions from 'firebase-functions';
import * as knex from 'knex';

const { env } = functions.config();

export default knex({
  client: 'mysql',
  connection: {
    ...env.mysql,
    timezone: 'UTC',
    dateStrings: true,
  },
  pool: { min: 1, max: 1 },
});

我们也在 main 中导入这个文件index.ts

import 'lib/db';

任何帮助,将不胜感激。

标签: google-cloud-platformgoogle-cloud-functionsgoogle-cloud-sqlknex.js

解决方案


推荐阅读