Insert: sort column names #10

Closed
opened 2018-04-25 15:52:26 +00:00 by lunny · 1 comment
Owner

Author: @fasterthanlime

These insert statements are generated with go-xorm/builder:

[37.61µs] INSERT INTO honors (title,id) Values (?,?) [Best Picture 0]
[37.67µs] INSERT INTO honors (id,title) Values (?,?) [1 Best Supporting Actor]
[11.215µs] INSERT INTO honors (id,title) Values (?,?) [2 Best Muffins]
[8.328µs] INSERT INTO honors (id,title) Values (?,?) [3 Second Best Muffins]

As you can see, sometimes it generates (title, id), and sometimes it generates (id, title). This is problematic in my usecase, all statements are prepared (and cached by their SQL string).

The reason this happens is because builder.Insert takes a builder.Eq, which is a golang map, and map iteration order in golang is random (by design).

A possible solution would be to sort the keys, so we get consistent ordering (at a slight performance cost).

Would you be open to this change? I'll happily open a PR once I get your 👍 !

Author: @fasterthanlime These insert statements are generated with go-xorm/builder: ``` [37.61µs] INSERT INTO honors (title,id) Values (?,?) [Best Picture 0] [37.67µs] INSERT INTO honors (id,title) Values (?,?) [1 Best Supporting Actor] [11.215µs] INSERT INTO honors (id,title) Values (?,?) [2 Best Muffins] [8.328µs] INSERT INTO honors (id,title) Values (?,?) [3 Second Best Muffins] ``` As you can see, sometimes it generates `(title, id)`, and sometimes it generates `(id, title)`. This is problematic in my usecase, all statements are prepared (and cached by their SQL string). The reason this happens is because `builder.Insert` takes a `builder.Eq`, which is a golang map, and map iteration order in golang is random (by design). A possible solution would be to sort the keys, so we get consistent ordering (at a slight performance cost). Would you be open to this change? I'll happily open a PR once I get your :+1: !
Author
Owner

Author: @lunny

@fasterthanlime please send a PR! Thanks!

Author: @lunny @fasterthanlime please send a PR! Thanks!
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/builder#10
No description provided.