typeorm: Cannot Create Connection without TypeScript Freaking Out
Hi all,
I’m creating a web app where I combine the (awesome, may I add) routing-controllers with TypeORM. While attempting to create a connection, I receive a wonderful error message for SublimeLinter’s TypeScript linter:
Argument of type '{ driver:{ type: "mysql"; host: string; port: number; username: string; password: string; database: string; } }' is not assignable to parameter of type 'ConnectionOptions'.
Type '{ driver: { type: "mysql"; host: string; port: number; username: string; password: string; database: string; } }' is not assignable to type 'MongoConnectionOptions'.
Property 'type' is missing in type '{ driver: { type: "mysql"; host: string; port: number; username: string; password: string; database: string; } }'.
I cannot seem to figure out what could be causing this. Would someone be able to help me, or just point me in the right direction? Thanks! (My code is below. It is in a @Get class decorator.)
createConnection({
driver: {
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "root",
database: "openhealth"
},
entities: [PatientEntity],
autoSchemaSync: true
}).then(c => {
return c.find();
}).catch(error => {
return error;
});
P.S. If there is a way to use a single connection multiple times, that would be great to know.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (8 by maintainers)
I mentioned few times that its pointless to store “database type” in env variables. Don’t do that.
are you using latest alpha versions? If yes then try to:
Then this ORM is not a database abstraction layer… You can’t change the database without change the code. Usually, the docker containers using the env variables for the configurations (db connection for example)… So then if it does not support the env variable then we must rebuild the docker images… It is really painful and useless.
Ok thank you ! I thought I tried it before, but this is working now 😃