Documentation
¶
Overview ¶
Package fields provides custom datatype fields and structures for GORM database models persisting. It includes types like high-precision numeric decimals (DecimalSix) and PostgreSQL coordinates (PGPoint).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DecimalSix ¶
type DecimalSix struct {
// R represents the underlying high-precision big rational number value.
R *big.Rat
}
DecimalSix represents a decimal numeric amount rounded to exactly 6 decimal places. It is intended for high-precision monetary-style fields or coordinate points. It maps to database NUMERIC storage columns and uses Go's standard *big.Rat representation.
func (DecimalSix) MarshalText ¶
func (p DecimalSix) MarshalText() ([]byte, error)
MarshalText serializes the rational number into a byte slice formatted with 6 decimal places.
func (DecimalSix) NormalizeDecimals ¶
func (p DecimalSix) NormalizeDecimals() DecimalSix
NormalizeDecimals yields a new DecimalSix structure with its big rational value rounded to exactly 6 decimal places.
func (*DecimalSix) Scan ¶
func (p *DecimalSix) Scan(src any) error
Scan implements the sql Scanner interface to populate decimal structures from database columns.
func (DecimalSix) String ¶
func (p DecimalSix) String() string
String returns a formatted fixed 6-decimal string representation suitable for UI views.
func (*DecimalSix) UnmarshalText ¶
func (p *DecimalSix) UnmarshalText(text []byte) error
UnmarshalText deserializes the byte slice formatted string into the high-precision rational number.
type PGPoint ¶
type PGPoint struct {
// Point embeds pgtype.Point containing Vec2 structures and validation markers.
pgtype.Point
}
PGPoint wraps PostgreSQL's geometric POINT type (representing float8 X and Y coordinates). When storing WGS84 geographic coordinates, use X to represent longitude and Y to represent latitude.
func NewPGPoint ¶
NewPGPoint constructs a valid PGPoint wrapper using raw longitude and latitude floats.