mongox

package module
v0.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

GitHub Repo stars GitHub issues GitHub License GitHub release (with filter) Go Report Card go.dev reference All Contributors

English | 中文简体

go-mongox

go-mongox is a generics-based library that extends the official MongoDB framework. Utilizing generic programming, it facilitates the binding of structs to MongoDB collections, aiming to provide type safety and streamlined data operations. go-mongox introduces chainable calls for smoother document handling and offers a rich set of bson builders and built-in functions to simplify the construction of bson data. Moreover, it supports plugin-based programming and incorporates various hooks, offering flexibility for custom logic before and after database operations, thus enhancing the application's extensibility and maintainability.

Feature Highlights

  • Generic MongoDB Collection
  • Support for constructing bson data
  • CRUD operations on documents
  • Aggregation operations
  • Built-in basic Model structure for automated updates of default field fields
  • Struct tag validation
  • Hooks
  • Plugin programming support

Install

go get github.com/chenmingyong0423/go-mongox

Getting Started

Contributing

With your participation, go-mongox will become even more powerful!

Contributors

Thank you for contributing to the go-mongox framework!

License

© Mingyong Chen,2024-now

This project is licensed under the Apache License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterPlugin added in v0.14.0

func RegisterPlugin(name string, cb callback.CbFn, opType operation.OpType)

func RemovePlugin added in v0.14.0

func RemovePlugin(name string, opType operation.OpType)

Types

type Collection

type Collection[T any] struct {
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection[T any](collection *mongo.Collection) *Collection[T]

func (*Collection[T]) Aggregator added in v0.0.3

func (c *Collection[T]) Aggregator() *aggregator.Aggregator[T]

func (*Collection[T]) Collection added in v0.1.0

func (c *Collection[T]) Collection() *mongo.Collection

func (*Collection[T]) Creator

func (c *Collection[T]) Creator() *creator.Creator[T]

func (*Collection[T]) Deleter

func (c *Collection[T]) Deleter() *deleter.Deleter[T]

func (*Collection[T]) Finder

func (c *Collection[T]) Finder() *finder.Finder[T]

func (*Collection[T]) Updater

func (c *Collection[T]) Updater() *updater.Updater[T]

type Model added in v0.11.0

type Model struct {
	ID        primitive.ObjectID `bson:"_id"`
	CreatedAt time.Time          `bson:"created_at"`
	UpdatedAt time.Time          `bson:"updated_at"`
}

Model is a base struct which includes the following fields: - ID: the primary key of the document - CreatedAt: the time when the document was created - UpdatedAt: the time when the document was last updated It may be embedded into a struct to provide these fields. Example:

type User struct {
	mongox.Model
}

func (*Model) DefaultCreatedAt added in v0.11.0

func (m *Model) DefaultCreatedAt()

func (*Model) DefaultId added in v0.13.0

func (m *Model) DefaultId()

func (*Model) DefaultUpdatedAt added in v0.11.0

func (m *Model) DefaultUpdatedAt()

Directories

Path Synopsis
builder
Code generated by MockGen.
Code generated by MockGen.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL