Documentation ¶
Index ¶
- Variables
- func FindBy[Q, T any](ctx context.Context, params *FindByParams[Q, T]) ([]*T, error)
- func FindOneBy[Q, T any](ctx context.Context, params *FindByParams[Q, T]) (*T, error)
- func Init()
- func LogList(ctx context.Context, m *mongo.Collection, spec specification.Set)
- func LogObject(ctx context.Context, m *mongo.Collection, spec specification.Set)
- type Config
- type DataContextGetter
- type DatabaseController
- type DatabaseGenerator
- type Document
- type DocumentBase
- type FindByParams
- type Mapper
- type MongoTransactionFactory
- type Transaction
- type TransactionFactoryGetter
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDbMigerationFailed = errors.New("database migeration failed") ErrDbNotFound = errors.New("database not found") )
View Source
var DiskAggregationOption = &options.AggregateOptions{AllowDiskUse: utils.ToValue(true)}
DiskAggregationOption tells mongo to store aggregation results on disk instead of in memory. use this option when the aggregation result is large. see: https://godoc.org/go.mongodb.org/mongo-driver/mongo/options#AggregateOptions
Functions ¶
func FindOneBy ¶
func FindOneBy[Q, T any](ctx context.Context, params *FindByParams[Q, T]) (*T, error)
func LogList ¶
func LogList(ctx context.Context, m *mongo.Collection, spec specification.Set)
func LogObject ¶
func LogObject(ctx context.Context, m *mongo.Collection, spec specification.Set)
Types ¶
type Config ¶
type DataContextGetter ¶
type DataContextGetter interface { // GetDataContext is used when we want to access underlying database for crud GetDataContext() any }
type DatabaseController ¶
type DatabaseController interface { TransactionFactoryGetter DatabaseGenerator }
type DatabaseGenerator ¶
TODO: Ambiguous definition for db first strategy, func name should be changed.
type DocumentBase ¶
type DocumentBase struct { ID string `json:"_id" bson:"_id"` CreatedAt time.Time `bson:"createdAt"` UpdatedAt time.Time `bson:"updatedAt"` }
func (DocumentBase) CollectionName ¶
func (d DocumentBase) CollectionName() string
func (DocumentBase) GenerateID ¶
func (d DocumentBase) GenerateID()
func (DocumentBase) GetID ¶
func (d DocumentBase) GetID() string
func (DocumentBase) SetCreatedAt ¶
func (d DocumentBase) SetCreatedAt()
func (DocumentBase) SetID ¶
func (d DocumentBase) SetID(id string)
func (DocumentBase) SetUpdatedAt ¶
func (d DocumentBase) SetUpdatedAt()
type FindByParams ¶
type FindByParams[Q, T any] struct { Spec specification.Set Collection *mongo.Collection ToModel func(Q) *T }
type Mapper ¶
type Mapper[T, J Document] interface { MapToEntity(model J) T MapToModel(T) J MapToEntities(model []J) []T MapToModels(identity []T) []J }
func NewDefaultMapper ¶
type MongoTransactionFactory ¶
type MongoTransactionFactory interface {
New() Transaction
}
type Transaction ¶
type TransactionFactoryGetter ¶
type TransactionFactoryGetter interface {
GetTransactionFactory() (MongoTransactionFactory, error)
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.