Skip to content

Rows.Null* misleading return bool value / reducing allocs #6

@SchumacherFM

Description

@SchumacherFM

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.

// 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

Also 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions