mongo

package
v1.30.36 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 18 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 added in v1.30.0

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

	// GetBySearch get url params
	// like form data
	GetBySearch(params bmap.BMap) Crud // search single table
	Get(params cmap.CMap) Crud         // get data no search
	GetByID(id interface{}) Crud       // by id

	// Delete delete by id/ids
	Delete(id interface{}) 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 interface{})

CursorScan scan data to mongo data

func (*Mongo) DB added in v1.30.0

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

func (*Mongo) Delete

func (m *Mongo) Delete(id interface{}) Crud

func (*Mongo) Error

func (m *Mongo) Error() error

func (*Mongo) Get added in v1.30.0

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

func (*Mongo) GetByDataSearch

func (m *Mongo) GetByDataSearch(params bmap.BMap) (cur *mongo.Cursor, err error)

func (*Mongo) GetByID

func (m *Mongo) GetByID(id interface{}) Crud

GetByID must be mongodb primitive.ObjectID by id

func (*Mongo) GetBySearch

func (m *Mongo) GetBySearch(params bmap.BMap) Crud

GetBySearch pager info

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 interface{}) Param

func KeyModel

func KeyModel(KeyModel interface{}) Param

func Model

func Model(Model interface{}) 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      interface{} // table model, like User{}
	KeyModel   interface{} // key like model
	Data       interface{} // table model data, like var user User{}, it is 'user', it store real data

	// count
	SubSQL string // SubQuery SQL
	// where
	WhereSQL string // SubWhere SQL
}

Params crud params

Jump to

Keyboard shortcuts

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