3
b2plane
3y

In typescript (angular) if i have a table USERS in the database and in typescript when i model this table

1) is it a good practice to write all fields exactly like i have in db table column?

2) in typescript am i supposed to write those fields as a class or interface and when should i use class and when to use interface?

While creating a model for the json response and request. Thanks

Comments
  • 2
    db table (db layer)-> domain model (domain layer) -> dto (application layer) -> ts class (presentation layer)

    at least if you go DDD.

    and you should not use an interface for this case.
  • 3
    Well; yes, but actually no.

    You will most likely have some data model classes in your API that may or may not have the same property names as your column names. In most cases your job will be easier when they have the same column names.

    Next, you should not return your data models directly. It will cause you all sorts of problems later, like when you need to return the combined result of multiple tables. Use plain classes, no logic just properties, for this. Again, you might find it easier to map between objects when the property names are equal but it's not a requirement.

    Finally, your frontend should use interfaces to pass data objects around. I cannot remember a single case where I needed a class instead of an interface. Again, mapping property names is up to you.
  • 0
    I use interfaces with property names same as the db collumn names.
Add Comment