Skip to content

proposal: database/sql: add NullTime support #30305

Closed
@isakbm

Description

@isakbm

Would it be an idea to extend the Nullable types to include NullTime as well?

Something like

type NullTime struct {
    Time  time.Time
    Valid bool
}

// Scan implements the Scanner interface.
func (nt *NullTime) Scan(value interface{}) error {
    if value == nil {
        nt.Time, nt.Valid = time.Time{}, false
        return nil
    }
    nt.Valid = true
    return convertAssign(&nt.Time, value)
}

// Value implements the Valuer interface.
func (nt NullTime) Valuer() (driver.Value, error) {
    if !nt.Valid {
        return nil, nil
    }
    return nt.Time, nil
}

Just copy paste into ...go/src/database/sql/sql.go, should work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions