diff --git a/sql/types/geometry.go b/sql/types/geometry.go index 8a429ce480..b9c20446c2 100644 --- a/sql/types/geometry.go +++ b/sql/types/geometry.go @@ -49,6 +49,7 @@ type GeometryValue interface { } var _ sql.Type = GeometryType{} +var _ sql.ValueType = GeometryType{} var _ sql.SpatialColumnType = GeometryType{} var _ sql.CollationCoercible = GeometryType{} @@ -486,6 +487,26 @@ func (t GeometryType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltype return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil } +// CompareValue implements the ValueType interface +func (t GeometryType) CompareValue(c *sql.Context, v sql.Value, value2 sql.Value) (int, error) { + panic("TODO: implement CompareValue for GeometryType") +} + +// SQLValue implements the ValueType interface +func (t GeometryType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) { + if v.IsNull() { + return sqltypes.NULL, nil + } + if v.Val == nil { + var err error + v.Val, err = v.WrappedVal.Unwrap(ctx) + if err != nil { + return sqltypes.Value{}, err + } + } + return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil +} + // String implements Type interface. func (t GeometryType) String() string { return "geometry" diff --git a/sql/types/json.go b/sql/types/json.go index 64ba15842c..6bbdce519b 100644 --- a/sql/types/json.go +++ b/sql/types/json.go @@ -172,6 +172,26 @@ func (t JsonType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes.Va return sqltypes.MakeTrusted(sqltypes.TypeJSON, val), nil } +// CompareValue implements the ValueType interface +func (t JsonType) CompareValue(c *sql.Context, v sql.Value, value2 sql.Value) (int, error) { + panic("TODO: implement CompareValue for JsonType") +} + +// SQLValue implements the ValueType interface +func (t JsonType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) { + if v.IsNull() { + return sqltypes.NULL, nil + } + if v.Val == nil { + var err error + v.Val, err = v.WrappedVal.Unwrap(ctx) + if err != nil { + return sqltypes.Value{}, err + } + } + return sqltypes.MakeTrusted(sqltypes.TypeJSON, v.Val), nil +} + // String implements Type interface. func (t JsonType) String() string { return "json" diff --git a/sql/types/linestring.go b/sql/types/linestring.go index 524b710ad9..091311c249 100644 --- a/sql/types/linestring.go +++ b/sql/types/linestring.go @@ -40,6 +40,7 @@ type LineString struct { } var _ sql.Type = LineStringType{} +var _ sql.ValueType = LineStringType{} var _ sql.SpatialColumnType = LineStringType{} var _ sql.CollationCoercible = LineStringType{} var _ GeometryValue = LineString{} @@ -108,6 +109,26 @@ func (t LineStringType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqlty return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil } +// CompareValue implements the ValueType interface. +func (t LineStringType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) { + panic("TODO: implement CompareValue for LineStringType") +} + +// SQLValue implements the ValueType interface. +func (t LineStringType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) { + if v.IsNull() { + return sqltypes.NULL, nil + } + if v.Val == nil { + var err error + v.Val, err = v.WrappedVal.Unwrap(ctx) + if err != nil { + return sqltypes.Value{}, err + } + } + return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil +} + // String implements Type interface. func (t LineStringType) String() string { return "linestring" diff --git a/sql/types/multilinestring.go b/sql/types/multilinestring.go index d76da96044..91f385aa3b 100644 --- a/sql/types/multilinestring.go +++ b/sql/types/multilinestring.go @@ -47,6 +47,7 @@ var ( ) var _ sql.Type = MultiLineStringType{} +var _ sql.ValueType = MultiLineStringType{} var _ sql.SpatialColumnType = MultiLineStringType{} var _ sql.CollationCoercible = MultiLineStringType{} var _ GeometryValue = MultiLineString{} @@ -111,6 +112,26 @@ func (t MultiLineStringType) SQL(ctx *sql.Context, dest []byte, v interface{}) ( return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil } +// CompareValue implements the ValueType interface. +func (t MultiLineStringType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) { + panic("TODO: implement CompareValue for MultiLineStringType") +} + +// SQLValue implements the ValueType interface. +func (t MultiLineStringType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) { + if v.IsNull() { + return sqltypes.NULL, nil + } + if v.Val == nil { + var err error + v.Val, err = v.WrappedVal.Unwrap(ctx) + if err != nil { + return sqltypes.Value{}, err + } + } + return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil +} + // String implements Type interface. func (t MultiLineStringType) String() string { return "multilinestring" diff --git a/sql/types/multipoint.go b/sql/types/multipoint.go index c0a9bfc519..cdbd4d7eef 100644 --- a/sql/types/multipoint.go +++ b/sql/types/multipoint.go @@ -41,6 +41,7 @@ type MultiPoint struct { } var _ sql.Type = MultiPointType{} +var _ sql.ValueType = MultiPointType{} var _ sql.SpatialColumnType = MultiPointType{} var _ sql.CollationCoercible = MultiPointType{} var _ GeometryValue = MultiPoint{} @@ -115,6 +116,26 @@ func (t MultiPointType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqlty return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil } +// CompareValue implements the ValueType interface. +func (t MultiPointType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) { + panic("TODO: implement CompareValue for MultiPointType") +} + +// SQLValue implements the ValueType interface. +func (t MultiPointType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) { + if v.IsNull() { + return sqltypes.NULL, nil + } + if v.Val == nil { + var err error + v.Val, err = v.WrappedVal.Unwrap(ctx) + if err != nil { + return sqltypes.Value{}, err + } + } + return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil +} + // String implements Type interface. func (t MultiPointType) String() string { return "multipoint" diff --git a/sql/types/multipolygon.go b/sql/types/multipolygon.go index b00c2ca33e..75cd293a0e 100644 --- a/sql/types/multipolygon.go +++ b/sql/types/multipolygon.go @@ -47,6 +47,7 @@ var ( ) var _ sql.Type = MultiPolygonType{} +var _ sql.ValueType = MultiPolygonType{} var _ sql.SpatialColumnType = MultiPolygonType{} var _ sql.CollationCoercible = MultiPolygonType{} var _ GeometryValue = MultiPolygon{} @@ -111,6 +112,26 @@ func (t MultiPolygonType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sql return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil } +// CompareValue implements the ValueType interface. +func (t MultiPolygonType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) { + panic("TODO: implement CompareValue for MultiPolygonType") +} + +// SQLValue implements the ValueType interface. +func (t MultiPolygonType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) { + if v.IsNull() { + return sqltypes.NULL, nil + } + if v.Val == nil { + var err error + v.Val, err = v.WrappedVal.Unwrap(ctx) + if err != nil { + return sqltypes.Value{}, err + } + } + return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil +} + // String implements Type interface. func (t MultiPolygonType) String() string { return "multipolygon" diff --git a/sql/types/point.go b/sql/types/point.go index 947b52b417..6ac1fb67b2 100644 --- a/sql/types/point.go +++ b/sql/types/point.go @@ -42,6 +42,7 @@ type Point struct { } var _ sql.Type = PointType{} +var _ sql.ValueType = PointType{} var _ sql.SpatialColumnType = PointType{} var _ sql.CollationCoercible = PointType{} var _ GeometryValue = Point{} @@ -123,6 +124,26 @@ func (t PointType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes.V return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil } +// CompareValue implements the ValueType interface. +func (t PointType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) { + panic("TODO: implement CompareValue for PointType") +} + +// SQLValue implements the ValueType interface. +func (t PointType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) { + if v.IsNull() { + return sqltypes.NULL, nil + } + if v.Val == nil { + var err error + v.Val, err = v.WrappedVal.Unwrap(ctx) + if err != nil { + return sqltypes.Value{}, err + } + } + return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil +} + // String implements Type interface. func (t PointType) String() string { return "point" diff --git a/sql/types/polygon.go b/sql/types/polygon.go index fc5311563f..f53cdb8b4c 100644 --- a/sql/types/polygon.go +++ b/sql/types/polygon.go @@ -41,6 +41,7 @@ type Polygon struct { } var _ sql.Type = PolygonType{} +var _ sql.ValueType = PolygonType{} var _ sql.SpatialColumnType = PolygonType{} var _ sql.CollationCoercible = PolygonType{} var _ GeometryValue = Polygon{} @@ -113,6 +114,26 @@ func (t PolygonType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes return sqltypes.MakeTrusted(sqltypes.Geometry, buf), nil } +// CompareValue implements the ValueType interface. +func (t PolygonType) CompareValue(c *sql.Context, value sql.Value, value2 sql.Value) (int, error) { + panic("TODO: implement CompareValue for PolygonType") +} + +// SQLValue implements the ValueType interface. +func (t PolygonType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) { + if v.IsNull() { + return sqltypes.NULL, nil + } + if v.Val == nil { + var err error + v.Val, err = v.WrappedVal.Unwrap(ctx) + if err != nil { + return sqltypes.Value{}, err + } + } + return sqltypes.MakeTrusted(sqltypes.Geometry, v.Val), nil +} + // String implements Type interface. func (t PolygonType) String() string { return "polygon"