Documentation
¶
Overview ¶
Package types provides nullable wrappers and not-null helpers for values that must travel through both database/sql and JSON.
Every wrapper implements sql.Scanner and driver.Valuer so the types can be used directly with sql.Row.Scan and db.Exec, and every wrapper implements json.Marshaler / json.Unmarshaler with a canonical shape: an invalid value marshals to null, a valid one to its documented string form (for example "2006-01-02" for Date/NullDate). Each type exposes an IsEmpty method (see Emptiable) and a ToString method (see ToStringAble) that returns "" when the value is NULL.
The package is organised around pairs that share a single serializer/parser:
- Date / NullDate — calendar date ("2006-01-02" or "02.01.2006" on input; always "2006-01-02" on output).
- LocalDateTime / NullLocalDateTime — wall-clock date-time without a timezone ("2006-01-02T15:04:05[.fff…]").
- OffsetDateTime / NullOffsetDateTime — date-time with an offset ("2006-01-02T15:04:05[.fff…]Z" or "±HH:MM").
- LocalTime / NullLocalTime — wall-clock time of day without a timezone ("15:04:05[.fff…]").
- OffsetTime / NullOffsetTime — time of day with an offset ("15:04:05[.fff…]Z" or "±HH:MM").
Additional nullable wrappers cover primitive types: NullString, NullBool, NullInt16/32/64, NullFloat, NullDecimal and NullUuid.
Nullable types accept the JSON token null on UnmarshalJSON and SQL NULL on Scan; their not-null counterparts reject both. Scan delegates to the corresponding sql.Null* wrapper so that typed nils from database drivers are honoured.
Index ¶
- Constants
- func AssembleDateTime(dateValue *time.Time, timeValue *time.Time, location *time.Location) *time.Time
- func AssembleDateTimeTZ(dateValue *time.Time, timeValue *time.Time, timeZone string) (*time.Time, error)
- func AssembleNullDateTimeTZ(dateValue *NullDate, defaultDate *time.Time, timeValue *NullOffsetTime, ...) (*time.Time, error)
- func DateTimeToString(t time.Time) string
- func DateToString(date time.Time) string
- func GetNullString(s sql.NullString) string
- func IsEmpty(t interface{}) bool
- func MaxDateTime(dt1, dt2 time.Time) time.Time
- func MinDateTime(dt1, dt2 time.Time) time.Time
- func NSFromString(s string) sql.NullString
- func ParseDateFromString(strValue string) (*time.Time, error)
- func ParseDateTimeFromString(strValue string) (*time.Time, error)
- func ParseTimeFromString(strValue string) (*time.Time, error)
- func ParseTimezoneExtended(strValue string) (*time.Location, string, error)
- func ToString(val interface{}) string
- type Date
- type Emptiable
- type LocalDateTime
- func (thisVal LocalDateTime) MarshalJSON() ([]byte, error)
- func (thisVal *LocalDateTime) Scan(value interface{}) error
- func (thisVal LocalDateTime) ToString() string
- func (thisVal LocalDateTime) ToTime(loc *time.Location) time.Time
- func (thisVal *LocalDateTime) UnmarshalJSON(data []byte) error
- func (thisVal LocalDateTime) Value() (driver.Value, error)
- type LocalTime
- func (thisVal LocalTime) MarshalJSON() ([]byte, error)
- func (thisVal *LocalTime) Scan(value interface{}) error
- func (thisVal LocalTime) ToString() string
- func (thisVal LocalTime) ToTime() time.Time
- func (thisVal *LocalTime) UnmarshalJSON(data []byte) error
- func (thisVal LocalTime) Value() (driver.Value, error)
- type NullBool
- func (thisVal *NullBool) IsEmpty() bool
- func (thisVal NullBool) IsZero() bool
- func (thisVal NullBool) MarshalJSON() ([]byte, error)
- func (thisVal *NullBool) Scan(value interface{}) error
- func (thisVal *NullBool) ToString() string
- func (thisVal *NullBool) UnmarshalJSON(data []byte) error
- func (thisVal NullBool) Value() (driver.Value, error)
- type NullDate
- func (thisVal *NullDate) IsEmpty() bool
- func (thisVal NullDate) IsZero() bool
- func (thisVal NullDate) MarshalJSON() ([]byte, error)
- func (thisVal *NullDate) Scan(value interface{}) error
- func (thisVal *NullDate) ToString() string
- func (thisVal *NullDate) UnmarshalJSON(data []byte) error
- func (thisVal NullDate) Value() (driver.Value, error)
- type NullDecimal
- func (thisVal *NullDecimal) IsEmpty() bool
- func (thisVal NullDecimal) IsZero() bool
- func (thisVal NullDecimal) MarshalJSON() ([]byte, error)
- func (thisVal *NullDecimal) Scan(value interface{}) error
- func (thisVal *NullDecimal) ToString() string
- func (thisVal *NullDecimal) UnmarshalJSON(data []byte) error
- func (thisVal NullDecimal) Value() (driver.Value, error)
- type NullFloat
- func (thisVal *NullFloat) IsEmpty() bool
- func (thisVal NullFloat) IsZero() bool
- func (thisVal NullFloat) MarshalJSON() ([]byte, error)
- func (thisVal *NullFloat) Scan(value interface{}) error
- func (thisVal *NullFloat) ToString() string
- func (thisVal *NullFloat) UnmarshalJSON(data []byte) error
- func (thisVal NullFloat) Value() (driver.Value, error)
- type NullInt16
- func (thisVal *NullInt16) IsEmpty() bool
- func (thisVal NullInt16) IsZero() bool
- func (thisVal NullInt16) MarshalJSON() ([]byte, error)
- func (thisVal *NullInt16) Scan(value interface{}) error
- func (thisVal *NullInt16) ToString() string
- func (thisVal *NullInt16) UnmarshalJSON(data []byte) error
- func (thisVal NullInt16) Value() (driver.Value, error)
- type NullInt32
- func (thisVal *NullInt32) IsEmpty() bool
- func (thisVal NullInt32) IsZero() bool
- func (thisVal NullInt32) MarshalJSON() ([]byte, error)
- func (thisVal *NullInt32) Scan(value interface{}) error
- func (thisVal *NullInt32) ToString() string
- func (thisVal *NullInt32) UnmarshalJSON(data []byte) error
- func (thisVal NullInt32) Value() (driver.Value, error)
- type NullInt64
- func (thisVal *NullInt64) IsEmpty() bool
- func (thisVal NullInt64) IsZero() bool
- func (thisVal NullInt64) MarshalJSON() ([]byte, error)
- func (thisVal *NullInt64) Scan(value interface{}) error
- func (thisVal *NullInt64) ToString() string
- func (thisVal *NullInt64) UnmarshalJSON(data []byte) error
- func (thisVal NullInt64) Value() (driver.Value, error)
- type NullLocalDateTime
- func (thisVal *NullLocalDateTime) IsEmpty() bool
- func (thisVal NullLocalDateTime) IsZero() bool
- func (thisVal NullLocalDateTime) MarshalJSON() ([]byte, error)
- func (thisVal *NullLocalDateTime) Scan(value interface{}) error
- func (thisVal *NullLocalDateTime) ToString() string
- func (thisVal *NullLocalDateTime) UnmarshalJSON(data []byte) error
- func (thisVal NullLocalDateTime) Value() (driver.Value, error)
- type NullLocalTime
- func (thisVal *NullLocalTime) IsEmpty() bool
- func (thisVal NullLocalTime) IsZero() bool
- func (thisVal NullLocalTime) MarshalJSON() ([]byte, error)
- func (thisVal *NullLocalTime) Scan(value interface{}) error
- func (thisVal *NullLocalTime) ToString() string
- func (thisVal *NullLocalTime) UnmarshalJSON(data []byte) error
- func (thisVal NullLocalTime) Value() (driver.Value, error)
- type NullOffsetDateTime
- func (thisVal NullOffsetDateTime) After(dt time.Time) bool
- func (thisVal NullOffsetDateTime) Before(dt time.Time) bool
- func (thisVal *NullOffsetDateTime) IsEmpty() bool
- func (thisVal NullOffsetDateTime) IsZero() bool
- func (thisVal NullOffsetDateTime) MarshalJSON() ([]byte, error)
- func (thisVal *NullOffsetDateTime) Scan(value interface{}) error
- func (thisVal NullOffsetDateTime) ToString() string
- func (thisVal NullOffsetDateTime) Unix() int64
- func (thisVal *NullOffsetDateTime) UnmarshalJSON(data []byte) error
- func (thisVal NullOffsetDateTime) Value() (driver.Value, error)
- type NullOffsetTime
- func (thisVal *NullOffsetTime) IsEmpty() bool
- func (thisVal NullOffsetTime) IsZero() bool
- func (thisVal NullOffsetTime) MarshalJSON() ([]byte, error)
- func (thisVal *NullOffsetTime) Scan(value interface{}) error
- func (thisVal NullOffsetTime) ToString() string
- func (thisVal *NullOffsetTime) UnmarshalJSON(data []byte) error
- func (thisVal NullOffsetTime) Value() (driver.Value, error)
- type NullString
- func (thisVal *NullString) IsEmpty() bool
- func (thisVal NullString) IsZero() bool
- func (thisVal NullString) MarshalJSON() ([]byte, error)
- func (thisVal *NullString) Scan(value interface{}) error
- func (thisVal *NullString) ToString() string
- func (thisVal *NullString) UnmarshalJSON(data []byte) error
- func (thisVal NullString) Value() (driver.Value, error)
- type NullUuid
- func (thisVal *NullUuid) IsEmpty() bool
- func (thisVal NullUuid) IsZero() bool
- func (thisVal NullUuid) MarshalJSON() ([]byte, error)
- func (thisVal *NullUuid) Scan(value interface{}) error
- func (thisVal *NullUuid) ToString() string
- func (thisVal *NullUuid) UnmarshalJSON(data []byte) error
- func (thisVal NullUuid) Value() (driver.Value, error)
- type OffsetDateTime
- func (thisVal OffsetDateTime) After(dt time.Time) bool
- func (thisVal OffsetDateTime) AsTime() time.Time
- func (thisVal OffsetDateTime) Before(dt time.Time) bool
- func (thisVal OffsetDateTime) MarshalJSON() ([]byte, error)
- func (thisVal *OffsetDateTime) Scan(value interface{}) error
- func (thisVal OffsetDateTime) ToString() string
- func (thisVal OffsetDateTime) Unix() int64
- func (thisVal *OffsetDateTime) UnmarshalJSON(data []byte) error
- func (thisVal OffsetDateTime) Value() (driver.Value, error)
- type OffsetTime
- func (thisVal OffsetTime) AsTime() time.Time
- func (thisVal OffsetTime) MarshalJSON() ([]byte, error)
- func (thisVal *OffsetTime) Scan(value interface{}) error
- func (thisVal OffsetTime) String() string
- func (thisVal OffsetTime) ToString() string
- func (thisVal *OffsetTime) UnmarshalJSON(data []byte) error
- func (thisVal OffsetTime) Value() (driver.Value, error)
- type ToStringAble
Constants ¶
const RuOnlyDateMask = "02.01.2006"
RuOnlyDateMask is the dd.MM.yyyy locale date format accepted by parseDate in addition to ISO 8601 (time.DateOnly).
Variables ¶
This section is empty.
Functions ¶
func AssembleDateTime ¶
func AssembleDateTime( dateValue *time.Time, timeValue *time.Time, location *time.Location, ) *time.Time
AssembleDateTime combines the calendar date from dateValue with the wall-clock components from timeValue. If location is non-nil it is used as the resulting time.Location, otherwise timeValue's location is kept.
func AssembleDateTimeTZ ¶
func AssembleDateTimeTZ( dateValue *time.Time, timeValue *time.Time, timeZone string, ) (*time.Time, error)
AssembleDateTimeTZ combines dateValue and timeValue and resolves the resulting location from the textual timeZone using ParseTimezoneExtended (IANA names, "Z", and "+HH:MM" / "+HHMM" offsets are all accepted). On a zone parse error the original dateValue is returned alongside the error.
func AssembleNullDateTimeTZ ¶
func AssembleNullDateTimeTZ( dateValue *NullDate, defaultDate *time.Time, timeValue *NullOffsetTime, defaultTime *time.Time, timeZone string, ) (*time.Time, error)
AssembleNullDateTimeTZ is the NULL-aware variant of AssembleDateTimeTZ. A NULL date or time is replaced by the corresponding default (defaultDate / defaultTime); the returned pointer reflects the assembled instant in the zone decoded from timeZone.
func DateTimeToString ¶
DateTimeToString renders a datetime in the library's canonical TZ-aware format. Kept as a thin wrapper for callers that operate on bare time.Time values.
func DateToString ¶
DateToString renders a calendar date in the library's canonical ISO 8601 form ("2006-01-02").
func GetNullString ¶
func GetNullString(s sql.NullString) string
GetNullString returns the underlying string of an sql.NullString, or "" when the value is NULL. Mirrors NSFromString on the read side.
func IsEmpty ¶
func IsEmpty(t interface{}) bool
IsEmpty reports whether v should be treated as empty/NULL. It accepts nil, primitives, the standard library's sql.Null* family, and any value that implements Emptiable (including pointer-receiver implementations invoked on a value).
func MaxDateTime ¶
MaxDateTime returns the later of dt1 and dt2. Ties return dt2.
func MinDateTime ¶
MinDateTime returns the earlier of dt1 and dt2. Ties return dt2.
func NSFromString ¶
func NSFromString(s string) sql.NullString
NSFromString builds an sql.NullString from a raw string, treating the empty string as NULL. Handy when composing queries against the database/sql package directly.
func ParseDateFromString ¶
ParseDateFromString parses a calendar date from a string using the formats supported by the library (ISO 8601 and dd.MM.yyyy). The returned pointer is never nil on success.
func ParseDateTimeFromString ¶
ParseDateTimeFromString parses a datetime string. The date and time parts must be separated by either 'T' or ' '. The time part may carry an optional timezone designator ("Z", "+HH:MM", "+HHMM").
func ParseTimeFromString ¶
ParseTimeFromString parses a time-of-day with an optional timezone designator ("HH:MM[:SS[.fff…]][Z|±HH:MM|±HHMM]").
func ParseTimezoneExtended ¶
ParseTimezoneExtended attempts to extract a trailing timezone designator from strValue. Supported forms are "+HH:MM" / "-HH:MM" (six chars) and "+HHMM" / "-HHMM" (five chars). When a designator is found it is removed from the returned string and represented as a *time.Location; otherwise time.Local is returned.
Types ¶
type Date ¶
Date is a not-null calendar date (no time component, no timezone).
Date shares its serializer with NullDate: both render as "2006-01-02" and accept the same parser inputs (ISO 8601 and dd.MM.yyyy). Use Date for required JSON or SQL fields where NULL is not permitted; use NullDate for optional ones.
func DateFromString ¶
DateFromString parses a calendar date using the formats supported by the library (ISO 8601 and dd.MM.yyyy).
func NewDate ¶
NewDate wraps t as a Date. The time-of-day component is preserved on the underlying value but is dropped by the serializer (formatDate writes only "YYYY-MM-DD").
func (Date) MarshalJSON ¶
MarshalJSON renders the date as a JSON string in the library's canonical format ("2006-01-02").
func (*Date) Scan ¶
Scan implements the database/sql.Scanner interface. A NULL value is rejected — Date cannot be empty.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON parses a JSON string in any of the formats accepted by DateFromString. JSON null is rejected — Date cannot be empty.
type Emptiable ¶
type Emptiable interface {
IsEmpty() bool
}
Emptiable is the interface implemented by every nullable type in the package. IsEmpty reports whether the value is missing (NULL).
type LocalDateTime ¶
type LocalDateTime struct {
Year int
Month time.Month
Day int
Hour int
Minute int
Second int
Nanosec int
}
LocalDateTime is a not-null wall-clock datetime without a timezone.
Use LocalDateTime for business events anchored to a calendar moment in a human's wall-clock time (e.g. "contract signed on 2026-04-18 at 13:00") where the offset is intentionally absent. For points in time with a known offset, use OffsetDateTime instead.
func LocalDateTimeFromString ¶
func LocalDateTimeFromString(strValue string) (LocalDateTime, error)
LocalDateTimeFromString parses a wall-clock datetime in either ISO 8601 "T" form ("2006-01-02T15:04:05[.fff]") or the equivalent space-separated form. Inputs carrying a timezone designator are rejected.
func LocalDateTimeFromTime ¶
func LocalDateTimeFromTime(t time.Time) LocalDateTime
LocalDateTimeFromTime extracts the wall-clock components of t and discards its location.
func NewLocalDateTime ¶
func NewLocalDateTime(year int, month time.Month, day, hour, minute, second, nanosec int) LocalDateTime
NewLocalDateTime constructs a LocalDateTime from its components.
func (LocalDateTime) MarshalJSON ¶
func (thisVal LocalDateTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in the library's canonical format.
func (*LocalDateTime) Scan ¶
func (thisVal *LocalDateTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. A NULL value is rejected — LocalDateTime cannot be empty.
func (LocalDateTime) ToString ¶
func (thisVal LocalDateTime) ToString() string
ToString renders the value in the library's canonical format ("2006-01-02T15:04:05[.fff]").
func (LocalDateTime) ToTime ¶
func (thisVal LocalDateTime) ToTime(loc *time.Location) time.Time
ToTime materialises the wall-clock components in the given location. Pass time.UTC, time.Local, or a fixed zone according to how the value should be interpreted at the boundary with timezone-aware code. A nil loc is treated as time.UTC.
func (*LocalDateTime) UnmarshalJSON ¶
func (thisVal *LocalDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string in any of the formats accepted by LocalDateTimeFromString. JSON null is rejected — LocalDateTime cannot be empty.
type LocalTime ¶
LocalTime is a not-null wall-clock time-of-day without a timezone.
Use LocalTime for values like "shop opens at 09:00" — a time-of-day with no offset. For points in time with a known offset, use OffsetTime instead.
func LocalTimeFromString ¶
LocalTimeFromString parses a wall-clock time-of-day in ISO 8601 form ("HH:MM[:SS[.fff]]"). Inputs carrying a timezone designator are rejected.
func LocalTimeFromTime ¶
LocalTimeFromTime extracts the time-of-day components of t and discards its date and location.
func NewLocalTime ¶
NewLocalTime constructs a LocalTime from its components.
func (LocalTime) MarshalJSON ¶
MarshalJSON renders the value as a JSON string in the library's canonical format.
func (*LocalTime) Scan ¶
Scan implements the database/sql.Scanner interface. Accepts time.Time, string, or []byte. A NULL value is rejected — LocalTime cannot be empty.
func (LocalTime) ToString ¶
ToString renders the value in the library's canonical format ("15:04:05[.fff]").
func (LocalTime) ToTime ¶
ToTime materialises the time-of-day on the zero date (year 0, January 1) in time.UTC.
func (*LocalTime) UnmarshalJSON ¶
UnmarshalJSON parses a JSON string in any of the formats accepted by LocalTimeFromString. JSON null is rejected — LocalTime cannot be empty.
type NullBool ¶
NullBool is a nullable boolean. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullBool ¶
NewNullBool constructs a valid NullBool wrapping value.
func NewNullBoolEmpty ¶
func NewNullBoolEmpty() NullBool
NewNullBoolEmpty returns an invalid (NULL) NullBool.
func NullBoolFromString ¶
NullBoolFromString parses a bool from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullBool.
func (NullBool) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullBool) MarshalJSON ¶
MarshalJSON renders the value as a JSON boolean, or null when empty. The valid path returns a shared literal slice ("true"/"false") to skip the reflection dispatch and allocation that json.Marshal does for the primitive bool type.
func (*NullBool) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullBool so that the driver's NULL signalling is honoured.
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON parses a JSON boolean or the token null. Any other input is treated as a parse error.
type NullDate ¶
NullDate is a nullable calendar date (year/month/day with no time-of-day or zone component). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullDate ¶
NewNullDate constructs a valid NullDate wrapping value.
func NewNullDateEmpty ¶
func NewNullDateEmpty() NullDate
NewNullDateEmpty returns an invalid (NULL) NullDate.
func NullDateFromString ¶
NullDateFromString parses a date from the string pointer using the library's accepted formats (ISO 8601 "2006-01-02" and the Russian "dd.MM.yyyy"). A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullDate.
func (NullDate) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullDate) MarshalJSON ¶
MarshalJSON renders the date as a JSON string in ISO 8601 form, or null when empty. The valid path writes directly to a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal would perform.
func (*NullDate) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullTime so that the driver's NULL signalling is honoured.
func (*NullDate) UnmarshalJSON ¶
UnmarshalJSON parses a JSON string using the accepted date formats (ISO 8601, dd.MM.yyyy) or the token null.
type NullDecimal ¶
NullDecimal is a nullable arbitrary-precision decimal backed by github.com/shopspring/decimal. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func MulNullDecimals ¶
func MulNullDecimals(val1, val2 NullDecimal) NullDecimal
MulNullDecimals multiplies two NullDecimals. The result is NULL if either operand is NULL.
func NewNullDecimal ¶
func NewNullDecimal(val decimal.Decimal) NullDecimal
NewNullDecimal constructs a valid NullDecimal wrapping val.
func NewNullDecimalEmpty ¶
func NewNullDecimalEmpty() NullDecimal
NewNullDecimalEmpty returns an invalid (NULL) NullDecimal.
func NullDecimalFromString ¶
func NullDecimalFromString(strValue *string) NullDecimal
NullDecimalFromString parses a decimal from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullDecimal.
func (*NullDecimal) IsEmpty ¶
func (thisVal *NullDecimal) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullDecimal) IsZero ¶
func (thisVal NullDecimal) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullDecimal) MarshalJSON ¶
func (thisVal NullDecimal) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON number (the format decimal.Decimal itself emits), or null when empty.
func (*NullDecimal) Scan ¶
func (thisVal *NullDecimal) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. The decimal is received as text from the driver (via sql.NullString) and parsed through NullDecimalFromString so precision is preserved.
func (*NullDecimal) ToString ¶
func (thisVal *NullDecimal) ToString() string
ToString renders the decimal via decimal.Decimal.String (no trailing zeros), or "" when NULL.
func (*NullDecimal) UnmarshalJSON ¶
func (thisVal *NullDecimal) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON number, JSON string, or the token null. Any other input is treated as a parse error.
type NullFloat ¶
NullFloat is a nullable float64. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullFloat ¶
NewNullFloat constructs a valid NullFloat wrapping value.
func NewNullFloatEmpty ¶
func NewNullFloatEmpty() NullFloat
NewNullFloatEmpty returns an invalid (NULL) NullFloat.
func NullFloatFromString ¶
NullFloatFromString parses a float64 from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullFloat.
func (NullFloat) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullFloat) MarshalJSON ¶
MarshalJSON renders the value as a JSON number, or null when empty. The valid path uses strconv.AppendFloat directly to skip the reflection dispatch and intermediate buffer allocation that json.Marshal does for primitive numeric types. The 'g' verb mirrors encoding/json's own format for float64.
func (*NullFloat) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullFloat64 so that the driver's NULL signalling is honoured.
func (*NullFloat) UnmarshalJSON ¶
UnmarshalJSON parses a JSON number or the token null. Any other input is treated as a parse error.
type NullInt16 ¶
NullInt16 is a nullable int16. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullInt16 ¶
NewNullInt16 constructs a valid NullInt16 wrapping value.
func NewNullInt16Empty ¶
func NewNullInt16Empty() NullInt16
NewNullInt16Empty returns an invalid (NULL) NullInt16.
func NullInt16FromNullString ¶
func NullInt16FromNullString(str NullString) NullInt16
NullInt16FromNullString parses an int16 from a NullString. An invalid or empty NullString, or a parse error, produce an invalid NullInt16.
func NullInt16FromString ¶
NullInt16FromString parses an int16 from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullInt16.
func (NullInt16) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullInt16) MarshalJSON ¶
MarshalJSON renders the value as a JSON number, or null when empty. The valid path uses strconv.AppendInt directly to skip the reflection dispatch and intermediate buffer allocation that json.Marshal does for primitive numeric types.
func (*NullInt16) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullInt16 so that the driver's NULL signalling is honoured.
func (*NullInt16) UnmarshalJSON ¶
UnmarshalJSON parses a JSON number or the token null. Any other input is treated as a parse error.
type NullInt32 ¶
NullInt32 is a nullable int32. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullInt32 ¶
NewNullInt32 constructs a valid NullInt32 wrapping value.
func NewNullInt32Empty ¶
func NewNullInt32Empty() NullInt32
NewNullInt32Empty returns an invalid (NULL) NullInt32.
func NullInt32FromNullString ¶
func NullInt32FromNullString(str NullString) NullInt32
NullInt32FromNullString parses an int32 from a NullString. An invalid or empty NullString, or a parse error, produce an invalid NullInt32.
func NullInt32FromString ¶
NullInt32FromString parses an int32 from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullInt32.
func (NullInt32) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullInt32) MarshalJSON ¶
MarshalJSON renders the value as a JSON number, or null when empty. The valid path uses strconv.AppendInt directly to skip the reflection dispatch and intermediate buffer allocation that json.Marshal does for primitive numeric types.
func (*NullInt32) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullInt32 so that the driver's NULL signalling is honoured.
func (*NullInt32) UnmarshalJSON ¶
UnmarshalJSON parses a JSON number or the token null. Any other input is treated as a parse error.
type NullInt64 ¶
NullInt64 is a nullable int64. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullInt64 ¶
NewNullInt64 constructs a valid NullInt64 wrapping value.
func NewNullInt64Empty ¶
func NewNullInt64Empty() NullInt64
NewNullInt64Empty returns an invalid (NULL) NullInt64.
func NullInt64FromNullString ¶
func NullInt64FromNullString(str NullString) NullInt64
NullInt64FromNullString parses an int64 from a NullString. An invalid or empty NullString, or a parse error, produce an invalid NullInt64.
func NullInt64FromString ¶
NullInt64FromString parses an int64 from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullInt64.
func (NullInt64) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullInt64) MarshalJSON ¶
MarshalJSON renders the value as a JSON number, or null when empty. The valid path uses strconv.AppendInt directly to skip the reflection dispatch and intermediate buffer allocation that json.Marshal does for primitive numeric types.
func (*NullInt64) Scan ¶
Scan implements the database/sql.Scanner interface, delegating to sql.NullInt64 so that the driver's NULL signalling is honoured.
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON parses a JSON number or the token null. Any other input is treated as a parse error.
type NullLocalDateTime ¶
type NullLocalDateTime struct {
Val LocalDateTime
Valid bool
}
NullLocalDateTime is the nullable counterpart of LocalDateTime. It shares the same serializer (formatLocalDateTime / parseLocalDateTime). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullLocalDateTime ¶
func NewNullLocalDateTime(value LocalDateTime) NullLocalDateTime
NewNullLocalDateTime constructs a valid NullLocalDateTime wrapping value.
func NewNullLocalDateTimeEmpty ¶
func NewNullLocalDateTimeEmpty() NullLocalDateTime
NewNullLocalDateTimeEmpty returns an invalid (NULL) NullLocalDateTime.
func NullLocalDateTimeFromString ¶
func NullLocalDateTimeFromString(strValue *string) NullLocalDateTime
NullLocalDateTimeFromString parses a local datetime from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullLocalDateTime.
func (*NullLocalDateTime) IsEmpty ¶
func (thisVal *NullLocalDateTime) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullLocalDateTime) IsZero ¶
func (thisVal NullLocalDateTime) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullLocalDateTime) MarshalJSON ¶
func (thisVal NullLocalDateTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in canonical local datetime form, or null when empty. The valid path appends directly into a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal(formatLocalDateTime(...)) would perform.
func (*NullLocalDateTime) Scan ¶
func (thisVal *NullLocalDateTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface, delegating to sql.NullTime so that the driver's NULL signalling is honoured. The returned time's wall-clock components are preserved verbatim.
func (*NullLocalDateTime) ToString ¶
func (thisVal *NullLocalDateTime) ToString() string
ToString renders the value in the library's canonical local datetime form, or "" when NULL.
func (*NullLocalDateTime) UnmarshalJSON ¶
func (thisVal *NullLocalDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string containing a local datetime, or the token null. Any other input is treated as a parse error.
func (NullLocalDateTime) Value ¶
func (thisVal NullLocalDateTime) Value() (driver.Value, error)
Value implements the database/sql/driver.Valuer interface. A NULL value is emitted as (nil, nil); the valid case is materialised as a time.Time in UTC (drivers interpret TIMESTAMP WITHOUT TIME ZONE as the wall-clock components).
type NullLocalTime ¶
NullLocalTime is the nullable counterpart of LocalTime. It shares the same serializer (formatLocalTime / parseLocalTime). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullLocalTime ¶
func NewNullLocalTime(value LocalTime) NullLocalTime
NewNullLocalTime constructs a valid NullLocalTime wrapping value.
func NewNullLocalTimeEmpty ¶
func NewNullLocalTimeEmpty() NullLocalTime
NewNullLocalTimeEmpty returns an invalid (NULL) NullLocalTime.
func NullLocalTimeFromString ¶
func NullLocalTimeFromString(strValue *string) NullLocalTime
NullLocalTimeFromString parses a local time from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullLocalTime.
func (*NullLocalTime) IsEmpty ¶
func (thisVal *NullLocalTime) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullLocalTime) IsZero ¶
func (thisVal NullLocalTime) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullLocalTime) MarshalJSON ¶
func (thisVal NullLocalTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in canonical local time form, or null when empty. The valid path appends directly into a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal(formatLocalTime(...)) would perform.
func (*NullLocalTime) Scan ¶
func (thisVal *NullLocalTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. NULL values produce an invalid NullLocalTime; non-NULL values are delegated to LocalTime.Scan.
func (*NullLocalTime) ToString ¶
func (thisVal *NullLocalTime) ToString() string
ToString renders the value in the library's canonical local time form, or "" when NULL.
func (*NullLocalTime) UnmarshalJSON ¶
func (thisVal *NullLocalTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string containing a local time, or the token null. Any other input is treated as a parse error.
type NullOffsetDateTime ¶
NullOffsetDateTime is the nullable counterpart of OffsetDateTime. It shares the same serializer (formatOffsetDateTime / parseOffsetDateTime). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullOffsetDateTime ¶
func NewNullOffsetDateTime(value time.Time) NullOffsetDateTime
NewNullOffsetDateTime constructs a valid NullOffsetDateTime wrapping value.
func NewNullOffsetDateTimeEmpty ¶
func NewNullOffsetDateTimeEmpty() NullOffsetDateTime
NewNullOffsetDateTimeEmpty returns an invalid (NULL) NullOffsetDateTime.
func NullOffsetDateTimeFromString ¶
func NullOffsetDateTimeFromString(strValue *string) NullOffsetDateTime
NullOffsetDateTimeFromString parses an offset datetime from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullOffsetDateTime.
func (NullOffsetDateTime) After ¶
func (thisVal NullOffsetDateTime) After(dt time.Time) bool
After reports whether the receiver is valid and its instant is after dt. An invalid (NULL) value is never after anything.
func (NullOffsetDateTime) Before ¶
func (thisVal NullOffsetDateTime) Before(dt time.Time) bool
Before reports whether the receiver is valid and its instant is before dt. An invalid (NULL) value is never before anything.
func (*NullOffsetDateTime) IsEmpty ¶
func (thisVal *NullOffsetDateTime) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullOffsetDateTime) IsZero ¶
func (thisVal NullOffsetDateTime) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullOffsetDateTime) MarshalJSON ¶
func (thisVal NullOffsetDateTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in canonical offset datetime form, or null when empty. The valid path appends directly into a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal(formatOffsetDateTime(...)) would perform.
func (*NullOffsetDateTime) Scan ¶
func (thisVal *NullOffsetDateTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface, delegating to sql.NullTime so that the driver's NULL signalling is honoured.
func (NullOffsetDateTime) ToString ¶
func (thisVal NullOffsetDateTime) ToString() string
ToString renders the value in the library's canonical offset datetime form, or "" when NULL.
func (NullOffsetDateTime) Unix ¶
func (thisVal NullOffsetDateTime) Unix() int64
Unix returns the underlying instant as a Unix timestamp — the number of seconds elapsed since January 1, 1970 UTC. An invalid (NULL) value returns 0.
func (*NullOffsetDateTime) UnmarshalJSON ¶
func (thisVal *NullOffsetDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string containing an offset datetime, or the token null. Any other input is treated as a parse error.
type NullOffsetTime ¶
NullOffsetTime is the nullable counterpart of OffsetTime. It shares the same serializer (formatOffsetTime / parseOffsetTime). Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullOffsetTime ¶
func NewNullOffsetTime(value time.Time) NullOffsetTime
NewNullOffsetTime constructs a valid NullOffsetTime wrapping value.
func NewNullOffsetTimeEmpty ¶
func NewNullOffsetTimeEmpty() NullOffsetTime
NewNullOffsetTimeEmpty returns an invalid (NULL) NullOffsetTime.
func NullOffsetTimeFromString ¶
func NullOffsetTimeFromString(strValue *string) NullOffsetTime
NullOffsetTimeFromString parses an offset time from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullOffsetTime.
func (*NullOffsetTime) IsEmpty ¶
func (thisVal *NullOffsetTime) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullOffsetTime) IsZero ¶
func (thisVal NullOffsetTime) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullOffsetTime) MarshalJSON ¶
func (thisVal NullOffsetTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in canonical offset time form, or null when empty. The valid path appends directly into a single buffer via time.Time.AppendFormat, skipping the intermediate string and reflection dispatch that json.Marshal(formatOffsetTime(...)) would perform.
func (*NullOffsetTime) Scan ¶
func (thisVal *NullOffsetTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface, delegating to sql.NullTime so that the driver's NULL signalling is honoured.
func (NullOffsetTime) ToString ¶
func (thisVal NullOffsetTime) ToString() string
ToString renders the value in the library's canonical offset time form, or "" when NULL.
func (*NullOffsetTime) UnmarshalJSON ¶
func (thisVal *NullOffsetTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string containing an offset time, or the token null. Any other input is treated as a parse error.
type NullString ¶
NullString is a nullable string. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullString ¶
func NewNullString(value string) NullString
NewNullString constructs a valid NullString wrapping value. The empty string is preserved as a valid value; use NewNullStringEmpty or NSFromString if an empty input should collapse to NULL.
func NewNullStringEmpty ¶
func NewNullStringEmpty() NullString
NewNullStringEmpty returns an invalid (NULL) NullString.
func (*NullString) IsEmpty ¶
func (thisVal *NullString) IsEmpty() bool
IsEmpty reports whether the value is NULL (Valid == false).
func (NullString) IsZero ¶
func (thisVal NullString) IsZero() bool
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullString) MarshalJSON ¶
func (thisVal NullString) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string, or null when empty.
func (*NullString) Scan ¶
func (thisVal *NullString) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface, delegating to sql.NullString so that the driver's NULL signalling is honoured.
func (*NullString) ToString ¶
func (thisVal *NullString) ToString() string
ToString returns the underlying string, or "" when NULL. Note that valid empty strings are indistinguishable from NULL in this output — use the Valid field directly to discriminate.
func (*NullString) UnmarshalJSON ¶
func (thisVal *NullString) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string or the token null. Surrounding quotes and JSON escape sequences are decoded via encoding/json.
type NullUuid ¶
NullUuid is a nullable UUID backed by github.com/google/uuid. Valid reports whether Val holds a meaningful value (true) or a SQL/JSON NULL (false).
func NewNullUuid ¶
NewNullUuid constructs a valid NullUuid wrapping val.
func NewNullUuidEmpty ¶
func NewNullUuidEmpty() NullUuid
NewNullUuidEmpty returns an invalid (NULL) NullUuid.
func NullUuidFromString ¶
NullUuidFromString parses a UUID from the string pointer. A nil pointer, an empty string, the tokens "null"/"nil" (case-insensitive), or a parse error all produce an invalid NullUuid.
func (NullUuid) IsZero ¶
IsZero reports whether the value is NULL (Valid == false). Mirroring time.Time.IsZero, this also enables encoding/json's `omitzero` tag (Go 1.24+) to elide invalid wrappers from marshalled output.
func (NullUuid) MarshalJSON ¶
MarshalJSON renders the value as a JSON string in canonical UUID form, or null when empty.
func (*NullUuid) Scan ¶
Scan implements the database/sql.Scanner interface. The UUID is received as text from the driver (via sql.NullString) and parsed through NullUuidFromString.
func (*NullUuid) ToString ¶
ToString renders the UUID in canonical 8-4-4-4-12 hex form, or "" when NULL.
func (*NullUuid) UnmarshalJSON ¶
UnmarshalJSON parses a JSON string containing a UUID, or the token null. Any other input is treated as a parse error.
type OffsetDateTime ¶
OffsetDateTime is a not-null datetime with a timezone offset (RFC 3339).
Use OffsetDateTime when the value is anchored to a specific point in time (e.g. an event timestamp). For wall-clock datetimes without an offset, use LocalDateTime.
func NewOffsetDateTime ¶
func NewOffsetDateTime(t time.Time) OffsetDateTime
NewOffsetDateTime wraps t as an OffsetDateTime, preserving its location.
func OffsetDateTimeFromString ¶
func OffsetDateTimeFromString(strValue string) (OffsetDateTime, error)
OffsetDateTimeFromString parses a datetime in any of the formats accepted by ParseDateTimeFromString.
func (OffsetDateTime) After ¶
func (thisVal OffsetDateTime) After(dt time.Time) bool
After reports whether the receiver is after dt.
func (OffsetDateTime) AsTime ¶
func (thisVal OffsetDateTime) AsTime() time.Time
AsTime returns the underlying time.Time.
func (OffsetDateTime) Before ¶
func (thisVal OffsetDateTime) Before(dt time.Time) bool
Before reports whether the receiver is before dt.
func (OffsetDateTime) MarshalJSON ¶
func (thisVal OffsetDateTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in the library's canonical TZ-aware format.
func (*OffsetDateTime) Scan ¶
func (thisVal *OffsetDateTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. A NULL value is rejected — OffsetDateTime cannot be empty.
func (OffsetDateTime) ToString ¶
func (thisVal OffsetDateTime) ToString() string
ToString renders the value in the library's canonical TZ-aware format.
func (OffsetDateTime) Unix ¶
func (thisVal OffsetDateTime) Unix() int64
Unix returns the underlying instant as a Unix timestamp — the number of seconds elapsed since January 1, 1970 UTC.
func (*OffsetDateTime) UnmarshalJSON ¶
func (thisVal *OffsetDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string in any of the formats accepted by OffsetDateTimeFromString. JSON null is rejected — OffsetDateTime cannot be empty.
type OffsetTime ¶
OffsetTime is a not-null time-of-day with a timezone offset.
Use OffsetTime when the time-of-day value carries a meaningful zone offset (e.g. exchange opens at "09:30:00-05:00"). For zone-less times, use LocalTime.
func NewOffsetTime ¶
func NewOffsetTime(t time.Time) OffsetTime
NewOffsetTime wraps t as an OffsetTime, preserving its location.
func OffsetTimeFromString ¶
func OffsetTimeFromString(strValue string) (OffsetTime, error)
OffsetTimeFromString parses a time-of-day with an optional timezone designator. When no designator is present, time.Local is assumed.
func (OffsetTime) AsTime ¶
func (thisVal OffsetTime) AsTime() time.Time
AsTime returns the underlying time.Time.
func (OffsetTime) MarshalJSON ¶
func (thisVal OffsetTime) MarshalJSON() ([]byte, error)
MarshalJSON renders the value as a JSON string in the library's canonical TZ-aware format.
func (*OffsetTime) Scan ¶
func (thisVal *OffsetTime) Scan(value interface{}) error
Scan implements the database/sql.Scanner interface. A NULL value is rejected — OffsetTime cannot be empty.
func (OffsetTime) String ¶
func (thisVal OffsetTime) String() string
String renders the value in the library's canonical TZ-aware format.
func (OffsetTime) ToString ¶
func (thisVal OffsetTime) ToString() string
ToString is an alias for String, satisfying the ToStringAble interface.
func (*OffsetTime) UnmarshalJSON ¶
func (thisVal *OffsetTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a JSON string in any of the formats accepted by OffsetTimeFromString. JSON null is rejected — OffsetTime cannot be empty.
type ToStringAble ¶
type ToStringAble interface {
ToString() string
}
ToStringAble is the interface implemented by every nullable type in the package. ToString renders the value in its canonical textual form (an empty string when the value is missing/NULL).
Source Files
¶
- date.go
- doc.go
- emptiable.go
- format_date.go
- format_local_datetime.go
- format_local_time.go
- format_offset_datetime.go
- format_offset_time.go
- local_datetime.go
- local_time.go
- null_bool.go
- null_date.go
- null_decimal.go
- null_float.go
- null_int16.go
- null_int32.go
- null_int64.go
- null_json.go
- null_local_datetime.go
- null_local_time.go
- null_offset_datetime.go
- null_offset_time.go
- null_string.go
- null_uuid.go
- offset_datetime.go
- offset_time.go
- string_able.go
- types_utils.go