Kononnable/typeorm-model-generator

Use custom abstract class

Opened this issue · 3 comments

Hi, thanks for the great work!

I am wondering if it is possible to pass my own abstract class?

I am trying to implement something like ActiveModel's conventional ApplicationRecord. I.e. a base abstract class inherited by all entities.

I'd imagine it will be something similar to the existing activeRecord flag, but instead of boolean, it will let me define a path to my own abstract class.

E.g.

Engine.createModelFromDatabase(
  Engine.createDriver(ormconfig.type),
  {
    ...
  },
  {
    abstractClassPath: './src/custom-base-entity.ts',
  }
)
// at ./src/custom-base-entity.ts

import { BaseEntity } from "typeorm"

export default abstract class CustomBaseEntity extends BaseEntity {
  ...
}

No, such functionality isn't implemented. The easiest way to achieve what you want would be to replace BaseEntity in your entities through your IDE(or make simple pipeline around typeorm-model-generator).
As for implementing such functionality inside this library - it wouldn't be that easy. You can use named export, or named export etc.

@Kononnable Thanks for the answer.
Is it possible to implement this feature?
I had a look at the source code, cannot quite understand how the .mst files are used.
Are they mustache templates? Can you please share a link to its doc?

I can mark this issue as an enhancement but I don't think it will be implemented any time soon.

.mst files are used by handlebars template engine. https://handlebarsjs.com/