go-reform / reform

A better ORM for Go, based on non-empty interfaces and code generation.
https://gopkg.in/reform.v1
MIT License
1.44k stars 73 forks source link

InsertMulti() does not update primary key field #327

Open mikestefanello opened 2 years ago

mikestefanello commented 2 years ago

Is your feature request related to a problem? Please describe. When bulk-inserting via Querier.InsertMulti the primary key field on the structs are not updated with the key it was assigned after inserting. This seems on purpose since a comment on the method notes this behavior. This makes it difficult to use, especially if you plan to assign those IDs to foreign-key fields of another set of structs to bulk-insert. I'm open to attempting to add this functionality, but wanted to first see if there's a specific reason why this was excluded or cannot be done.

Describe the solution you'd like The structs have their primary key field populated after bulk-inserting.

Describe alternatives you've considered None yet.

AlekSi commented 2 years ago

wanted to first see if there's a specific reason why this was excluded or cannot be done

That's because I don't know how to implement that functionality with databases and drivers that use LastInsertId() (like MySQL) and don't want to implement only for some databases/drivers (like PostgreSQL), but not others.