gorm/schema/pool.go
Jinzhu 39d84cba5f Add serializer support (#5078)
* Update context

* Update GormFieldValuer

* Add Serializer

* Add Serializer Interface

* Refactor gorm field

* Refactor setter, valuer

* Add sync.Pool

* Fix test

* Add pool manager

* Fix pool manager

* Add poolInitializer

* Add Serializer Scan support

* Add Serializer Value method

* Add serializer test

* Finish Serializer

* Fix JSONSerializer for postgres

* Fix JSONSerializer for sqlserver

* Test serializer tag

* Add unixtime serializer

* Update go.mod
2022-02-19 17:02:53 +08:00

63 lines
987 B
Go

package schema
import (
"reflect"
"sync"
"time"
)
// sync pools
var (
normalPool sync.Map
stringPool = &sync.Pool{
New: func() interface{} {
var v string
ptrV := &v
return &ptrV
},
}
intPool = &sync.Pool{
New: func() interface{} {
var v int64
ptrV := &v
return &ptrV
},
}
uintPool = &sync.Pool{
New: func() interface{} {
var v uint64
ptrV := &v
return &ptrV
},
}
floatPool = &sync.Pool{
New: func() interface{} {
var v float64
ptrV := &v
return &ptrV
},
}
boolPool = &sync.Pool{
New: func() interface{} {
var v bool
ptrV := &v
return &ptrV
},
}
timePool = &sync.Pool{
New: func() interface{} {
var v time.Time
ptrV := &v
return &ptrV
},
}
poolInitializer = func(reflectType reflect.Type) FieldNewValuePool {
v, _ := normalPool.LoadOrStore(reflectType, &sync.Pool{
New: func() interface{} {
return reflect.New(reflectType).Interface()
},
})
return v.(FieldNewValuePool)
}
)