S
S
slip312018-12-15 11:58:42
Node.js
slip31, 2018-12-15 11:58:42

How to change tables dynamically in the database (model)?

Hello.
It is necessary to add several directories located in different postgres tables in the application admin panel.
Table properties are of the same type
"Id", "name_ru", "description".
Models Table1, Table2, etc. are created for each of the tables.
Do I need to make a separate CRUD controller with the same functionality for each of the models, or can I make one CrudController { constructor (model:string) and substitute the model name into the methods there?
What is the general practice?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2018-12-15
@inoise

Need. That's not for long

V
Vitaly, 2018-12-15
@vshvydky

class CRUD {
    repository = null;
    constructor(selectedRepository){
        this.repository = selectedRepository;
    }
     someCRUDmethod(){
         return this.repository.getSome();
     }
}

class Current extends CRUD{
    constructor(repo){
        super(repo);
    }
}

export default new Current(someRepo);

shit like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question