typeorm ConnectionNotFoundError: Connection "default" was not found.
import { Connection, getConnectionManager,createConnection, QueryRunner } from 'typeorm';
async updateRule(data){
try {
let connection: Connection;
if (!getConnectionManager().has('default')) {
connection = await createConnection({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'xxx',
database: 'xxx',
entities: [RulesEvaluation],
});
} else {
connection = getConnection();
}
const res = await connection
.createQueryBuilder()
.update(RulesEvaluation)
.set({
value: data.value,
})
.where("id = :id", { id: data.id })
.execute();
return {
status: true,
data: res,
}
} catch (e) {
console.log('e',e)
//QueryFailedError:
return {
status: false
}
}
}