Skip to content

Commit 5fe77ac

Browse files
author
James Cor
committed
json too
1 parent c432ed1 commit 5fe77ac

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sql/types/json.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,26 @@ func (t JsonType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes.Va
172172
return sqltypes.MakeTrusted(sqltypes.TypeJSON, val), nil
173173
}
174174

175+
// CompareValue implements the ValueType interface
176+
func (t JsonType) CompareValue(c *sql.Context, v sql.Value, value2 sql.Value) (int, error) {
177+
panic("TODO: implement CompareValue for JsonType")
178+
}
179+
180+
// SQLValue implements the ValueType interface
181+
func (t JsonType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
182+
if v.IsNull() {
183+
return sqltypes.NULL, nil
184+
}
185+
if v.Val == nil {
186+
var err error
187+
v.Val, err = v.WrappedVal.Unwrap(ctx)
188+
if err != nil {
189+
return sqltypes.Value{}, err
190+
}
191+
}
192+
return sqltypes.MakeTrusted(sqltypes.TypeJSON, v.Val), nil
193+
}
194+
175195
// String implements Type interface.
176196
func (t JsonType) String() string {
177197
return "json"

0 commit comments

Comments
 (0)