Let say I have a simple database as below:
Table 1. Car_registration_id (PK) | Owner | Registration_date
Table 2. Car_serial_number (PK) | Car_model | Car_registration_id (FK)
A user makes queries to retrieve a arbitrary views as below (it can be any other different views too).
# This view has no identifying column
View 1. Car_model | Owner
# This view has at least 1 identifying column
View 2. Car_registration_id | Car_serial_number | Owner | Car_model
The constraints are:
The front end is not aware of database schemas. Only send request via a provided API.
All processing is left to the back end.
The question is, what is a strategy/pattern to design queries along with API endpoints in which a user can simply go to a view table on the front end, modify any number of cells (UPDATE or REMOVE only), then reflect the changes on database itself? The modification can be applied to different tables, columns, rows at once. In my use case, the database can have more than 10 tables so number of columns is not small.
I'm currently thinking of 2 approaches, but they don't seem to work:
Create endpoints for every possible combinations, for request with or without identifying columns information. This will work, but at the cost of exponential amount of code to maintain, so not reasonable.
Deliver identifying columns to the client no matter it appears in the view or not (just store in memory). Then use all information from client's request to construct queries respectively. However, as a user can modify an arbitrary amount of column, this leads to a complex condition/combination to build a query so it's also an issue. Also, how to separate the endpoints logically in this use case?
I'm using TypeORM, but using raw SQL is fine too. Any help is appreciated!