oracle-databasenestjstypeormnode.js-typeormnestjs-typeorm

TypeOrm putting double quotes when generating the Crud operations


Im using **typeorm **with **nestjs **to work with oracle database.

  1. When I use repository way to get some data from oracle database I'm getting following error: Error: ORA-00942: table or view does not exist

async findAll(): Promise<BRANCHE[]> { let brancheListe: BRANCHE[] = null;

try {
  brancheListe = await this.brancheRepository.find();
} catch (error) {
  console.log(error);
}

return brancheListe;

}

  1. When I look at the generated select statement, it has double quotes, which i believe is the case that oracle can't find the table or view.

query: SELECT "Branche"."ID" AS "Branche_ID", "Branche"."BRANCHE" AS "Branche_BRANCHE", "Branche"."BRACHE_NAVN" AS "Branche_BRACHE_NAVN", "Branche"."TS" AS "Branche_TS" FROM "branche" "Branche" WHERE branche.id < :1 -- PARAMETERS: [10] query failed: SELECT "Branche"."ID" AS "Branche_ID", "Branche"."BRANCHE" AS "Branche_BRANCHE", "Branche"."BRACHE_NAVN" AS "Branche_BRACHE_NAVN", "Branche"."TS" AS "Branche_TS" FROM "branche" "Branche" WHERE branche.id < :1 -- PARAMETERS: [10] error: Error: ORA-00942: table or view does not exist

  1. If I use the repository way with query then its works fine

async findAll(): Promise<BRANCHE[]> { let brancheListe: BRANCHE[] = null;

try {
  brancheListe = await this.brancheRepository.query(
    'SELECT * FROM BRANCHE',
  );
} catch (error) {
  console.log(error);
}
return brancheListe;

}

  1. Do anybody know how i force the TypeOrm not to use doube quotes? is ther any options im missing?

I just wanna know how can stop TypeORM to put double quoutes "" for the generated sql


Solution

  • Allow TypeORM to use the double quotes. Instead, fix your entity so that the double quoted identifiers in the queries have the correct case (upper-case).

    If you have:

    @Entity()
    export class Branche {
        @PrimaryGeneratedColumn()
        ID: number
    
        @Column()
        BRANCHE: string
    
        @Column()
        BRACHE_NAVN: string
    
        @Column()
        TS: string
    }
    

    You can try either:

    @Entity()
    export class BRANCHE {
    ...
    

    or, specify the table name with the Entity decorator:

    @Entity("BRANCHE")
    export class Branche {
    ...
    

    or:

    @Entity({name: "BRANCHE"})
    export class Branche {
    ...