@canecomext/backend-generator
v1.1.0
Published
Generates sophistiocated CRUD backend by a datamodel schema destriptor.
Downloads
40
Readme
Backend generator
Instructions
For implementing code around the generator please see the example project in ./example
To generate code run node ./index.js Eg: node ./index.js ./example/example.json ./example/generated
Upsert feature
Data upsert is not supported by the generator yet. However, upsert feature of Sequelize is ready to be used in custom handler functions.
Further considerations:
- Hooks are designed to support create/update entity cases
- For pre hooks the endpoint itself would have to determine if the upsert will execute an update or an insert in order to decide whiche pre hook (create or update) to call. This would mean additional overhead plus a potential race condition scenario if not implemented properly.
- In case of post hooks there are no such challenges since sequelize is returning if the actual command was an UPDATE or an INSERT
Suggestion:
- One possible solution could be to cheat a little bit. We could start a transaction -> execute the upsert -> call the pre hooks -> roll back the transaction in case the hooks failed. But this approach would not cover the case where the pre hooks modify the request. In that case we would have to somehow detect that a change happened and execute the upsert a second time with the modified request body after the pre hooks.