Typical ormconfig.json file for Google Cloud SQL?
Asked Answered
S

2

5

I have been trying for hours. What should be the ormconfig.json file for Google Cloud SQL working with TypeORM? I managed to get it working with the IP of the DB locally (with mysql workbench and Google cloud proxy and whitelisting my ip) but I don't know what the connection details should be for app engine.

{
  "name": "default",
  "type": "mysql",
  "host": "/cloudsql/[project:region:instance]",
  "port": "3306",
  "username": "root",
  "password": "xxxx",
  "database": "yyy",
  "synchronize": true,
  "logging": false,
  "entities": [
    "modules/**/*.entity.js"
  ]
}

or

{
  "name": "default",
  "type": "mysql",
  "extra": {
    "socketPath": "/cloudsql/[project:region:instance]"
  },
  "username": "root",
  "password": "xxxx",
  "database": "yyy",
  "synchronize": true,
  "logging": false,
  "entities": [
    "modules/**/*.entity.js"
  ]
}

or anything else?

Thanks a lot!

Server answered 19/12, 2017 at 21:42 Comment(0)
S
14

For those interested, here is the solution:

{
  "name": "default",
  "type": "mysql",
  "extra": {
    "socketPath": "/cloudsql/[project:region:instance]"
  },
  "username": "root",
  "password": "xxxx",
  "database": "yyy",
  "synchronize": true,
  "logging": false,
  "entities": [
    "dist/**/*.entity.js"
  ]
}

Note that I also changed the entities path

Server answered 19/12, 2017 at 22:38 Comment(2)
How is entities path supposed to be correct? This way of connecting creates connection but doesn't create repositories. I tried lib/entity/**/*.js but without success.Deuced
It depends on the outDir option of your tsconfig.json. The point is that once you transpile your, the production code of the entities is no longer at the same place.Server
P
1

It didn't worked for me until I added the "cloud_sql" path also the the "host":

{
     "name": "default",
     "host": "/cloudsql/[project:region:instance]",
     "type": "mysql",
     "extra": {
       "socketPath": "/cloudsql/[project:region:instance]"
     },
     "username": "root",
     "password": "xxxx",
     "database": "yyy",
     "synchronize": true,
     "logging": false,
     "entities": [
         "dist/**/*.entity.js"
     ]
}
Phillis answered 30/10, 2020 at 11:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.