typeorm-model-generator icon indicating copy to clipboard operation
typeorm-model-generator copied to clipboard

Use custom abstract class

Open ivawzh opened this issue 4 years ago • 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 {
  ...
}

ivawzh avatar Jul 19 '20 14:07 ivawzh

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 avatar Aug 01 '20 16:08 Kononnable

@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?

ivawzh avatar Aug 01 '20 17:08 ivawzh

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/

Kononnable avatar Aug 01 '20 20:08 Kononnable