egg icon indicating copy to clipboard operation
egg copied to clipboard

[Feature Request] get all new ids when batch insert

Open jilingyun opened this issue 4 years ago • 0 comments

Background

I use egg-mysql. insert into table (column1, column2) values(value1, value2), (value3, value4), (value5, value6);

I want to get insertId of all new inserted columns from the result. But I can't only get the id of the first row.

Proposal

Can I get ids of every new row? Like this: const result = this.app.mysql.query('insert into photo (user_id, name) values(?, ?), (?, ?), (?, ?)', ['xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx']); const [id1, id2, id3] = result.insertIds;

Or provide an efficient way to insert in batches.

jilingyun avatar Apr 14 '21 00:04 jilingyun