datum

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 10 Imported by: 0

README

Datum GoDoc

Datum is a set of tools for serializing geospatial primitives with database/sql & volatiletech/sqlboiler. It's currently limited to point, nullPoint, and nullGeometryCollection.

Example

Below is a minimal example of using datum to serialize a geospatial point to a record with sqlboiler generated structs.

    import (
        "log"

        "gitub.com/myorg/path/to/sqlboiler/models"
        "github.com/1build/datum"
    )

    const srid := 4326

    record := &models.Supplier{
        Name: input.Name,
        Location: datum.Point{
            SRID: srid,
            Lat:  input.Lat,
            Lng:  input.Lng,
        },
    }

    if err := record.Insert(ctx, tx, boil.Infer()); err != nil {
        warning := fmt.Sprintf("[Supplier.Repository.CreateSupplier]: Couldn't create new supplier: %s", input.Name)
        log.Panic(warning)

        return nil, errors.New(warning)
    }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NullGeometryCollection

type NullGeometryCollection struct {
	GeometryCollection *geom.GeometryCollection
}

NullGeometryCollection --

func (*NullGeometryCollection) Scan

func (gc *NullGeometryCollection) Scan(src interface{}) error

Scan scans from a []byte.

func (NullGeometryCollection) Value

func (gc NullGeometryCollection) Value() (driver.Value, error)

Value returns the WKB encoding of gc.

type NullPoint

type NullPoint struct {
	Point *geom.Point
}

NullPoint --

func (*NullPoint) Scan

func (gc *NullPoint) Scan(src interface{}) error

Scan scans from a []byte.

func (NullPoint) Value

func (gc NullPoint) Value() (driver.Value, error)

Value returns the WKB encoding of gc.

type Point

type Point struct {
	SRID int
	Lng  float64
	Lat  float64
}

Point is a PostGIS point.

func NewPoint

func NewPoint(srid int, lng float64, lat float64) Point

NewPoint creates a new point.

func PointFromVal

func PointFromVal(value interface{}, srid int) (*Point, error)

PointFromVal creates a new point from any value. If the value is nil, the point (0 0) is returned.

func (*Point) Scan

func (p *Point) Scan(value interface{}, srid int) error

Scan implements the Scanner interface.

func (Point) Value

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

Value implements the driver Value interface.

Jump to

Keyboard shortcuts

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