I'm trying to query an Oracle table with Loopback4 and TypeORM but i ORA-00942: table or view does not exist. Morover, after a while, i get another error like this:
'Cannot create a new connection named "default", because connection with such name already exist and it now has an active connection session.'
I'm new to Loopback4 and Nodejs - Typescript, so I called the createConnection method inside the controller.
Maybe i should call It somewhere centralized, but i don't know where and how to centralize this inside my project.
this is my entity
import { Entity, Column, PrimaryColumn, OneToOne } from "typeorm";
@Entity("Pratica")
export class Pratica {
@PrimaryColumn()
protocolloaci: number;
@Column()
codicepratica: string;
}
my controller method
@get('/pratiche/{id}', {
responses: {
'200': {
description: 'Pratica model instance',
content: { 'application/json': { schema: getModelSchemaRef(Pratica) } },
},
},
})
async findById(@param.path.number('id') id: number): Promise<Pratica> {
return new Promise((resolve) => {
createConnection({
type: 'oracle',
host: '10.64.2.226',
port: 1521,
sid: 'npra02s.svidbs003std',
username: 'sua03e',
password: 'iniziale',
entities: [
Pratica
],
logging: true
}).then(async connection => {
let praticaRepository = connection.getRepository(Pratica);
const pratica = await praticaRepository.find({ protocolloaci: id });
resolve(pratica[0]); // return using resolve
}).catch(error => console.log(error));
});
}
thank you