Search code examples
javascripttypeorm

How to dynamically get column names from TypeORM?


I have tried

let modelClass = (await import('@models/' + modelName + '.ts'))[modelName];
let keys = Object.keys(modelClass);//no column names included, only custom helper vars i.e. NoteColumnVarcharLength
let keys = Object.keys(new modelClass());//nothing at all in this model

Is there a helper function in the library to automatically get them all?


Solution

  • As proposed in the issue on repository of that library (link) can be solved by using

    connection.getMetadata("User").columns