Skip to content

Commit 70b8622

Browse files
author
James Cor
committed
implement valuetype for geomtype
1 parent 83d2fda commit 70b8622

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sql/types/geometry.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type GeometryValue interface {
4949
}
5050

5151
var _ sql.Type = GeometryType{}
52+
var _ sql.ValueType = GeometryType{}
5253
var _ sql.SpatialColumnType = GeometryType{}
5354
var _ sql.CollationCoercible = GeometryType{}
5455

@@ -486,6 +487,26 @@ func (t GeometryType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltype
486487
return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil
487488
}
488489

490+
// CompareValue implements the ValueType interface
491+
func (t GeometryType) CompareValue(c *sql.Context, v sql.Value, value2 sql.Value) (int, error) {
492+
panic("TODO: implement CompareValue for GeometryType")
493+
}
494+
495+
// SQLValue implements the ValueType interface
496+
func (t GeometryType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
497+
if v.IsNull() {
498+
return sqltypes.NULL, nil
499+
}
500+
if v.Val != nil {
501+
return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil
502+
}
503+
geomBytes, err := v.WrappedVal.Unwrap(ctx)
504+
if err != nil {
505+
return sqltypes.Value{}, err
506+
}
507+
return sqltypes.MakeTrusted(sqltypes.Geometry, geomBytes), nil
508+
}
509+
489510
// String implements Type interface.
490511
func (t GeometryType) String() string {
491512
return "geometry"

0 commit comments

Comments
 (0)