sqlboiler icon indicating copy to clipboard operation
sqlboiler copied to clipboard

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

Open xux1217 opened this issue 1 year ago • 4 comments

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 avatar Oct 21 '24 14:10 xux1217

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.

xux1217 avatar Oct 21 '24 15:10 xux1217

I'll be happy to review a PR fixing this.

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

Why will the new version break compatibility?
As far as the function signature does not change, the implementation of the Load() function should be able to change.

Or am I missing something?

stephenafamo avatar Oct 23 '24 09:10 stephenafamo

I'll be happy to review a PR fixing this.

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

Why will the new version break compatibility? As far as the function signature does not change, the implementation of the Load() function should be able to change.

Or am I missing something?

If we fix the crash of the load method for binary primary keys, there will be no compatibility issues.

xux1217 avatar Oct 24 '24 03:10 xux1217

https://github.com/volatiletech/sqlboiler/pull/1422

A PR has been submitted. Please help me check whether the modification is appropriate.

xux1217 avatar Oct 24 '24 05:10 xux1217