File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1+ * Added ` table/types.ToDecimal() ` converter from ` table/types.Value ` to ` table/types.Decimal `
2+
13## v3.46.1
2- * Implemented ` xcontext.With{Cancel,Timeout} ` with stack record and switched all usages from standard ` context.With{Cancel,Timeout} `
4+ * Implemented ` internal/ xcontext.With{Cancel,Timeout}` with stack record and switched all usages from standard ` context.With{Cancel,Timeout} `
35
46## v3.46.0
57* Refactored package ` log ` for support typed fields in log messages
Original file line number Diff line number Diff line change @@ -410,11 +410,31 @@ func DatetimeValueFromTime(t time.Time) datetimeValue {
410410 return datetimeValue (t .Unix ())
411411}
412412
413+ var _ DecimalValuer = (* decimalValue )(nil )
414+
413415type decimalValue struct {
414416 value [16 ]byte
415417 innerType * DecimalType
416418}
417419
420+ func (v * decimalValue ) Value () [16 ]byte {
421+ return v .value
422+ }
423+
424+ func (v * decimalValue ) Precision () uint32 {
425+ return v .innerType .Precision
426+ }
427+
428+ func (v * decimalValue ) Scale () uint32 {
429+ return v .innerType .Scale
430+ }
431+
432+ type DecimalValuer interface {
433+ Value () [16 ]byte
434+ Precision () uint32
435+ Scale () uint32
436+ }
437+
418438func (v * decimalValue ) castTo (dst interface {}) error {
419439 return xerrors .WithStackTrace (fmt .Errorf ("cannot cast '%+v' to '%T' destination" , v , dst ))
420440}
Original file line number Diff line number Diff line change @@ -18,6 +18,17 @@ func CastTo(v Value, dst interface{}) error {
1818 return value .CastTo (v , dst )
1919}
2020
21+ func ToDecimal (v Value ) (* Decimal , error ) {
22+ if valuer , isDecimalValuer := v .(value.DecimalValuer ); isDecimalValuer {
23+ return & Decimal {
24+ Bytes : valuer .Value (),
25+ Precision : valuer .Precision (),
26+ Scale : valuer .Scale (),
27+ }, nil
28+ }
29+ return nil , xerrors .WithStackTrace (fmt .Errorf ("value type '%s' is not decimal type" , v .Type ().Yql ()))
30+ }
31+
2132func TupleItems (v Value ) ([]Value , error ) {
2233 if vv , has := v .(interface {
2334 Items () []Value
You can’t perform that action at this time.
0 commit comments