Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
Crear una estructura independiente de ORM

A veces necesito usar typeorm, sequelize o mongoose. Quiero establecer una estructura sólida que pueda usar en cada proyecto.

Por ejemplo,

Definición del modelo Typeorm:

 @Entity() class UserTO { @PrimaryGeneratedColumn() id: number; @Column() firstName: string; @Column() lastName: string; @Column() email: string; @Column() password: string; }

Secuela Definición del modelo:

 const User = sequelize.define('User', { firstName: { type: DataTypes.STRING, }, lastName: { type: DataTypes.STRING}}, { });

quiero hacer asi:

 class User implements Model { id: number; firstName: string; lastName: string; } interface IRepository<T> { // T is model add(entity: T): void; delete(entity: T): void; update(entity: T): void; getAll(filter?: object): T[]; getOne(filter: object): T; } class TypeOrmBaseRepository<T> implements IRepository<T> { add(entity: T): void { // database operations with typeorm } delete(entity: T): void { // database operations with typeorm } update(entity: T): void { // database operations with typeorm } getAll(filter?: object): T[]{ // database operations with typeorm } getOne(filter: object): T { // database operations with typeorm } } class SequelizeBaseRepository<T> implements IRepository<T> { add(entity: T): void { // database operations with sequelize } delete(entity: T): void { // database operations with sequelize } update(entity: T): void { // database operations with sequelize } getAll(filter?: object): T[]{ // database operations with sequelize } getOne(filter: object): T { // database operations with sequelize } } class UserService { private repository; constructor(repository: IRepository) { this.repository = repository // Whatever ORM's concrete object I give it will work according to what I gave it. } // Service codes }

¿Es posible hacer tal estructura? No he visto tal estructura en muchos proyectos que he revisado.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda