github.com/Ali-iotechsys/sqlboiler/v4@v4.0.0-20221208124957-6aec9a5f1f71/types/pgeo/point.go (about)

     1  package pgeo
     2  
     3  import (
     4  	"database/sql/driver"
     5  )
     6  
     7  // Point is the fundamental two-dimensional building block for geometric types.
     8  // X and Y are the respective coordinates, as floating-point numbers
     9  type Point struct {
    10  	X float64 `json:"x"`
    11  	Y float64 `json:"y"`
    12  }
    13  
    14  // Value representation for database
    15  func (p Point) Value() (driver.Value, error) {
    16  	return valuePoint(p)
    17  }
    18  
    19  // Scan from query
    20  func (p *Point) Scan(src interface{}) error {
    21  	return scanPoint(p, src)
    22  }
    23  
    24  func valuePoint(p Point) (driver.Value, error) {
    25  	return formatPoint(p), nil
    26  }
    27  
    28  func scanPoint(p *Point, src interface{}) error {
    29  	if src == nil {
    30  		*p = NewPoint(0, 0)
    31  		return nil
    32  	}
    33  
    34  	val, err := iToS(src)
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	*p, err = parsePoint(val)
    40  	if err != nil {
    41  		return err
    42  	}
    43  
    44  	return nil
    45  
    46  }
    47  
    48  func randPoint(nextInt func() int64) Point {
    49  	return Point{newRandNum(nextInt), newRandNum(nextInt)}
    50  }
    51  
    52  func randPoints(nextInt func() int64, n int) []Point {
    53  	var points = []Point{}
    54  	if n <= 0 {
    55  		return points
    56  	}
    57  
    58  	for i := 0; i < n; i++ {
    59  		points = append(points, randPoint(nextInt))
    60  	}
    61  
    62  	return points
    63  }
    64  
    65  // Randomize for sqlboiler
    66  func (p *Point) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
    67  	*p = randPoint(nextInt)
    68  }