This commit is contained in:
2023-06-10 16:22:14 +02:00
parent d017530444
commit b613b122e3
8 changed files with 103 additions and 48 deletions

View File

@@ -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()
}