mongo

package
v1.30.7 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2021 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

single db

Types

type Crud added in v1.30.0

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

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

	// delete by id/ids
	Delete(id interface{}) Crud // delete

	// 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

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

Crud

func NewCrud

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

new crud

type Mongo

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

implement Crud

func (*Mongo) Create

func (m *Mongo) Create() Crud

create

func (*Mongo) CreateMore

func (m *Mongo) CreateMore() Crud

create more

func (*Mongo) CursorScan

func (m *Mongo) CursorScan(cur *mongo.Cursor, data interface{})

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

delete

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 cmap.CMap) (cur *mongo.Cursor, err error)

func (*Mongo) GetByID

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

must be mongodb primitive.ObjectID by id

func (*Mongo) GetBySearch

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

search 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
}

crud params

Jump to

Keyboard shortcuts

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