1

Here's my config.json from Sequelize:

{
  "development": {
    "username": "root",
    "password": "xxxx",
    "database": "xxxx",
    "host": "127.0.0.1",
    "dialect": "mysql",
    "dialectOptions": {
      "socketPath": "/cloudsql/xxx:xxxx:xxxx"
    }
  },
  ...
}

And I deployed at Firebase Functions with firebase deploy.

But when I do something with database, it shows SequelizeConnectionRefusedError: connect ECONNREFUSED /cloudsql/xxx:xxx:xxx

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
typeocean
  • 55
  • 1
  • 10
  • Can you provide a minimal reproducible code that provides the error? also see: https://stackoverflow.com/help/minimal-reproducible-example – Darwin Jul 13 '22 at 03:30

1 Answers1

0

Here's a working config:

const sequelize = new Sequelize("test-db", "test-user", "mypassword", {
  dialect: "mysql",
  host: "/cloudsql/PROJECT:REGION:INSTANCE",
})

Sequalize wants a host that points to the Unix socket.

No other configuration on the Firebase Functions side is necessary.

enocom
  • 1,496
  • 1
  • 15
  • 22
  • But is it possible to connect Firebase Function with Google Cloud SQL? – typeocean Jul 14 '22 at 02:14
  • Yes. See the docs for Cloud Functions which will be the same for Firebase functions: https://cloud.google.com/sql/docs/mysql/connect-functions. – enocom Jul 14 '22 at 21:43
  • I tried this by remove host, but I still get the same error like Sequelize doesn't want to connect with the socketPath. Is there something I need to setup google cloud SQL so it could connect to entity framework like Sequelize? – typeocean Jul 15 '22 at 06:19
  • 1
    Updated my answer after testing this manually. It's not obvious from the docs, either Cloud SQL or Sequalize. – enocom Jul 15 '22 at 22:44
  • Thanks for the answer, but I got a different error again which is ``SequelizeConnectionError: getaddrinfo EAI_AGAIN /cloudsql/PROJECT:REGION:INSTANCE`` – typeocean Jul 16 '22 at 02:46
  • I already deployed into Firebase Hosting, but I still got that error. – typeocean Jul 16 '22 at 03:30
  • Did you see this? https://stackoverflow.com/a/55132016/927514 – enocom Jul 17 '22 at 04:10
  • Also I assume you're swapping out PROJECT for your project, REGION for your database's region, and INSTANCE for your Cloud SQL instance's name... – enocom Jul 17 '22 at 04:11