Documentation
¶
Overview ¶
Example ¶
package main
import (
"database/sql"
gopostgis "github.com/asif-mahmud/go-postgis"
)
func main() {
// we know it will panic at testing time, so
// recovering silently, ignore this part
defer func() {
recover()
}()
// this is written for purely example purpose
// create db connection
db, e := sql.Open("postgres", "database=test_db")
if e != nil {
panic(e)
}
// create a table with geometry column
_, e = db.Exec(`CREATE TABLE IF NOT EXISTS test_table (
id SERIAL PRIMARY KEY,
location GEOMETRY
)`)
if e != nil {
panic(e)
}
// construct a point
point := gopostgis.Point{
X: 10,
Y: 20,
Valid: true, // if you don't mark it as valid, null will be saved in db
}
// insert a point
_, e = db.Exec(`
INSERT INTO test_table (location) VALUES($1)`,
point,
)
if e != nil {
panic(e)
}
// read a point
row := db.QueryRow(`SELECT location from test_table LIMIT 1`)
if e := row.Scan(&point); e != nil {
panic(e)
}
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HexEWKBDecoder ¶
type HexEWKBDecoder interface {
// Decoded datatype that represents a postgis datatype.
// Example - 0x00000001 means it is Point type.
// See the reference doc for full list of datatypes.
Type() uint32
// Reads a single byte
ReadByte() (byte, error)
// Reads a 32-bit unsigned integer
ReadUint32() (uint32, error)
// Reads a 64-bit float
ReadDouble() (float64, error)
// Reads into any fixed-size value
ReadAny(interface{}) error
}
Decoder for hex encoded EWKB data. reference - https://github.com/postgis/postgis/blob/master/doc/bnf-wkb.txt It does not implement any specific postgis datatype, instead it is intended to be used as a reader for specific postgis datatype implementation. Instance of this struct should be initialized by NewHexEWKBDecoder function. Creating an instance of this struct directly will cause incorrect behavior
func NewHexEWKBDecoder ¶
func NewHexEWKBDecoder(data []byte) (HexEWKBDecoder, error)
Creates an instance of HexEWKBDecoder.
type Point ¶ added in v0.1.1
Point (X, Y) datatype. Supports NULL value.
func (Point) MarshalJSON ¶ added in v0.1.1
MarshalJSON implements json.Marshaler
func (*Point) UnmarshalJSON ¶ added in v0.1.1
UnmarshalJSON implements json.Unmarshaler
type PointM ¶ added in v0.1.2
PointM (X, Y, M) datatype. Supports NULL value.
func (PointM) MarshalJSON ¶ added in v0.1.2
MarshalJSON implements json.Marshaler
func (*PointM) UnmarshalJSON ¶ added in v0.1.2
UnmarshalJSON implements json.Unmarshaler
type PointMS ¶ added in v0.1.2
PointMS (SRID X, Y, M) datatype. Supports NULL value.
func (PointMS) MarshalJSON ¶ added in v0.1.2
MarshalJSON implements json.Marshaler
func (*PointMS) UnmarshalJSON ¶ added in v0.1.2
UnmarshalJSON implements json.Unmarshaler
type PointS ¶ added in v0.1.1
PointS (SRID X, Y) datatype. Supports NULL value.
func (PointS) MarshalJSON ¶ added in v0.1.1
MarshalJSON implements json.Marshaler
func (*PointS) UnmarshalJSON ¶ added in v0.1.1
UnmarshalJSON implements json.Unmarshaler
type PointZ ¶ added in v0.1.2
PointZ (X, Y, Z) datatype. Supports NULL value.
func (PointZ) MarshalJSON ¶ added in v0.1.2
MarshalJSON implements json.Marshaler
func (*PointZ) UnmarshalJSON ¶ added in v0.1.2
UnmarshalJSON implements json.Unmarshaler
type PointZM ¶ added in v0.1.2
PointZM (X, Y, Z, M) datatype. Supports NULL value.
func (PointZM) MarshalJSON ¶ added in v0.1.2
MarshalJSON implements json.Marshaler
func (*PointZM) UnmarshalJSON ¶ added in v0.1.2
UnmarshalJSON implements json.Unmarshaler
type PointZMS ¶ added in v0.1.2
PointZMS (SRID X, Y, Z, M) datatype. Supports NULL value.
func (PointZMS) MarshalJSON ¶ added in v0.1.2
MarshalJSON implements json.Marshaler
func (*PointZMS) UnmarshalJSON ¶ added in v0.1.2
UnmarshalJSON implements json.Unmarshaler
type PointZS ¶ added in v0.1.2
PointZS (SRID X, Y, Z) datatype. Supports NULL value.
func (PointZS) MarshalJSON ¶ added in v0.1.2
MarshalJSON implements json.Marshaler
func (*PointZS) UnmarshalJSON ¶ added in v0.1.2
UnmarshalJSON implements json.Unmarshaler