Documentation
¶
Index ¶
- Constants
- func ConvertCommitTime(driverTime time.Time, timezone *time.Location) time.Time
- func FormatMSSQLGUID(b []byte) string
- func FormatTimeValue(v interface{}, format TimeFormat) interface{}
- func ParseTimeValue(v interface{}) (time.Time, bool)
- func SetDefaultTimezone(tz *time.Location)
- type Codec
- type DBType
- type Dialect
- type MSSQLTime
- type NullBool
- type NullBytes
- type NullDecimal
- type NullFloat64
- type NullGUID
- type NullInt64
- type NullString
- type NullTime
- type Nullable
- type TimeFormat
Constants ¶
const ( TypeBigInt = "BIGINT" TypeInt = "INT" TypeSmallInt = "SMALLINT" TypeTinyInt = "TINYINT" TypeBit = "BIT" TypeFloat = "FLOAT" TypeReal = "REAL" TypeNumeric = "NUMERIC" TypeDecimal = "DECIMAL" TypeMoney = "MONEY" TypeSmallMoney = "SMALLMONEY" TypeDateTime = "DATETIME" TypeDateTime2 = "DATETIME2" TypeSmallDateTime = "SMALLDATETIME" TypeDate = "DATE" TypeTime = "TIME" TypeDateTimeOffset = "DATETIMEOFFSET" TypeUniqueIdentifier = "UNIQUEIDENTIFIER" TypeChar = "CHAR" TypeVarchar = "VARCHAR" TypeNChar = "NCHAR" TypeNVarchar = "NVARCHAR" TypeNText = "NTEXT" TypeText = "TEXT" TypeBinary = "BINARY" TypeVarBinary = "VARBINARY" TypeImage = "IMAGE" TypeXML = "XML" TypeSQLVariant = "SQL_VARIANT" )
MSSQL type names from DatabaseTypeName().
const ( TypeSQLiteText = "TEXT" TypeSQLiteInteger = "INTEGER" TypeSQLiteReal = "REAL" TypeSQLiteBlob = "BLOB" TypeSQLiteNumeric = "NUMERIC" TypeSQLiteDatetime = "DATETIME" TypeSQLiteTimestamp = "TIMESTAMP" TypeSQLiteBoolean = "BOOLEAN" )
SQLite type names from DatabaseTypeName().
Variables ¶
This section is empty.
Functions ¶
func ConvertCommitTime ¶
ConvertCommitTime reinterprets driverTime as timezone local wall clock and returns UTC.
func FormatMSSQLGUID ¶
FormatMSSQLGUID exports formatMSSQLGUID for use by other packages.
func FormatTimeValue ¶
func FormatTimeValue(v interface{}, format TimeFormat) interface{}
FormatTimeValue weakly formats date-like values for map[string]interface{} payloads.
func ParseTimeValue ¶
ParseTimeValue extracts a UTC time and validity from common date-like values.
func SetDefaultTimezone ¶
SetDefaultTimezone sets the package-level default timezone for MSSQL codecs created by NewMSSQLCodec (no explicit timezone option). Call this once at startup, e.g. from config.ParseTimezone.
Types ¶
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
Codec creates typed DB destinations from sql.ColumnType metadata.
func NewMSSQLCodec ¶
func NewMSSQLCodec() *Codec
NewMSSQLCodec creates an MSSQL codec using the package-level default timezone and no format override.
func NewMSSQLCodecWithOptions ¶
func NewMSSQLCodecWithOptions(tz *time.Location, format TimeFormat) *Codec
NewMSSQLCodecWithOptions creates an MSSQL codec with explicit timezone and output format. Pass nil timezone to use time.UTC; pass "" format to use DefaultTimeFormat in JSON output.
func NewSQLiteCodec ¶
func NewSQLiteCodec() *Codec
NewSQLiteCodec creates a SQLite codec that shares the package-level default timezone with MSSQL codecs. Call SetDefaultTimezone once at startup to keep both dialects in sync.
func (*Codec) CreateDest ¶
func (c *Codec) CreateDest(colTypes []*sql.ColumnType) []interface{}
CreateDest creates a []interface{} of DBType pointers for rows.Scan.
type MSSQLTime ¶
type MSSQLTime = NullTime
MSSQLTime is kept as a backward-compatible alias of NullTime.
type NullDecimal ¶
NullDecimal preserves numeric string representation to avoid precision loss.
func (*NullDecimal) Scan ¶
func (s *NullDecimal) Scan(src interface{}) error
Scan implements sql.Scanner for NullDecimal.
type NullFloat64 ¶
func (*NullFloat64) Scan ¶
func (f *NullFloat64) Scan(src interface{}) error
Scan implements sql.Scanner for NullFloat64.
type NullString ¶
func (*NullString) Scan ¶
func (s *NullString) Scan(src interface{}) error
Scan implements sql.Scanner for NullString.
type NullTime ¶
type NullTime struct {
// contains filtered or unexported fields
}
NullTime is the unified nullable time type for MSSQL/SQLite scan + SQL write + JSON. Scan-time timezone reinterpretation corrects MSSQL driver's DATETIME location issue.
func NewMSSQLTime ¶
func NewMSSQLTime(tz *time.Location, format TimeFormat) *NullTime
NewMSSQLTime is kept as a backward-compatible constructor alias.
func NewNullTime ¶
func NewNullTime(tz *time.Location, format TimeFormat) *NullTime
func (NullTime) MarshalJSON ¶
func (*NullTime) UnmarshalJSON ¶
type Nullable ¶
type Nullable[T any] struct { // contains filtered or unexported fields }
Nullable represents a value that may be NULL. It implements sql.Scanner, driver.Valuer, json.Marshaler and json.Unmarshaler. When Valid is false, Value() returns nil (SQL NULL) and MarshalJSON returns null.
func (Nullable[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler. Returns JSON null when not valid; otherwise marshals the underlying value.
func (*Nullable[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. JSON null sets the value to invalid; any other JSON value is unmarshalled into T.
func (Nullable[T]) Val ¶
func (n Nullable[T]) Val() T
Val returns the underlying value. Check Valid() before using it.
type TimeFormat ¶
type TimeFormat string
TimeFormat defines how NullTime values are serialized for JSON output.
const ( TimeFormatRFC3339Nano TimeFormat = "RFC3339Nano" TimeFormatRFC3339 TimeFormat = "RFC3339" TimeFormatDatetime TimeFormat = "datetime" TimeFormatDate TimeFormat = "date" TimeFormatUnix TimeFormat = "unix" TimeFormatUnixMilli TimeFormat = "unixMilli" TimeFormatUnixNano TimeFormat = "unixNano" )
var DefaultTimeFormat TimeFormat = TimeFormatDatetime
DefaultTimeFormat applies when a NullTime has no per-instance format override. Defaults to "datetime" ("2006-01-02 15:04:05") so SQLite storage and JSON output share the same human-readable format.