volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

New Feature: Add Binary[] Load function when Primary Key is Binary[] #1421

Open xux1217 opened 6 hours ago

xux1217 commented 6 hours ago

What version of SQLBoiler are you using (sqlboiler --version)?

4.16.2

What is your database and version (eg. Postgresql 10)

mysql8

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

As this issue(https://github.com/volatiletech/sqlboiler/issues/1381), when primary key is binary, the load function would report error.

The core reason is we use map as the record structure instead of array when release V4.16.0 (https://github.com/volatiletech/sqlboiler/releases/tag/v4.16.0).

Further information. What did you do, what did you expect?

We have many projects use sqlboiler, and we use the load function too, we also need high performance load function, but we have many tables has binary primary key.

The new version breaks the compatibility, so in the future, we also can't upgrade it.

Resolve method?

I think we need to optimize this point, it not very hard.

Just need to do binary sorting as map key when detect the key is binary array.

  1. cover it to string.
  2. implement a special struct(like type sortbinary []byte), implement sort function, and do the type conversion.
xux1217 commented 6 hours ago

I roughly looked at the template file, is it just necessary to modify this scope(https://github.com/volatiletech/sqlboiler/blob/master/templates/main/07_relationship_to_one_eager.go.tpl#L40) ?

Can we replace the map key type and when converting to an array, the type can be restored.