Documentation
¶
Index ¶
- Constants
- Variables
- func CursorToBase64(c Cursor) string
- func NewFxMongoRepo[T Entity](collectionName, shortName string, indexFields []IndexField) fx.Option
- func NewMongoClientFx[T MongoConfig]() fx.Option
- func NewMongoDatabase(ctx context.Context, uri string, dbName string) (db *mongo.Database, e error)
- type BaseEntity
- func (c *BaseEntity) GetCreationTime() time.Time
- func (c *BaseEntity) GetId() ID
- func (c *BaseEntity) GetPrimitiveID() ID
- func (c *BaseEntity) GetRecordVersion() int
- func (c *BaseEntity) GetUpdateTime() time.Time
- func (c *BaseEntity) IncrementRecordVersion()
- func (c *BaseEntity) IsEntity()
- func (c *BaseEntity) IsMarkedForDeletion() bool
- func (c *BaseEntity) IsZero() bool
- func (c *BaseEntity) SetCreationTime(ct time.Time)
- func (c *BaseEntity) SetId(id ID)
- func (c *BaseEntity) SetUpdateTime(ut time.Time)
- type Cursor
- type CursorPagination
- type CursorSortBy
- type DbRepo
- type Document
- type Entity
- type Filter
- type GroupByAndCountOptions
- type ID
- type IndexField
- type IndexKey
- type MatchFilter
- type MatchType
- type MongoConfig
- type MongoRepoOptions
- type Opts
- type PageInfo
- type PaginatedRecord
- type Query
- type RecordEdge
- type SortDirection
- type SortOpts
- type UpdateOpts
Constants ¶
View Source
const ( IndexAsc indexOrder = true IndexDesc indexOrder = false )
Variables ¶
View Source
var DefaultCursorPagination = CursorPagination{ First: functions.New(int64(10)), After: nil, OrderBy: "_id", SortDirection: SortDirectionAsc, }
View Source
var ErrNoDocuments error = fmt.Errorf("no documents found")
View Source
var ErrRecordMismatch = fmt.Errorf("update with version check failed, last updated time mismatch")
Functions ¶
func CursorToBase64 ¶
func NewFxMongoRepo ¶
func NewFxMongoRepo[T Entity](collectionName, shortName string, indexFields []IndexField) fx.Option
func NewMongoClientFx ¶
func NewMongoClientFx[T MongoConfig]() fx.Option
Types ¶
type BaseEntity ¶
type BaseEntity struct { PrimitiveId ID `json:"_id,omitempty" graphql:"ignore" struct-json-path:",ignore"` Id ID `json:"id" graphql:"scalar-type=ID"` CreationTime time.Time `json:"creationTime"` UpdateTime time.Time `json:"updateTime"` RecordVersion int `json:"recordVersion"` MarkedForDeletion *bool `json:"markedForDeletion,omitempty"` }
func (*BaseEntity) GetCreationTime ¶
func (c *BaseEntity) GetCreationTime() time.Time
func (*BaseEntity) GetId ¶
func (c *BaseEntity) GetId() ID
func (*BaseEntity) GetPrimitiveID ¶
func (c *BaseEntity) GetPrimitiveID() ID
func (*BaseEntity) GetRecordVersion ¶
func (c *BaseEntity) GetRecordVersion() int
func (*BaseEntity) GetUpdateTime ¶
func (c *BaseEntity) GetUpdateTime() time.Time
func (*BaseEntity) IncrementRecordVersion ¶
func (c *BaseEntity) IncrementRecordVersion()
func (*BaseEntity) IsEntity ¶
func (c *BaseEntity) IsEntity()
added because gqlgen needs it when using @key directives read more [here](https://github.com/99designs/gqlgen/blob/ee526b05f28b0e7d5a8e7b1da28da3e03c826df9/plugin/federation/fedruntime/runtime.go#L12)
func (*BaseEntity) IsMarkedForDeletion ¶
func (c *BaseEntity) IsMarkedForDeletion() bool
func (*BaseEntity) IsZero ¶
func (c *BaseEntity) IsZero() bool
func (*BaseEntity) SetCreationTime ¶
func (c *BaseEntity) SetCreationTime(ct time.Time)
func (*BaseEntity) SetId ¶
func (c *BaseEntity) SetId(id ID)
func (*BaseEntity) SetUpdateTime ¶
func (c *BaseEntity) SetUpdateTime(ut time.Time)
type CursorPagination ¶
type CursorPagination struct { First *int64 `json:"first"` After *string `json:"after,omitempty"` Last *int64 `json:"last,omitempty"` Before *string `json:"before,omitempty"` OrderBy string `json:"orderBy,omitempty" graphql:"default=\"_id\""` SortDirection SortDirection `json:"sortDirection,omitempty" graphql:"enum=ASC;DESC,default=\"ASC\""` }
type CursorSortBy ¶
type CursorSortBy struct { Field string `json:"field"` Direction SortDirection `json:"sortDirection"` }
type DbRepo ¶
type DbRepo[T Entity] interface { NewId() ID Find(ctx context.Context, query Query) ([]T, error) FindOne(ctx context.Context, filter Filter) (T, error) FindPaginated(ctx context.Context, filter Filter, pagination CursorPagination) (*PaginatedRecord[T], error) FindById(ctx context.Context, id ID) (T, error) Create(ctx context.Context, data T) (T, error) CreateMany(ctx context.Context, data []T) error Exists(ctx context.Context, filter Filter) (bool, error) Count(ctx context.Context, filter Filter) (int64, error) // upsert Upsert(ctx context.Context, filter Filter, data T) (T, error) UpdateMany(ctx context.Context, filter Filter, updatedData map[string]any) error UpdateById(ctx context.Context, id ID, updatedData T, opts ...UpdateOpts) (T, error) PatchById(ctx context.Context, id ID, patch Document, opts ...UpdateOpts) (T, error) UpdateWithVersionCheck(ctx context.Context, id ID, updatedData T) (T, error) Patch(ctx context.Context, filter Filter, patch Document, opts ...UpdateOpts) (T, error) UpdateOne(ctx context.Context, filter Filter, updatedData T, opts ...UpdateOpts) (T, error) PatchOne(ctx context.Context, filter Filter, patch Document, opts ...UpdateOpts) (T, error) DeleteById(ctx context.Context, id ID) error DeleteMany(ctx context.Context, filter Filter) error IndexFields(ctx context.Context, indices []IndexField) error // Delete(ctx context.Context, query Query) ([]ID, error) DeleteOne(ctx context.Context, filter Filter) error GroupByAndCount(ctx context.Context, filter Filter, groupBy string, opts GroupByAndCountOptions) (map[string]int64, error) ErrAlreadyExists(err error) bool MergeMatchFilters(filter Filter, matchFilters ...map[string]MatchFilter) Filter }
type GroupByAndCountOptions ¶
type GroupByAndCountOptions struct { Limit int64 Sort SortDirection }
type IndexField ¶
type MatchFilter ¶
type MongoConfig ¶
type MongoRepoOptions ¶
type MongoRepoOptions struct {
IndexFields []string
}
type PaginatedRecord ¶
type PaginatedRecord[T Entity] struct { Edges []RecordEdge[T] PageInfo PageInfo TotalCount int64 }
type RecordEdge ¶
type SortDirection ¶
type SortDirection string
const ( SortDirectionAsc SortDirection = "ASC" SortDirectionDesc SortDirection = "DESC" )
func (SortDirection) Int ¶
func (s SortDirection) Int() int64
type UpdateOpts ¶
type UpdateOpts struct {
Upsert bool
}
Click to show internal directories.
Click to hide internal directories.