fields

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 6 Imported by: 0

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.

func (DecimalSix) Value

func (p DecimalSix) Value() (driver.Value, error)

Value implements the database driver Valuer interface to save decimal numbers as numeric database strings.

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

func NewPGPoint(lng, lat float64) PGPoint

NewPGPoint constructs a valid PGPoint wrapper using raw longitude and latitude floats.

func (*PGPoint) Scan

func (p *PGPoint) Scan(src any) error

Scan implements the database sql Scanner interface. It supports scanning standard pgtype objects as well as raw byte arrays.

Jump to

Keyboard shortcuts

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