mongodb

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToBSONM added in v0.2.1

func ConvertToBSONM(data any) (bson.M, error)

转换data TO bsonM

func GetTableName added in v0.5.9

func GetTableName(dest any) string

func Init

func Init() (types.ORM, error)

Types

type CtxKey added in v0.1.4

type CtxKey string

type Cursor added in v0.3.9

type Cursor struct {
	*mongo.Cursor
	// contains filtered or unexported fields
}

func (*Cursor) Close added in v0.3.9

func (c *Cursor) Close() error

func (*Cursor) Decode added in v0.4.8

func (c *Cursor) Decode(v any) error

func (*Cursor) Next added in v0.3.9

func (c *Cursor) Next() bool

type DBConn

type DBConn struct {
	Database      string //连接的数据库
	NearestClient *mongo.Client
	*mongo.Client
}
var ORMConn *DBConn

func (*DBConn) Model

func (m *DBConn) Model(data any) types.ORMModel

type IDModel added in v0.0.4

type IDModel struct {
	ID primitive.ObjectID `bson:"_id"`
}

type Model

type Model struct {
	Tx         *DBConn
	Data       any
	OpList     sync.Map // key:操作模式Mode value:操作值
	WhereList  bson.M
	Ctx        context.Context //上下文
	Collection string
}

func (*Model) All added in v0.3.9

func (m *Model) All(data any) error

func (*Model) Asc

func (m *Model) Asc(condition any) types.ORMModel

正序

func (*Model) BulkWrite added in v0.1.9

func (m *Model) BulkWrite(datas any, order bool) error

func (*Model) CheckOID added in v0.1.5

func (m *Model) CheckOID()

func (*Model) Count added in v0.3.9

func (m *Model) Count() int64

func (*Model) Create

func (m *Model) Create(data any) (id string, err error)

func (*Model) Cursor added in v0.3.9

func (m *Model) Cursor() (types.Cursor, error)

func (*Model) Delete

func (m *Model) Delete(data ...any) error

删除

func (*Model) Desc

func (m *Model) Desc(condition any) types.ORMModel

逆序

func (*Model) Equal added in v0.4.6

func (m *Model) Equal(key any, value ...any) types.ORMModel

func (*Model) Find

func (m *Model) Find() types.ORMQuery

查询数据

func (*Model) GetCollection

func (m *Model) GetCollection(dest any) string

获取集合

func (*Model) GetContext added in v0.0.4

func (m *Model) GetContext() context.Context

func (*Model) GetValue added in v0.1.4

func (m *Model) GetValue(key string) (any, bool)

func (*Model) Gt added in v0.4.6

func (m *Model) Gt(condition any, value ...any) types.ORMModel

func (*Model) Gte added in v0.4.6

func (m *Model) Gte(condition any, value ...any) types.ORMModel

func (*Model) Insert added in v0.4.0

func (m *Model) Insert(data any) error

func (*Model) Like added in v0.4.6

func (m *Model) Like(condition any, value ...any) types.ORMModel

func (*Model) Limit

func (m *Model) Limit(limit int) types.ORMModel

限制查询的数量

func (*Model) Lt added in v0.4.6

func (m *Model) Lt(condition any, value ...any) types.ORMModel

func (*Model) Lte added in v0.4.6

func (m *Model) Lte(condition any, value ...any) types.ORMModel

func (*Model) Not added in v0.4.6

func (m *Model) Not(condition any, value ...any) types.ORMModel

func (*Model) Offset

func (m *Model) Offset(offset int) types.ORMModel

跳过查询的数量

func (*Model) One added in v0.3.9

func (m *Model) One(data any) error

func (*Model) Or added in v0.4.6

func (m *Model) Or(condition any, value ...any) types.ORMModel

func (*Model) Page

func (m *Model) Page(page, limit int) types.ORMModel

func (*Model) Reset added in v0.5.9

func (m *Model) Reset() types.ORMModel

func (*Model) ResetFilter added in v0.5.9

func (m *Model) ResetFilter() types.ORMModel

func (*Model) Save

func (m *Model) Save(data any, value ...any) (err error)

更新或插入数据

func (*Model) Session added in v0.0.4

func (m *Model) Session(transactionFunc func(session types.Session) error) error

启动事务做函数调用

func (*Model) SetContext added in v0.0.4

func (m *Model) SetContext(ctx context.Context) types.ORMModel

func (*Model) SetValue added in v0.1.4

func (m *Model) SetValue(key string, value any) types.ORMModel

func (*Model) TableName added in v0.5.9

func (m *Model) TableName(table any) types.ORMModel

func (*Model) Update

func (m *Model) Update(data any, value ...any) error

修改

func (*Model) Upsert added in v0.4.0

func (m *Model) Upsert(data any, value ...any) error

func (*Model) Where

func (m *Model) Where(condition any, value ...any) types.ORMModel

限制条件

func (*Model) WhereGt

func (m *Model) WhereGt(condition any, value ...any) types.ORMModel

func (*Model) WhereGte added in v0.1.1

func (m *Model) WhereGte(condition any, value ...any) types.ORMModel

func (*Model) WhereIs

func (m *Model) WhereIs(key string, value any) types.ORMModel

func (*Model) WhereLike added in v0.4.4

func (m *Model) WhereLike(condition any, value ...any) types.ORMModel

func (*Model) WhereLt

func (m *Model) WhereLt(condition any, value ...any) types.ORMModel

func (*Model) WhereLte added in v0.1.1

func (m *Model) WhereLte(condition any, value ...any) types.ORMModel

func (*Model) WhereNot

func (m *Model) WhereNot(condition any, value ...any) types.ORMModel

func (*Model) WhereOr

func (m *Model) WhereOr(condition any, value ...any) types.ORMModel

type Query added in v0.5.2

type Query struct {
	Where bson.M
	// contains filtered or unexported fields
}

func (*Query) All added in v0.5.2

func (q *Query) All(data any) error

查询全部

func (*Query) Count added in v0.5.2

func (q *Query) Count() int64

func (*Query) Cursor added in v0.5.2

func (q *Query) Cursor() (types.Cursor, error)

游标

func (*Query) Delete added in v0.5.2

func (q *Query) Delete() error

删除查询结果

func (*Query) One added in v0.5.2

func (q *Query) One(data any) error

type SessionModel added in v0.3.7

type SessionModel struct {
	*Model
	// contains filtered or unexported fields
}

func (*SessionModel) Commit added in v0.3.7

func (m *SessionModel) Commit() error

func (*SessionModel) Rollback added in v0.3.7

func (m *SessionModel) Rollback() error

type Table

type Table interface {
	TableName() string
}

Jump to

Keyboard shortcuts

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