-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
registry.go
59 lines (55 loc) · 3.25 KB
/
registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package mysql
import (
"database/sql"
"encoding/json"
"reflect"
"time"
"cloud.google.com/go/civil"
"github.com/google/uuid"
"github.com/paulmach/orb"
"github.com/si3nloong/sqlike/v2/db"
"github.com/si3nloong/sqlike/v2/internal/spatial"
"github.com/si3nloong/sqlike/v2/sql/codec"
"golang.org/x/text/currency"
"golang.org/x/text/language"
)
func buildDefaultRegistry() db.Codecer {
rg := codec.NewRegistry()
dec := DefaultDecoders{rg}
enc := DefaultEncoders{rg}
rg.RegisterTypeCodec(reflect.TypeOf(uuid.UUID{}), enc.EncodeUUID, dec.DecodeUUID)
rg.RegisterTypeCodec(reflect.TypeOf([]byte{}), enc.EncodeByte, dec.DecodeByte)
rg.RegisterTypeCodec(reflect.TypeOf(language.Tag{}), enc.EncodeStringer, dec.DecodeLanguage)
rg.RegisterTypeCodec(reflect.TypeOf(currency.Unit{}), enc.EncodeStringer, dec.DecodeCurrency)
rg.RegisterTypeCodec(reflect.TypeOf(civil.Time{}), enc.EncodeStringer, dec.DecodeTime)
rg.RegisterTypeCodec(reflect.TypeOf(civil.Date{}), enc.EncodeStringer, dec.DecodeDate)
rg.RegisterTypeCodec(reflect.TypeOf(time.Time{}), enc.EncodeDateTime, dec.DecodeDateTime)
rg.RegisterTypeCodec(reflect.TypeOf(sql.RawBytes{}), enc.EncodeRawBytes, dec.DecodeRawBytes)
rg.RegisterTypeCodec(reflect.TypeOf(json.RawMessage{}), enc.EncodeJsonRaw, dec.DecodeJsonRaw)
rg.RegisterTypeCodec(reflect.TypeOf(orb.Point{}), enc.EncodeSpatial(spatial.Point), dec.DecodePoint)
rg.RegisterTypeCodec(reflect.TypeOf(orb.LineString{}), enc.EncodeSpatial(spatial.LineString), dec.DecodeLineString)
// rg.RegisterTypeCodec(reflect.TypeOf(orb.Polygon{}), enc.EncodeSpatial2(spatial.Polygon), dec.DecodePolygon)
// rg.RegisterTypeCodec(reflect.TypeOf(orb.MultiPoint{}), enc.EncodeSpatial(spatial.MultiPoint), dec.DecodeMultiPoint)
// rg.RegisterTypeCodec(reflect.TypeOf(orb.MultiLineString{}), enc.EncodeSpatial(spatial.MultiLineString), dec.DecodeMultiLineString)
// rg.RegisterTypeCodec(reflect.TypeOf(orb.MultiPolygon{}), enc.EncodeSpatial(spatial.MultiPolygon), dec.DecodeMultiPolygon)
rg.RegisterKindCodec(reflect.String, enc.EncodeString, dec.DecodeString)
rg.RegisterKindCodec(reflect.Bool, enc.EncodeBool, dec.DecodeBool)
rg.RegisterKindCodec(reflect.Int, enc.EncodeInt, dec.DecodeInt)
rg.RegisterKindCodec(reflect.Int8, enc.EncodeInt, dec.DecodeInt)
rg.RegisterKindCodec(reflect.Int16, enc.EncodeInt, dec.DecodeInt)
rg.RegisterKindCodec(reflect.Int32, enc.EncodeInt, dec.DecodeInt)
rg.RegisterKindCodec(reflect.Int64, enc.EncodeInt, dec.DecodeInt)
rg.RegisterKindCodec(reflect.Uint, enc.EncodeUint, dec.DecodeUint)
rg.RegisterKindCodec(reflect.Uint8, enc.EncodeUint, dec.DecodeUint)
rg.RegisterKindCodec(reflect.Uint16, enc.EncodeUint, dec.DecodeUint)
rg.RegisterKindCodec(reflect.Uint32, enc.EncodeUint, dec.DecodeUint)
rg.RegisterKindCodec(reflect.Uint64, enc.EncodeUint, dec.DecodeUint)
rg.RegisterKindCodec(reflect.Float32, enc.EncodeFloat, dec.DecodeFloat)
rg.RegisterKindCodec(reflect.Float64, enc.EncodeFloat, dec.DecodeFloat)
rg.RegisterKindCodec(reflect.Ptr, enc.EncodePtr, dec.DecodePtr)
rg.RegisterKindCodec(reflect.Struct, enc.EncodeStruct, dec.DecodeStruct)
rg.RegisterKindCodec(reflect.Array, enc.EncodeArray, dec.DecodeArray)
rg.RegisterKindCodec(reflect.Slice, enc.EncodeArray, dec.DecodeArray)
rg.RegisterKindCodec(reflect.Map, enc.EncodeMap, dec.DecodeMap)
return rg
}