types

package
v0.0.0-...-77b25ca Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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().

View Source
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

func ConvertCommitTime(driverTime time.Time, timezone *time.Location) time.Time

ConvertCommitTime reinterprets driverTime as timezone local wall clock and returns UTC.

func FormatMSSQLGUID

func FormatMSSQLGUID(b []byte) string

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

func ParseTimeValue(v interface{}) (time.Time, bool)

ParseTimeValue extracts a UTC time and validity from common date-like values.

func SetDefaultTimezone

func SetDefaultTimezone(tz *time.Location)

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 DBType

type DBType interface {
	sql.Scanner
	driver.Valuer
	json.Marshaler
	json.Unmarshaler
}

DBType is the unified interface for SQL scan/write + JSON encode/decode.

type Dialect

type Dialect string

Dialect identifies database type mapping strategy.

const (
	DialectMSSQL  Dialect = "mssql"
	DialectSQLite Dialect = "sqlite"
)

type MSSQLTime

type MSSQLTime = NullTime

MSSQLTime is kept as a backward-compatible alias of NullTime.

type NullBool

type NullBool struct{ Nullable[bool] }

func (*NullBool) Scan

func (b *NullBool) Scan(src interface{}) error

Scan implements sql.Scanner for NullBool.

type NullBytes

type NullBytes struct{ Nullable[[]byte] }

func (*NullBytes) Scan

func (b *NullBytes) Scan(src interface{}) error

Scan implements sql.Scanner for NullBytes.

type NullDecimal

type NullDecimal struct{ Nullable[string] }

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

type NullFloat64 struct{ Nullable[float64] }

func (*NullFloat64) Scan

func (f *NullFloat64) Scan(src interface{}) error

Scan implements sql.Scanner for NullFloat64.

type NullGUID

type NullGUID struct{ Nullable[string] }

NullGUID scans MSSQL UNIQUEIDENTIFIER values.

func (*NullGUID) Scan

func (g *NullGUID) Scan(src interface{}) error

Scan implements sql.Scanner for NullGUID.

type NullInt64

type NullInt64 struct{ Nullable[int64] }

func (*NullInt64) Scan

func (i *NullInt64) Scan(src interface{}) error

Scan implements sql.Scanner for NullInt64.

type NullString

type NullString struct{ Nullable[string] }

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 (m NullTime) MarshalJSON() ([]byte, error)

func (*NullTime) Scan

func (m *NullTime) Scan(src interface{}) error

func (*NullTime) Time

func (m *NullTime) Time() time.Time

func (*NullTime) UnmarshalJSON

func (m *NullTime) UnmarshalJSON(data []byte) error

func (*NullTime) Valid

func (m *NullTime) Valid() bool

func (NullTime) Value

func (m NullTime) Value() (driver.Value, error)

Value returns a formatted value matching the JSON output format so that SQLite storage and JSON serialization are always consistent. For Unix timestamp formats (int64), the raw int64 is returned.

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

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

MarshalJSON implements json.Marshaler. Returns JSON null when not valid; otherwise marshals the underlying value.

func (*Nullable[T]) Scan

func (n *Nullable[T]) Scan(src interface{}) error

Scan implements sql.Scanner.

func (*Nullable[T]) UnmarshalJSON

func (n *Nullable[T]) UnmarshalJSON(data []byte) error

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.

func (Nullable[T]) Valid

func (n Nullable[T]) Valid() bool

Valid reports whether the value is non-NULL.

func (Nullable[T]) Value

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

Value implements driver.Valuer.

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.

Jump to

Keyboard shortcuts

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