spectypes

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package spectypes provides nullable SQL types with automatic casting and conversion methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToJSONDT

func ToJSONDT(dt time.Time) string

ToJSONDT formats a time.Time to RFC3339 string.

func TryIfInt64

func TryIfInt64(v any, def int64) int64

TryIfInt64 tries to parse any value to int64 with default.

Types

type SqlBool

type SqlBool = SqlNull[bool]

Type aliases for common types.

func NewSqlBool

func NewSqlBool(v bool) SqlBool

type SqlDate

type SqlDate struct{ SqlNull[time.Time] }

SqlDate - Date only (YYYY-MM-DD).

func NewSqlDate

func NewSqlDate(v time.Time) SqlDate

func SqlDateNow

func SqlDateNow() SqlDate

func (SqlDate) MarshalJSON

func (d SqlDate) MarshalJSON() ([]byte, error)

func (SqlDate) String

func (d SqlDate) String() string

func (*SqlDate) UnmarshalJSON

func (d *SqlDate) UnmarshalJSON(b []byte) error

func (SqlDate) Value

func (d SqlDate) Value() (driver.Value, error)

type SqlFloat64

type SqlFloat64 = SqlNull[float64]

Type aliases for common types.

func NewSqlFloat64

func NewSqlFloat64(v float64) SqlFloat64

type SqlInt16

type SqlInt16 = SqlNull[int16]

Type aliases for common types.

func NewSqlInt16

func NewSqlInt16(v int16) SqlInt16

type SqlInt32

type SqlInt32 = SqlNull[int32]

Type aliases for common types.

func NewSqlInt32

func NewSqlInt32(v int32) SqlInt32

type SqlInt64

type SqlInt64 = SqlNull[int64]

Type aliases for common types.

func NewSqlInt64

func NewSqlInt64(v int64) SqlInt64

type SqlJSONB

type SqlJSONB []byte

SqlJSONB - Nullable JSONB as []byte.

func (SqlJSONB) AsMap

func (n SqlJSONB) AsMap() (map[string]any, error)

func (SqlJSONB) AsSlice

func (n SqlJSONB) AsSlice() ([]any, error)

func (SqlJSONB) MarshalJSON

func (n SqlJSONB) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*SqlJSONB) Scan

func (n *SqlJSONB) Scan(value any) error

Scan implements sql.Scanner.

func (*SqlJSONB) UnmarshalJSON

func (n *SqlJSONB) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (SqlJSONB) Value

func (n SqlJSONB) Value() (driver.Value, error)

Value implements driver.Valuer.

type SqlNull

type SqlNull[T any] struct {
	Val   T
	Valid bool
}

SqlNull is a generic nullable type that behaves like sql.NullXXX with auto-casting.

func NewSql

func NewSql[T any](value any) SqlNull[T]

func Null

func Null[T any](v T, valid bool) SqlNull[T]

Constructor helpers - clean and fast value creation

func (SqlNull[T]) Bool

func (n SqlNull[T]) Bool() bool

Bool converts to bool or false if invalid.

func (SqlNull[T]) Float64

func (n SqlNull[T]) Float64() float64

Float64 converts to float64 or 0.0 if invalid.

func (*SqlNull[T]) FromString

func (n *SqlNull[T]) FromString(s string) error

func (SqlNull[T]) Int64

func (n SqlNull[T]) Int64() int64

Int64 converts to int64 or 0 if invalid.

func (SqlNull[T]) MarshalJSON

func (n SqlNull[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*SqlNull[T]) Scan

func (n *SqlNull[T]) Scan(value any) error

Scan implements sql.Scanner.

func (SqlNull[T]) String

func (n SqlNull[T]) String() string

String implements fmt.Stringer.

func (SqlNull[T]) Time

func (n SqlNull[T]) Time() time.Time

Time converts to time.Time or zero if invalid.

func (SqlNull[T]) UUID

func (n SqlNull[T]) UUID() uuid.UUID

UUID converts to uuid.UUID or Nil if invalid.

func (*SqlNull[T]) UnmarshalJSON

func (n *SqlNull[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (SqlNull[T]) Value

func (n SqlNull[T]) Value() (driver.Value, error)

Value implements driver.Valuer.

type SqlString

type SqlString = SqlNull[string]

Type aliases for common types.

func NewSqlString

func NewSqlString(v string) SqlString

type SqlTime

type SqlTime struct{ SqlNull[time.Time] }

SqlTime - Time only (HH:MM:SS).

func NewSqlTime

func NewSqlTime(v time.Time) SqlTime

func SqlTimeNow

func SqlTimeNow() SqlTime

func (SqlTime) MarshalJSON

func (t SqlTime) MarshalJSON() ([]byte, error)

func (SqlTime) String

func (t SqlTime) String() string

func (*SqlTime) UnmarshalJSON

func (t *SqlTime) UnmarshalJSON(b []byte) error

func (SqlTime) Value

func (t SqlTime) Value() (driver.Value, error)

type SqlTimeStamp

type SqlTimeStamp struct{ SqlNull[time.Time] }

SqlTimeStamp - Timestamp with custom formatting (YYYY-MM-DDTHH:MM:SS).

func NewSqlTimeStamp

func NewSqlTimeStamp(v time.Time) SqlTimeStamp

func SqlTimeStampNow

func SqlTimeStampNow() SqlTimeStamp

func (SqlTimeStamp) MarshalJSON

func (t SqlTimeStamp) MarshalJSON() ([]byte, error)

func (*SqlTimeStamp) UnmarshalJSON

func (t *SqlTimeStamp) UnmarshalJSON(b []byte) error

func (SqlTimeStamp) Value

func (t SqlTimeStamp) Value() (driver.Value, error)

type SqlUUID

type SqlUUID = SqlNull[uuid.UUID]

Type aliases for common types.

func NewSqlUUID

func NewSqlUUID(v uuid.UUID) SqlUUID

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL