v0.0.300 add custom unmarshal-hooks to wmo
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m45s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m45s
This commit is contained in:
@@ -44,6 +44,7 @@ type Coll[TData any] struct {
|
||||
implDataTypeMap map[reflect.Type]map[string]fullTypeRef // dynamic list of fields of TData implementations (only if TData is an interface)
|
||||
customDecoder *func(ctx context.Context, dec Decodable) (TData, error) // custom decoding function (useful if TData is an interface)
|
||||
isInterfaceDataType bool // true if TData is an interface (not a struct)
|
||||
unmarshalHooks []func(d TData) TData // called for every object after unmarshalling
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) Collection() *mongo.Collection {
|
||||
@@ -54,14 +55,6 @@ func (c *Coll[TData]) Name() string {
|
||||
return c.coll.Name()
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) WithDecodeFunc(cdf func(ctx context.Context, dec Decodable) (TData, error), example TData) *Coll[TData] {
|
||||
|
||||
c.EnsureInitializedReflection(example)
|
||||
|
||||
c.customDecoder = langext.Ptr(cdf)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) Indexes() mongo.IndexView {
|
||||
return c.coll.Indexes()
|
||||
}
|
||||
@@ -74,6 +67,20 @@ func (c *Coll[TData]) Drop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) WithDecodeFunc(cdf func(ctx context.Context, dec Decodable) (TData, error), example TData) *Coll[TData] {
|
||||
|
||||
c.EnsureInitializedReflection(example)
|
||||
|
||||
c.customDecoder = langext.Ptr(cdf)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) WithUnmarshalHook(fn func(d TData) TData) *Coll[TData] {
|
||||
c.unmarshalHooks = append(c.unmarshalHooks, fn)
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) createToken(fieldPrimary string, dirPrimary ct.SortDirection, fieldSecondary *string, dirSecondary *ct.SortDirection, lastEntity TData, pageSize *int) (ct.CursorToken, error) {
|
||||
|
||||
valuePrimary, err := c.getFieldValueAsTokenString(lastEntity, fieldPrimary)
|
||||
|
Reference in New Issue
Block a user