OpenAlchemy icon indicating copy to clipboard operation
OpenAlchemy copied to clipboard

api.py create/update list rather than one at a time

Open tduval-unifylogic opened this issue 4 years ago • 0 comments

Greetings! Long time no chat. I am in the process of generating a service using OpenAlchemy and want to create the endpoint fulfillment a little differently. (api.py) and am wondering if you have any thoughts on how I might go about it? I will use your employee example to explain it.

For post: I would like to have a list of employees (one-or-more) rather than having one employee in the body.

For patch: same as post, update a list of employees (one-or-more), additionally, want to not have to hardcode the property names to the keys in the body dictionary. Since the model is a reflection of the API schema, this seems superflous to me? Can't it just be database.db.session.update(employees)?

Lastly, I am curious as to the performance of iterating db.Add (or db.Update) vs a way to persist employees in bulk ( SQLAlchemy bulk_save_objects, update_changed_only) like I can do with pandas (which smokes!). I'm not a big fan of iterating.

I was thinking it might be a comprehension? An array of employees, like the one returned from get are passed in the def post(body) and then it would be something like:

  • database.db.session.bulk_save_objects(map(models.Employee.from_dict(), body))

The question I have is, how to represent in the openapi.yml file (post and schema) that the body contains array?

Thanks in advance!

Tim

tduval-unifylogic avatar Jun 10 '21 20:06 tduval-unifylogic