HergBot / musqrat

A lightweight, strongly typed wrapper for using MySQL in Node.JS
0 stars 0 forks source link

Insert/update does not return Schema[] #18

Open xHergz opened 2 years ago

xHergz commented 2 years ago

Actual: Insert returns an object of data like so: {"fieldCount":0,"affectedRows":1,"insertId":6,"info":"","serverStatus":2,"warningStatus":0} Update returns {"fieldCount":0,"affectedRows":1,"insertId":0,"info":"Rows matched: 1 Changed: 0 Warnings: 0","serverStatus":2,"warningStatus":0,"changedRows":0}

Expected: Array of objects inserted but this is not possible. Fix the typing to allow insert/update to return the correct info.

xHergz commented 1 year ago

After some research it appears that MySQL just doesn't have good support for returning the inserted/updated values. The closest thing it can do is return the meta info for the statement which contains insertId but that is only the last insert id and would not work well for bulk inserts/updates.

The solution seems to be to generated my own ids (UUID) and not worry about auto increment integer ids. Some benefits of this are they are non sequential and allow a distributed system (auto increment doesn't work well/at all distributed)

xHergz commented 1 year ago

Updating the issue to make sure we return the right meta data.