mongo

package
v1.2.10-beta8 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MongoDB

func MongoDB() *mongo.Database

MongoDB single db

Types

type Crud

type Crud interface {
	// Init crud
	Init(*Params)
	// DB db
	DB() *mongo.Database
	// Params new/replace param
	// return param
	Params(...Param) Crud

	// FindSearch get url params
	// like form data
	FindSearch(tmap.TMap[string, any]) Crud // search single table
	Find(cmap.CMap) Crud                    // get data no search
	FindID(any) Crud                        // by id

	// Delete delete by id/ids
	Delete(any) Crud // delete

	// Update crud and search id
	// json data
	Update() Crud     // update
	Create() Crud     // create, include res insert id
	CreateMore() Crud // create more, data must array type, single table

	Error() error        // crud error
	RowsAffected() int64 // inflect rows
	Pager() result.Pager // search pager
}

Crud mongo

func NewCrud

func NewCrud(params ...Param) (crud Crud)

NewCrud new crud

type Mongo

type Mongo struct {
	// contains filtered or unexported fields
}

Mongo implement Crud

func (*Mongo) Create

func (m *Mongo) Create() Crud

func (*Mongo) CreateMore

func (m *Mongo) CreateMore() Crud

func (*Mongo) CursorScan

func (m *Mongo) CursorScan(cur *mongo.Cursor, data any)

CursorScan scan data to mongo data

func (*Mongo) DB

func (m *Mongo) DB() *mongo.Database

func (*Mongo) Delete

func (m *Mongo) Delete(id any) Crud

func (*Mongo) Error

func (m *Mongo) Error() error

func (*Mongo) Find

func (m *Mongo) Find(params cmap.CMap) Crud

func (*Mongo) FindID

func (m *Mongo) FindID(id any) Crud

FindID must be mongodb primitive.ObjectID by id

func (*Mongo) FindSearch

func (m *Mongo) FindSearch(params tmap.TMap[string, any]) Crud

FindSearch pager info

func (*Mongo) GetByDataSearch

func (m *Mongo) GetByDataSearch(params tmap.TMap[string, any]) (cur *mongo.Cursor, err error)

func (*Mongo) Init

func (m *Mongo) Init(param *Params)

func (*Mongo) Pager

func (m *Mongo) Pager() result.Pager

func (*Mongo) Params

func (m *Mongo) Params(params ...Param) Crud

func (*Mongo) RowsAffected

func (m *Mongo) RowsAffected() int64

func (*Mongo) Update

func (m *Mongo) Update() Crud

Update must id string

type Param

type Param func(*Params)

func Data

func Data(Data any) Param

func KeyModel

func KeyModel(KeyModel any) Param

func Model

func Model(Model any) Param

func Table

func Table(Table string) Param

type Params

type Params struct {
	// attributes
	InnerTable []string // inner join tables
	LeftTable  []string // left join tables
	Table      string   // table name
	Model      any      // table model, like User{}
	KeyModel   any      // key like model
	Data       any      // table model data, like var user User{}, it is 'user', it store real data
}

Params crud params

Jump to

Keyboard shortcuts

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