You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've used your library now more in depth for performance analyses (will publish it soon on my blog) and figured out that the pattern for Rows.Null* functions is really confusing.
// NullString returns string as a value and
// NULL indicator. When value is NULL, second parameter is true.
func (r *Rows) NullString() (string, bool) { ... }
When you come from database/sql background ;-) you expect sql.NullString.Valid to be true when the column value is not null. But in your case it returns true when the string is null. Yes it's documented but it still is the total opposite of how database/sql handles.
Would you like to change that behaviour? Would be a breaking change.
Allocs
Every NullInt* function makes a call to NullString which causes an allocation and then again you call strconv.Parse* which creates another allocation. Maybe you can directly transform the byte slice into an int like they do it here: https://github.com/go-sql-driver/mysql/blob/master/utils.go#L499
Hello @SchumacherFM, thanks for such detailed report.
About Null Behaviour, agree that interface is different than in database/sql. At this moment we don't plan to change it. I'd rather update the README to make it clear what the second parameter stands for.
The reason the second parameter is true when your field is null in DB is that we expect to read values in this way:
name, null:=rows.NullString()
ifnull {
// ...
}
However, we might rethink the interface, but in this case, we rather release mysqldriver2-go than changing existing package.
About Allocs. Thanks for the advice. Agree that transforming bytes directly into ints sounds more beneficial. Since you have already researched this part, would you be willing to make a PR?
Null behaviour
I've used your library now more in depth for performance analyses (will publish it soon on my blog) and figured out that the pattern for
Rows.Null*
functions is really confusing.When you come from database/sql background ;-) you expect
sql.NullString.Valid
to be true when the column value is not null. But in your case it returns true when the string is null. Yes it's documented but it still is the total opposite of how database/sql handles.Would you like to change that behaviour? Would be a breaking change.
Allocs
Every
NullInt*
function makes a call to NullString which causes an allocation and then again you call strconv.Parse* which creates another allocation. Maybe you can directly transform the byte slice into an int like they do it here: https://github.com/go-sql-driver/mysql/blob/master/utils.go#L499Also Rows.Time and Rows.NullTime is missing ;-) I would pull in https://github.com/go-sql-driver/mysql/blob/master/utils.go#L277 to implement it ... but I don't if that matches with your license model.
Maybe I can be wrong with the two above points ... so please correct me.
The text was updated successfully, but these errors were encountered: