v0.0.157
This commit is contained in:
@@ -14,6 +14,19 @@ type EntityID interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
type Decodable interface {
|
||||
Decode(v any) error
|
||||
}
|
||||
|
||||
type Cursorable interface {
|
||||
Decode(v any) error
|
||||
Err() error
|
||||
Close(ctx context.Context) error
|
||||
All(ctx context.Context, results any) error
|
||||
RemainingBatchLength() int
|
||||
Next(ctx context.Context) bool
|
||||
}
|
||||
|
||||
type fullTypeRef[TData any] struct {
|
||||
IsPointer bool
|
||||
Kind reflect.Kind
|
||||
@@ -25,8 +38,9 @@ type fullTypeRef[TData any] struct {
|
||||
}
|
||||
|
||||
type Coll[TData any] struct {
|
||||
coll *mongo.Collection
|
||||
dataTypeMap map[string]fullTypeRef[TData]
|
||||
coll *mongo.Collection
|
||||
dataTypeMap map[string]fullTypeRef[TData]
|
||||
customDecoder *func(ctx context.Context, dec Decodable) (TData, error)
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) Collection() *mongo.Collection {
|
||||
@@ -37,6 +51,11 @@ func (c *Coll[TData]) Name() string {
|
||||
return c.coll.Name()
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) WithDecodeFunc(cdf func(ctx context.Context, dec Decodable) (TData, error)) *Coll[TData] {
|
||||
c.customDecoder = langext.Ptr(cdf)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) Indexes() mongo.IndexView {
|
||||
return c.coll.Indexes()
|
||||
}
|
||||
|
Reference in New Issue
Block a user