Skip to content

Commit f4b5a8a

Browse files
author
James Cor
committed
implement for geom types
1 parent 5fe77ac commit f4b5a8a

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed

sql/types/linestring.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ func (t LineStringType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqlty
108108
return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil
109109
}
110110

111+
// CompareValue implements the ValueType interface.
112+
func (t LineStringType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) {
113+
panic("TODO: implement CompareValue for LineStringType")
114+
}
115+
116+
// SQLValue implements the ValueType interface.
117+
func (t LineStringType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
118+
if v.IsNull() {
119+
return sqltypes.NULL, nil
120+
}
121+
if v.Val == nil {
122+
var err error
123+
v.Val, err = v.WrappedVal.Unwrap(ctx)
124+
if err != nil {
125+
return sqltypes.Value{}, err
126+
}
127+
}
128+
return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil
129+
}
130+
111131
// String implements Type interface.
112132
func (t LineStringType) String() string {
113133
return "linestring"

sql/types/multilinestring.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ func (t MultiLineStringType) SQL(ctx *sql.Context, dest []byte, v interface{}) (
111111
return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil
112112
}
113113

114+
// CompareValue implements the ValueType interface.
115+
func (t MultiLineStringType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) {
116+
panic("TODO: implement CompareValue for MultiLineStringType")
117+
}
118+
119+
// SQLValue implements the ValueType interface.
120+
func (t MultiLineStringType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
121+
if v.IsNull() {
122+
return sqltypes.NULL, nil
123+
}
124+
if v.Val == nil {
125+
var err error
126+
v.Val, err = v.WrappedVal.Unwrap(ctx)
127+
if err != nil {
128+
return sqltypes.Value{}, err
129+
}
130+
}
131+
return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil
132+
}
133+
114134
// String implements Type interface.
115135
func (t MultiLineStringType) String() string {
116136
return "multilinestring"

sql/types/multipoint.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ func (t MultiPointType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqlty
115115
return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil
116116
}
117117

118+
// CompareValue implements the ValueType interface.
119+
func (t MultiPointType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) {
120+
panic("TODO: implement CompareValue for MultiPointType")
121+
}
122+
123+
// SQLValue implements the ValueType interface.
124+
func (t MultiPointType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
125+
if v.IsNull() {
126+
return sqltypes.NULL, nil
127+
}
128+
if v.Val == nil {
129+
var err error
130+
v.Val, err = v.WrappedVal.Unwrap(ctx)
131+
if err != nil {
132+
return sqltypes.Value{}, err
133+
}
134+
}
135+
return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil
136+
}
137+
118138
// String implements Type interface.
119139
func (t MultiPointType) String() string {
120140
return "multipoint"

sql/types/multipolygon.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ func (t MultiPolygonType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sql
111111
return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil
112112
}
113113

114+
// CompareValue implements the ValueType interface.
115+
func (t MultiPolygonType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) {
116+
panic("TODO: implement CompareValue for MultiPolygonType")
117+
}
118+
119+
// SQLValue implements the ValueType interface.
120+
func (t MultiPolygonType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
121+
if v.IsNull() {
122+
return sqltypes.NULL, nil
123+
}
124+
if v.Val == nil {
125+
var err error
126+
v.Val, err = v.WrappedVal.Unwrap(ctx)
127+
if err != nil {
128+
return sqltypes.Value{}, err
129+
}
130+
}
131+
return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil
132+
}
133+
114134
// String implements Type interface.
115135
func (t MultiPolygonType) String() string {
116136
return "multipolygon"

sql/types/point.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Point struct {
4242
}
4343

4444
var _ sql.Type = PointType{}
45+
var _ sql.ValueType = PointType{}
4546
var _ sql.SpatialColumnType = PointType{}
4647
var _ sql.CollationCoercible = PointType{}
4748
var _ GeometryValue = Point{}
@@ -123,6 +124,26 @@ func (t PointType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes.V
123124
return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil
124125
}
125126

127+
// CompareValue implements the ValueType interface.
128+
func (t PointType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) {
129+
panic("TODO: implement CompareValue for PointType")
130+
}
131+
132+
// SQLValue implements the ValueType interface.
133+
func (t PointType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
134+
if v.IsNull() {
135+
return sqltypes.NULL, nil
136+
}
137+
if v.Val == nil {
138+
var err error
139+
v.Val, err = v.WrappedVal.Unwrap(ctx)
140+
if err != nil {
141+
return sqltypes.Value{}, err
142+
}
143+
}
144+
return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil
145+
}
146+
126147
// String implements Type interface.
127148
func (t PointType) String() string {
128149
return "point"

sql/types/polygon.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ func (t PolygonType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes
113113
return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil
114114
}
115115

116+
// CompareValue implements the ValueType interface.
117+
func (t PolygonType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) {
118+
panic("TODO: implement CompareValue for PolygonType")
119+
}
120+
121+
// SQLValue implements the ValueType interface.
122+
func (t PolygonType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
123+
if v.IsNull() {
124+
return sqltypes.NULL, nil
125+
}
126+
if v.Val == nil {
127+
var err error
128+
v.Val, err = v.WrappedVal.Unwrap(ctx)
129+
if err != nil {
130+
return sqltypes.Value{}, err
131+
}
132+
}
133+
return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil
134+
}
135+
116136
// String implements Type interface.
117137
func (t PolygonType) String() string {
118138
return "polygon"

0 commit comments

Comments
 (0)