-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnullPolygon.go
53 lines (42 loc) · 1 KB
/
nullPolygon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package pgeo
import (
"database/sql/driver"
"encoding/json"
"github.com/volatiletech/sqlboiler/randomize"
)
type NullPolygon struct {
Polygon
Valid bool
}
func (p NullPolygon) Value() (driver.Value, error) {
if !p.Valid {
return nil, nil
}
return valuePolygon(p.Polygon)
}
func (p *NullPolygon) Scan(src interface{}) error {
if src == nil {
p.Polygon, p.Valid = NewPolygon([]Point{Point{}, Point{}, Point{}, Point{}}), false
return nil
}
p.Valid = true
return scanPolygon(&p.Polygon, src)
}
func (p *NullPolygon) MarshalJSON() ([]byte, error) {
if !p.Valid {
return []byte("null"), nil
}
return json.Marshal(p.Polygon)
}
func (p *NullPolygon) UnmarshalJSON(data []byte) error {
if string(data) == "" || string(data) == "null" {
p.Valid = false
return nil
}
var err = json.Unmarshal(data, p.Polygon)
p.Valid = err == nil
return err
}
func (o *NullPolygon) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
*o = NewNullPolygon(NewRandPolygon(), !shouldBeNull)
}