morm

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 13 Imported by: 0

README

morm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetObjectID

func GetObjectID(id interface{}) (primitive.ObjectID, error)

Types

type Collection

type Collection interface {
	GetC() string
}

type CommonDoc

type CommonDoc struct {
	Records []*Record
}

func (*CommonDoc) AddRecord

func (c *CommonDoc) AddRecord(u LogUser, msg string) []*Record

func (*CommonDoc) GetC

func (u *CommonDoc) GetC() string

func (*CommonDoc) SetCreator

func (c *CommonDoc) SetCreator(lu LogUser)

type DocInter

type DocInter interface {
	Collection
	GetDoc() interface{}
	GetID() interface{}
	SetCreator(u LogUser)
	AddRecord(u LogUser, msg string) []*Record
	GetIndexes() []mongo.IndexModel
}

type ListDoc

type ListDoc interface {
	GetID() string
	GetC() string
	GetList(slice interface{}) []ListDoc
	BeforeSave() error
}

type LogUser

type LogUser interface {
	GetName() string
	GetAccount() string
}

type MgoAggregate

type MgoAggregate interface {
	GetPipeline(q bson.M) mongo.Pipeline
	Collection
}

type MgoDBModel

type MgoDBModel interface {
	DisableCheckBeforeSave(b bool)
	SetDB(db *mongo.Database)
	BatchUpdate(doclist []DocInter, getField func(d DocInter) bson.D, u LogUser) (failed []DocInter, err error)
	BatchSave(doclist []DocInter, u LogUser) (inserted []interface{}, failed []DocInter, err error)
	Save(d DocInter, u LogUser) (interface{}, error)
	RemoveAll(d DocInter, q primitive.M, u LogUser) (int64, error)
	RemoveByID(d DocInter, u LogUser) (int64, error)
	UpdateOne(d DocInter, fields bson.D, u LogUser) (int64, error)
	UpdateAll(d DocInter, q bson.M, fields bson.D, u LogUser) (int64, error)
	UnsetFields(d DocInter, q bson.M, fields []string, u LogUser) (int64, error)
	Upsert(d DocInter, u LogUser) (interface{}, error)
	FindByID(d DocInter) error
	FindOne(d DocInter, q bson.M, option ...*options.FindOneOptions) error
	Find(d DocInter, q bson.M, option ...*options.FindOptions) (interface{}, error)
	FindAndExec(
		d DocInter, q bson.M,
		exec func(i interface{}) error,
		opts ...*options.FindOptions,
	) error
	PipeFindOne(aggr MgoAggregate, filter bson.M) error
	PipeFind(aggr MgoAggregate, filter bson.M, opts ...*options.AggregateOptions) (interface{}, error)
	PipeFindAndExec(
		aggr MgoAggregate, q bson.M,
		exec func(i interface{}) error,
		opts ...*options.AggregateOptions,
	) error
	PagePipeFind(aggr MgoAggregate, filter bson.M, sort bson.M, limit, page int64) (interface{}, error)
	PageFind(d DocInter, q bson.M, limit, page int64, opts ...*options.FindOptions) (interface{}, error)

	CountDocuments(d Collection, q bson.M) (int64, error)
	GetPaginationSource(d DocInter, q bson.M, opts ...*options.FindOptions) format.PaginationSource
	GetPipePaginationSource(aggr MgoAggregate, q bson.M, sort bson.M) format.PaginationSource

	CreateCollection(dlist ...DocInter) error
	//Reference to customer code, use for aggregate pagination
	CountAggrDocuments(aggr MgoAggregate, q bson.M) (int64, error)
	GetPipeMatchPaginationSource(aggr MgoAggregate, q bson.M, sort bson.M) format.PaginationSource

	NewFindMgoDS(d DocInter, q bson.M, opts ...*options.FindOptions) MgoDS
	NewPipeFindMgoDS(d MgoAggregate, q bson.M, opts ...*options.AggregateOptions) MgoDS
}

func NewMgoModel

func NewMgoModel(ctx context.Context, db *mongo.Database) MgoDBModel

func NewMgoModelByReq

func NewMgoModelByReq(req *http.Request) MgoDBModel

type MgoDS

type MgoDS interface {
	Exec(exec func(i interface{}) error) error
	ExportCSV(w io.Writer, title []string, exec func(writer *csv.Writer, i interface{}) error) error
}

type Record

type Record struct {
	Datetime time.Time
	Summary  string
	Account  string
	Name     string
}

func NewRecord

func NewRecord(date time.Time, acc, name, msg string) *Record

Directories

Path Synopsis
_example

Jump to

Keyboard shortcuts

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