adapter

package
v0.1.140 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMongoId = "mongo"
	ErrInvalidOpt  = "mongo: invalid option "
)

mongo

View Source
const (
	DefaultMongodbId     = "mongodb"
	ErrInvalidMongoDbOpt = "mongodb: invalid option "
)

mongo

View Source
const (
	DefaultDbTimeout = 10 * time.Second
	DefaultDbId      = "db"
)

db

View Source
const (
	Reset       = "\033[0m"
	Red         = "\033[31m"
	Green       = "\033[32m"
	Yellow      = "\033[33m"
	Blue        = "\033[34m"
	Magenta     = "\033[35m"
	Cyan        = "\033[36m"
	White       = "\033[37m"
	BlueBold    = "\033[34;1m"
	MagentaBold = "\033[35;1m"
	RedBold     = "\033[31;1m"
	YellowBold  = "\033[33;1m"
)

Colors

View Source
const (
	DefaultHttpId = "http"
)

http

View Source
const (
	DefaultMaxMindId = "maxMind"
)

maxMind

View Source
const (
	DefaultMemCacheId = "memCache"
)

memCache

View Source
const (
	DefaultMemoryId = "memory"
)

memory

View Source
const (
	DefaultOrmId = "orm"
)

orm

View Source
const (
	DefaultRabbitId = "rabbitMq"
)

rabbitMq

View Source
const (
	DefaultRedisId = "redis"
)

redis

Variables

View Source
var DbClass string
View Source
var EsClass string
View Source
var HttpClass string
View Source
var MaxMindClass string
View Source
var MemCacheClass string
View Source
var MemoryClass string
View Source
var MongoClass string
View Source
var MongodbCAggregate string
View Source
var MongodbCQueryClass string
View Source
var MongodbClass string
View Source
var OrmClass string
View Source
var RabbitMqClass string
View Source
var RedisClass string

Functions

func FileWithLineNum added in v0.1.134

func FileWithLineNum() string

func NewDbPool

func NewDbPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewDbPool of db Client from pool, add context support. usage: db := this.GetObjPool(adapter.DbClass, adapter.NewDbPool).(adapter.IDb)/(*adapter.Db) It is recommended to use : db := this.GetObjBox(adapter.DbClass).(adapter.IDb)/(*adapter.Db)

func NewHttpPool

func NewHttpPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

Http of Http Client from pool, add context support. usage: http := this.GetObjPool(adapter.HttpClass, adapter.NewHttpPool).(adapter.IHttp)/(*adapter.Http) It is recommended to use : http := this.GetObjBox(adapter.HttpClass).(adapter.IHttp)/(*adapter.Http)

func NewMaxMindPool

func NewMaxMindPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewMaxMindPool of MaxMind Client from pool, add context support. usage: mmd := this.GetObjPool(adapter.MaxMindClass, adapter.NewMaxMindPool).(adapter.IMaxMind)/(*adapter.MaxMind) It is recommended to use :mmd := this.GetObjBox(adapter.MaxMindClass).(adapter.IMaxMind)/(*adapter.MaxMind)

func NewMemCachePool

func NewMemCachePool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewMemCachePool of MemCache Client from pool, add context support. usage: mc := this.GetObjPool(adapter.MemCacheClass, adapter.NewMemCachePool).(adapter.IMemCache)/(*adapter.MemCache) It is recommended to use :mc := this.GetObjBox(adapter.MemCacheClass).(adapter.IMemCache)/(*adapter.MemCache)

func NewMemoryPool

func NewMemoryPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewMemoryPool of Memory Client from object pool, add context support. usage: memory := this.GetObjPool(adapter.MemoryClass, adapter.NewMemoryPool).(adapter.IMemory)/(*adapter.Memory) It is recommended to use : memory := this.GetObjBox(adapter.MemoryClass).(adapter.IMemory)/(*adapter.Memory)

func NewMongoPool

func NewMongoPool(iObj iface.IObject, args ...interface{}) iface.IObject

NewMongoPool of Mongo Client from pool, add context support. usage: mongo := this.GetObjectPool(adapter.MongoClass, adapter.NewMongoPool,db, coll)).(adapter.IMongo)/(*adapter.Mongo) It is recommended to use : mongo := this.GetObjectBox(adapter.MongoClass,db, coll)).(adapter.IMongo)/(*adapter.Mongo)

func NewRabbitMqPool

func NewRabbitMqPool(iObj iface.IObject, dftConfig ...interface{}) iface.IObject

NewRabbitMqPool of RabbitMq Client from pool, add context support. usage: rabbitMq := this.GetObjPool(adapter.RabbitMqClass,adapter.NewRabbitMqPool).(adapter.IRabbitMq)/(*adapter.RabbitMq) It is recommended to use : rabbitMq := this.GetObjBox(adapter.RabbitMqClass).(adapter.IRabbitMq)/(*adapter.RabbitMq)

func NewRedisPool

func NewRedisPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewRedisPool of Redis Client from pool, add context support. usage: redis := this.GetObjPool(adapter.RedisClass, adapter.NewRedisPool).(*adapter.Redis) It is recommended to use : redis := this.GetObjBox(adapter.RedisClass).(*adapter.Redis)

Types

type CAggregate added in v0.1.135

type CAggregate struct {
	pgo2.Object
	qmgo.AggregateI
	// contains filtered or unexported fields
}

func (*CAggregate) All added in v0.1.135

func (c *CAggregate) All(results interface{}) error

func (*CAggregate) One added in v0.1.135

func (c *CAggregate) One(results interface{}) error

func (*CAggregate) Prepare added in v0.1.135

func (c *CAggregate) Prepare(q qmgo.AggregateI, dftCtxCancel ...context.CancelFunc)

type CQuery added in v0.1.134

type CQuery struct {
	qmgo.QueryI
	pgo2.Object
	// contains filtered or unexported fields
}

func (*CQuery) All added in v0.1.134

func (c *CQuery) All(result interface{}) error

func (*CQuery) Apply added in v0.1.134

func (c *CQuery) Apply(change qmgo.Change, result interface{}) error

func (*CQuery) Count added in v0.1.134

func (c *CQuery) Count() (n int64, err error)

func (*CQuery) Distinct added in v0.1.134

func (c *CQuery) Distinct(key string, result interface{}) error

func (*CQuery) Hint added in v0.1.134

func (c *CQuery) Hint(hint interface{}) qmgo.QueryI

func (*CQuery) Limit added in v0.1.134

func (c *CQuery) Limit(n int64) qmgo.QueryI

func (*CQuery) One added in v0.1.134

func (c *CQuery) One(result interface{}) error

func (*CQuery) Prepare added in v0.1.134

func (c *CQuery) Prepare(q qmgo.QueryI, dftCtxCancel ...context.CancelFunc)

func (*CQuery) Select added in v0.1.134

func (c *CQuery) Select(selector interface{}) qmgo.QueryI

func (*CQuery) Skip added in v0.1.134

func (c *CQuery) Skip(n int64) qmgo.QueryI

func (*CQuery) Sort added in v0.1.134

func (c *CQuery) Sort(fields ...string) qmgo.QueryI

type Db

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

func NewDb

func NewDb(componentId ...string) *Db

NewDb of db Client, add context support. usage: db := this.GetObj(adapter.NewDb()).(adapter.IDb)/(*adapter.Db)

func (*Db) Begin

func (d *Db) Begin(opts ...*sql.TxOptions) ITx

Begin start a transaction with default timeout context and optional opts, if opts is nil, default driver option will be used.

func (*Db) BeginContext

func (d *Db) BeginContext(ctx context.Context, opts *sql.TxOptions) ITx

BeginContext start a transaction with specified context and optional opts, if opts is nil, default driver option will be used.

func (*Db) Exec

func (d *Db) Exec(query string, args ...interface{}) sql.Result

Exec perform exec using a default timeout context.

func (*Db) ExecContext

func (d *Db) ExecContext(ctx context.Context, query string, args ...interface{}) sql.Result

ExecContext perform exec using a specified context.

func (*Db) GetClient

func (d *Db) GetClient() *db.Client

func (*Db) GetDb

func (d *Db) GetDb(master bool) *sql.DB

func (*Db) Master

func (d *Db) Master() bool

func (*Db) Prepare

func (d *Db) Prepare(componentId ...interface{})

GetObjPool, GetObjBox fetch is performed automatically

func (*Db) PrepareContext

func (d *Db) PrepareContext(ctx context.Context, query string) IStmt

PrepareContext creates a prepared statement for later queries or executions, the Close method must be called by caller.

func (*Db) PrepareSql added in v0.1.109

func (d *Db) PrepareSql(query string) IStmt

PrepareSql creates a prepared statement for later queries or executions, the Close method must be called by caller.

func (*Db) Query

func (d *Db) Query(query string, args ...interface{}) *sql.Rows

Query perform query using a default timeout context.

func (*Db) QueryContext

func (d *Db) QueryContext(ctx context.Context, query string, args ...interface{}) *sql.Rows

QueryContext perform query using a specified context.

func (*Db) QueryOne

func (d *Db) QueryOne(query string, args ...interface{}) IRow

QueryOne perform one row query using a default timeout context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Db) QueryOneContext

func (d *Db) QueryOneContext(ctx context.Context, query string, args ...interface{}) IRow

QueryOneContext perform one row query using a specified context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Db) SetMaster

func (d *Db) SetMaster(v bool)

type Es added in v0.1.140

type Es struct {
	pgo2.Object
	// contains filtered or unexported fields
}

Adapter of ElasticSearch Client, add context support. Adapter of Http Client, add context support. usage: http := this.GetObjBox(adapter.EsClass).(*adapter.Es)

func NewEs added in v0.1.140

func NewEs(componentId ...string) *Es

NewEs of ElasticSearch Client, add context support. usage: es := this.GetObj(adapter.NewEs()).(adapter.IEs)/(*adapter.Es)

func (*Es) Batch added in v0.1.140

func (e *Es) Batch(action, head, body string) error

批量增加命令 异步执行 action : index,create,delete, update head : {“_ index”:“test”,“_ type”:“_ doc”,“_ id”:“1”} body : {"filed1":"value1"}

func (*Es) GetClient added in v0.1.140

func (e *Es) GetClient() *es.Client

func (*Es) Prepare added in v0.1.140

func (e *Es) Prepare(componentId ...string)

func (*Es) Single added in v0.1.140

func (e *Es) Single(method, uri string, body []byte, timeout time.Duration) ([]byte, error)

method: POST GET PUT DELETE uri body timeout 超时时间

type Http

type Http struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewHttp

func NewHttp(componentId ...string) *Http

Http of Http Client, add context support. usage: http := this.GetObj(adapter.NewHttp()).(adapter.IHttp)/(*adapter.Http)

func (*Http) Do

func (h *Http) Do(req *http.Request, option ...*phttp.Option) *http.Response

Do perform a single request

func (*Http) DoMulti

func (h *Http) DoMulti(requests []*http.Request, option ...*phttp.Option) []*http.Response

DoMulti perform multi requests concurrently

func (*Http) Get

func (h *Http) Get(addr string, data interface{}, option ...*phttp.Option) *http.Response

Get perform a get request

func (*Http) GetClient

func (h *Http) GetClient() *phttp.Client

func (*Http) Post

func (h *Http) Post(addr string, data interface{}, option ...*phttp.Option) *http.Response

Post perform a post request

func (*Http) Prepare added in v0.1.131

func (h *Http) Prepare(componentId ...interface{})

GetObjPool, GetObjBox fetch is performed automatically

func (*Http) SetPanicRecover

func (h *Http) SetPanicRecover(v bool)

type IDb

type IDb interface {
	SetMaster(v bool)
	GetDb(master bool) *sql.DB
	Begin(opts ...*sql.TxOptions) ITx
	BeginContext(ctx context.Context, opts *sql.TxOptions) ITx
	QueryOne(query string, args ...interface{}) IRow
	QueryOneContext(ctx context.Context, query string, args ...interface{}) IRow
	Query(query string, args ...interface{}) *sql.Rows
	QueryContext(ctx context.Context, query string, args ...interface{}) *sql.Rows
	Exec(query string, args ...interface{}) sql.Result
	ExecContext(ctx context.Context, query string, args ...interface{}) sql.Result
	PrepareSql(query string) IStmt
	PrepareContext(ctx context.Context, query string) IStmt
}

type IEs added in v0.1.140

type IEs interface {
	GetClient() *es.Client
	Single(method, uri string, body []byte, timeout time.Duration) ([]byte, error)
	Batch(action, head, body string) error
}

type IHttp

type IHttp interface {
	SetPanicRecover(v bool)
	Get(addr string, data interface{}, option ...*phttp.Option) *http.Response
	Post(addr string, data interface{}, option ...*phttp.Option) *http.Response
	Do(req *http.Request, option ...*phttp.Option) *http.Response
	DoMulti(requests []*http.Request, option ...*phttp.Option) []*http.Response
}

type IMaxMind

type IMaxMind interface {
	GeoByIp(ip string, args ...interface{}) *maxmind.Geo
}

type IMemCache

type IMemCache interface {
	SetPanicRecover(v bool)
	Get(key string) *value.Value
	MGet(keys []string) map[string]*value.Value
	Set(key string, value interface{}, expire ...time.Duration) bool
	MSet(items map[string]interface{}, expire ...time.Duration) bool
	Add(key string, value interface{}, expire ...time.Duration) bool
	MAdd(items map[string]interface{}, expire ...time.Duration) bool
	Del(key string) bool
	MDel(keys []string) bool
	Exists(key string) bool
	Incr(key string, delta int) int
	Retrieve(cmd, key string) *memcache.Item
	MultiRetrieve(cmd string, keys []string) []*memcache.Item
	Store(cmd string, item *memcache.Item, expire ...time.Duration) bool
	MultiStore(cmd string, items []*memcache.Item, expire ...time.Duration) bool
}

type IMemory

type IMemory interface {
	SetPanicRecover(v bool)
	Get(key string) *value.Value
	MGet(keys []string) map[string]*value.Value
	Set(key string, value interface{}, expire ...time.Duration) bool
	MSet(items map[string]interface{}, expire ...time.Duration) bool
	Add(key string, value interface{}, expire ...time.Duration) bool
	MAdd(items map[string]interface{}, expire ...time.Duration) bool
	Del(key string) bool
	MDel(keys []string) bool
	Exists(key string) bool
	Incr(key string, delta int) int
}

type IMongo

type IMongo interface {
	FindOne(query interface{}, result interface{}, options ...bson.M) error
	FindAll(query interface{}, result interface{}, options ...bson.M) error
	FindAndModify(query interface{}, change mgo.Change, result interface{}, options ...bson.M) error
	FindDistinct(query interface{}, key string, result interface{}, options ...bson.M) error
	InsertOne(doc interface{}) error
	InsertAll(docs []interface{}) error
	UpdateOne(query interface{}, update interface{}) error
	UpdateAll(query interface{}, update interface{}) error
	UpdateOrInsert(query interface{}, update interface{}) error
	DeleteOne(query interface{}) error
	DeleteAll(query interface{}) error
	Count(query interface{}, options ...bson.M) (int, error)
	PipeOne(pipeline interface{}, result interface{}) error
	PipeAll(pipeline interface{}, result interface{}) error
	MapReduce(query interface{}, job *mgo.MapReduce, result interface{}, options ...bson.M) error
}

type IMongodb added in v0.1.134

type IMongodb interface {
	iface.IObject
	InsertOne(doc interface{}, opts ...opts.InsertOneOptions) (result *qmgo.InsertOneResult, err error)
	InsertOneCtx(ctx context.Context, doc interface{}, opts ...opts.InsertOneOptions) (result *qmgo.InsertOneResult, err error)
	InsertMany(docs interface{}, opts ...opts.InsertManyOptions) (result *qmgo.InsertManyResult, err error)
	InsertManyCtx(ctx context.Context, docs interface{}, opts ...opts.InsertManyOptions) (result *qmgo.InsertManyResult, err error)
	Upsert(filter interface{}, replacement interface{}, opts ...opts.UpsertOptions) (result *qmgo.UpdateResult, err error)
	UpsertCtx(ctx context.Context, filter interface{}, replacement interface{}, opts ...opts.UpsertOptions) (result *qmgo.UpdateResult, err error)
	UpsertId(id interface{}, replacement interface{}, opts ...opts.UpsertOptions) (result *qmgo.UpdateResult, err error)
	UpsertIdCtx(ctx context.Context, id interface{}, replacement interface{}, opts ...opts.UpsertOptions) (result *qmgo.UpdateResult, err error)
	UpdateOne(filter interface{}, update interface{}, opts ...opts.UpdateOptions) (err error)
	UpdateOneCtx(ctx context.Context, filter interface{}, update interface{}, opts ...opts.UpdateOptions) (err error)
	UpdateId(id interface{}, update interface{}, opts ...opts.UpdateOptions) (err error)
	UpdateIdCtx(ctx context.Context, id interface{}, update interface{}, opts ...opts.UpdateOptions) (err error)
	UpdateAll(filter interface{}, update interface{}, opts ...opts.UpdateOptions) (result *qmgo.UpdateResult, err error)
	UpdateAllCtx(ctx context.Context, filter interface{}, update interface{}, opts ...opts.UpdateOptions) (result *qmgo.UpdateResult, err error)
	ReplaceOne(filter interface{}, doc interface{}, opts ...opts.ReplaceOptions) (err error)
	ReplaceOneCtx(ctx context.Context, filter interface{}, doc interface{}, opts ...opts.ReplaceOptions) (err error)
	Remove(filter interface{}, opts ...opts.RemoveOptions) (err error)
	RemoveCtx(ctx context.Context, filter interface{}, opts ...opts.RemoveOptions) (err error)
	RemoveId(id interface{}, opts ...opts.RemoveOptions) (err error)
	RemoveIdCtx(ctx context.Context, id interface{}, opts ...opts.RemoveOptions) (err error)
	RemoveAll(filter interface{}, opts ...opts.RemoveOptions) (result *qmgo.DeleteResult, err error)
	RemoveAllCtx(ctx context.Context, filter interface{}, opts ...opts.RemoveOptions) (result *qmgo.DeleteResult, err error)
	Aggregate(pipeline interface{}) IMongodbAggregate
	AggregateCtx(ctx context.Context, pipeline interface{}) IMongodbAggregate
	EnsureIndexes(uniques []string, indexes []string) (err error)
	EnsureIndexesCtx(ctx context.Context, uniques []string, indexes []string) (err error)
	CreateIndexes(indexes []opts.IndexModel) (err error)
	CreateIndexesCtx(ctx context.Context, indexes []opts.IndexModel) (err error)
	CreateOneIndex(index opts.IndexModel) error
	CreateOneIndexCtx(ctx context.Context, index opts.IndexModel) (err error)
	DropAllIndexes() (err error)
	DropAllIndexesCtx(ctx context.Context) (err error)
	DropIndex(indexes []string) error
	DropIndexCtx(ctx context.Context, indexes []string) error
	DropCollection() error
	DropCollectionCtx(ctx context.Context) error
	CloneCollection() (*mongo.Collection, error)
	GetCollectionName() string
	Find(filter interface{}, options ...opts.FindOptions) IMongodbQuery
	FindCtx(ctx context.Context, filter interface{}, options ...opts.FindOptions) IMongodbQuery
	GetClient() *mongodb.Client
	Session() (*qmgo.Session, error)
	DoTransaction(ctx context.Context, callback func(sessCtx context.Context) (interface{}, error)) (interface{}, error)
}

type IMongodbAggregate added in v0.1.135

type IMongodbAggregate interface {
	qmgo.AggregateI
}

type IMongodbQuery added in v0.1.134

type IMongodbQuery interface {
	qmgo.QueryI
}

type IOrm added in v0.1.132

type IOrm interface {
	iface.IObject
	Assign(attrs ...interface{}) IOrm
	Attrs(attrs ...interface{}) IOrm
	Begin(opts ...*sql.TxOptions) IOrm
	Clauses(conds ...clause.Expression) IOrm
	Commit() IOrm
	Count(count *int64) IOrm
	Create(value interface{}) IOrm
	CreateInBatches(value interface{}, batchSize int) IOrm
	Debug() IOrm
	Delete(value interface{}, conds ...interface{}) IOrm
	Distinct(args ...interface{}) IOrm
	Exec(sql string, values ...interface{}) IOrm
	Find(dest interface{}, conds ...interface{}) IOrm
	FindInBatches(dest interface{}, batchSize int, fc func(pTx *gorm.DB, batch int) error) IOrm
	First(dest interface{}, conds ...interface{}) IOrm
	FirstOrCreate(dest interface{}, conds ...interface{}) IOrm
	FirstOrInit(dest interface{}, conds ...interface{}) IOrm
	Group(name string) IOrm
	Having(query interface{}, args ...interface{}) IOrm
	Joins(query string, args ...interface{}) IOrm
	Last(dest string, conds ...interface{}) IOrm
	Limit(limit int) IOrm
	Model(value interface{}) IOrm
	Not(query interface{}, args ...interface{}) IOrm
	Offset(offset int) IOrm
	Omit(columns ...string) IOrm
	Or(query interface{}, args ...interface{}) IOrm
	Order(value interface{}) IOrm
	Pluck(column string, dest interface{}) IOrm
	Preload(query string, args ...interface{}) IOrm
	Raw(sql string, values ...interface{}) IOrm
	Rollback() IOrm
	RollbackTo(name string) IOrm
	Row() *sql.Row
	Rows() (*sql.Rows, error)
	Save(value interface{}) IOrm
	SavePoint(name string) IOrm
	Scan(dest interface{}) IOrm
	Scopes(funcs ...func(*gorm.DB) *gorm.DB) IOrm
	Select(query interface{}, args ...interface{}) IOrm
	Session(config *gorm.Session) IOrm
	InstanceSet(key string, value interface{}) IOrm
	Set(key string, value interface{}) IOrm
	Table(name string, args ...interface{}) IOrm
	Take(dest interface{}, conds ...interface{}) IOrm
	Unscoped() IOrm
	Update(column string, value interface{}) IOrm
	UpdateColumn(column string, value interface{}) IOrm
	UpdateColumns(values interface{}) IOrm
	Updates(values interface{}) IOrm
	Where(query interface{}, args ...interface{}) IOrm
	WithContext(ctx context.Context) IOrm
	AddError(err error) error
	Association(column string) *gorm.Association
	AutoMigrate(dst ...interface{}) error
	SqlDB() (*sql.DB, error)
	Get(key string) (interface{}, bool)
	InstanceGet(key string) (interface{}, bool)
	ScanRows(rows *sql.Rows, dest interface{}) error
	SetupJoinTable(model interface{}, field string, joinTable interface{}) error
	Transaction(fc func(tx *gorm.DB) error, opts ...*sql.TxOptions) (err error)
	Use(plugin gorm.Plugin) (err error)
	GetError() error
	GetRowsAffected() int64
	GetStatement() *gorm.Statement
	GetConfig() *gorm.Config
}

type IRabbitMq

type IRabbitMq interface {
	SetPanicRecover(v bool)
	ExchangeDeclare(dftExchange ...*rabbitmq.ExchangeData)
	Publish(opCode string, data interface{}, dftOpUid ...string) bool
	PublishExchange(serviceName, exchangeName, exchangeType, opCode string, data interface{}, dftOpUid ...string) bool
	ChannelBox() *rabbitmq.ChannelBox
	GetConsumeChannelBox(queueName string, opCodes []string, dftExchange ...*rabbitmq.ExchangeData) *rabbitmq.ChannelBox
	Consume(queueName string, opCodes []string, limit int, autoAck, noWait, exclusive bool) <-chan amqp.Delivery
	ConsumeExchange(exchangeName, exchangeType, queueName string, opCodes []string, limit int, autoAck, noWait, exclusive bool) <-chan amqp.Delivery
	DecodeBody(d amqp.Delivery, ret interface{}) error
	DecodeHeaders(d amqp.Delivery) *rabbitmq.RabbitHeaders
}

type IRedis

type IRedis interface {
	SetPanicRecover(v bool)
	Get(key string) *value.Value
	MGet(keys []string) map[string]*value.Value
	Set(key string, value interface{}, expire ...time.Duration) bool
	MSet(items map[string]interface{}, expire ...time.Duration) bool
	Add(key string, value interface{}, expire ...time.Duration) bool
	MAdd(items map[string]interface{}, expire ...time.Duration) bool
	Del(key string) bool
	MDel(keys []string) bool
	Exists(key string) bool
	Incr(key string, delta int) int
	IncrBy(key string, delta int64) (int64, error)
	Do(cmd string, args ...interface{}) interface{}
	ExpireAt(key string, timestamp int64) bool
	Expire(key string, expire time.Duration) bool
	RPush(key string, values ...interface{}) bool
	LPush(key string, values ...interface{}) bool
	RPop(key string) *value.Value
	LPop(key string) *value.Value
	LLen(key string) int64
	HDel(key string, fields ...interface{}) int64
	HExists(key, field string) bool
	HSet(key string, fv ...interface{}) bool
	HGet(key, field string) *value.Value
	HGetAll(key string) map[string]*value.Value
	HMSet(key string, fv ...interface{}) bool
	HMGet(key string, fields ...interface{}) map[string]*value.Value
	HIncrBy(key, field string, delta int64) (int64, error)
	ZRange(key string, start, end int) []*value.Value
	ZRevRange(key string, start, end int) []*value.Value
	ZRangeWithScores(key string, start, end int) []*redis.ZV
	ZRevRangeWithScores(key string, start, end int) []*redis.ZV
	ZAdd(key string, members ...*redis.Z) int64
	ZAddOpt(key string, opts []string, members ...*redis.Z) (int64, error)
	ZCard(key string) int64
	ZRem(key string, members ...interface{}) int64
}

type IRow

type IRow interface {
	iface.IObject
	Scan(dest ...interface{}) error
}

type IStmt

type IStmt interface {
	iface.IObject
	Close()
	QueryOne(args ...interface{}) IRow
	QueryOneContext(ctx context.Context, args ...interface{}) IRow
	Query(args ...interface{}) *sql.Rows
	QueryContext(ctx context.Context, args ...interface{}) *sql.Rows
	Exec(args ...interface{}) sql.Result
	ExecContext(ctx context.Context, args ...interface{}) sql.Result
}

type ITx

type ITx interface {
	iface.IObject
	Commit() bool
	Rollback() bool
	QueryOne(query string, args ...interface{}) IRow
	QueryOneContext(ctx context.Context, query string, args ...interface{}) IRow
	Query(query string, args ...interface{}) *sql.Rows
	QueryContext(ctx context.Context, query string, args ...interface{}) *sql.Rows
	Exec(query string, args ...interface{}) sql.Result
	ExecContext(ctx context.Context, query string, args ...interface{}) sql.Result
	PrepareSql(query string) IStmt
	PrepareContext(ctx context.Context, query string) IStmt
}

type MaxMind

type MaxMind struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewMaxMind

func NewMaxMind(componentId ...string) *MaxMind

NewMaxMind of MaxMind Client, add context support. usage: mmd := this.GetObj(adapter.NewMaxMind()).(adapter.IMaxMind)/(*adapter.MaxMind)

func (*MaxMind) GeoByIp

func (m *MaxMind) GeoByIp(ip string, args ...interface{}) *maxmind.Geo

get geo info by ip, optional args: db int: preferred max mind db lang string: preferred i18n language

func (*MaxMind) GetClient

func (m *MaxMind) GetClient() *maxmind.Client

func (*MaxMind) Prepare added in v0.1.131

func (m *MaxMind) Prepare(componentId ...interface{})

GetObjPool, GetObjBox fetch is performed automatically

type MemCache

type MemCache struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewMemCache

func NewMemCache(componentId ...string) *MemCache

NewMemCache of MemCache Client, add context support. usage: mc := this.GetObj(adapter.NewMemCache()).(adapter.IMemCache)/(*adapter.MemCache)

func (*MemCache) Add

func (m *MemCache) Add(key string, value interface{}, expire ...time.Duration) bool

func (*MemCache) Del

func (m *MemCache) Del(key string) bool

func (*MemCache) Exists

func (m *MemCache) Exists(key string) bool

func (*MemCache) Get

func (m *MemCache) Get(key string) *value.Value

func (*MemCache) GetClient

func (m *MemCache) GetClient() *memcache.Client

func (*MemCache) Incr

func (m *MemCache) Incr(key string, delta int) int

func (*MemCache) MAdd

func (m *MemCache) MAdd(items map[string]interface{}, expire ...time.Duration) bool

func (*MemCache) MDel

func (m *MemCache) MDel(keys []string) bool

func (*MemCache) MGet

func (m *MemCache) MGet(keys []string) map[string]*value.Value

func (*MemCache) MSet

func (m *MemCache) MSet(items map[string]interface{}, expire ...time.Duration) bool

func (*MemCache) MultiRetrieve

func (m *MemCache) MultiRetrieve(cmd string, keys []string) []*memcache.Item

func (*MemCache) MultiStore

func (m *MemCache) MultiStore(cmd string, items []*memcache.Item, expire ...time.Duration) bool

func (*MemCache) Prepare added in v0.1.131

func (m *MemCache) Prepare(componentId ...interface{})

GetObjPool, GetObjBox fetch is performed automatically

func (*MemCache) Retrieve

func (m *MemCache) Retrieve(cmd, key string) *memcache.Item

func (*MemCache) Set

func (m *MemCache) Set(key string, value interface{}, expire ...time.Duration) bool

func (*MemCache) SetPanicRecover

func (m *MemCache) SetPanicRecover(v bool)

func (*MemCache) Store

func (m *MemCache) Store(cmd string, item *memcache.Item, expire ...time.Duration) bool

type Memory

type Memory struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory(componentId ...string) *Memory

NewMemory of Memory Client, add context support. usage: memory := this.GetObj(adapter.NewMemory()).(adapter.IMemory)/(*adapter.Memory)

func (*Memory) Add

func (m *Memory) Add(key string, value interface{}, expire ...time.Duration) bool

func (*Memory) Client

func (m *Memory) Client() *memory.Client

func (*Memory) Del

func (m *Memory) Del(key string) bool

func (*Memory) Exists

func (m *Memory) Exists(key string) bool

func (*Memory) Get

func (m *Memory) Get(key string) *value.Value

func (*Memory) Incr

func (m *Memory) Incr(key string, delta int) int

func (*Memory) MAdd

func (m *Memory) MAdd(items map[string]interface{}, expire ...time.Duration) bool

func (*Memory) MDel

func (m *Memory) MDel(keys []string) bool

func (*Memory) MGet

func (m *Memory) MGet(keys []string) map[string]*value.Value

func (*Memory) MSet

func (m *Memory) MSet(items map[string]interface{}, expire ...time.Duration) bool

func (*Memory) Prepare added in v0.1.131

func (m *Memory) Prepare(componentId ...interface{})

GetObjPool, GetObjBox fetch is performed automatically

func (*Memory) Set

func (m *Memory) Set(key string, value interface{}, expire ...time.Duration) bool

func (*Memory) SetPanicRecover

func (m *Memory) SetPanicRecover(v bool)

type Mongo

type Mongo struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewMongo

func NewMongo(db, coll string, componentId ...string) *Mongo

NewMongo of Mongo Client, add context support. usage: mongo := this.GetObj(adapter.NewMongo(db, coll)).(adapter.IMongo)/(*adapter.Mongo)

func (*Mongo) Count

func (m *Mongo) Count(query interface{}, options ...bson.M) (int, error)

Count return the count of documents match the query.

func (*Mongo) DeleteAll

func (m *Mongo) DeleteAll(query interface{}) error

DeleteAll delete all documents that match the query.

func (*Mongo) DeleteOne

func (m *Mongo) DeleteOne(query interface{}) error

DeleteOne delete one document that match the query.

func (*Mongo) FindAll

func (m *Mongo) FindAll(query interface{}, result interface{}, options ...bson.M) error

FindAll retrieve all documents that match the query, param result must be a slice(interface{}, map, bson.M or bson compatible struct) other params see FindOne()

func (*Mongo) FindAndModify

func (m *Mongo) FindAndModify(query interface{}, change mgo.Change, result interface{}, options ...bson.M) error

FindAndModify execute findAndModify command, which allows atomically update or remove one document, param change specify the change operation, eg. mgo.Change{Update:bson.M{"$inc": bson.M{"n":1}}, ReturnNew:true}, other params see FindOne()

func (*Mongo) FindDistinct

func (m *Mongo) FindDistinct(query interface{}, key string, result interface{}, options ...bson.M) error

FindDistinct retrieve distinct values for the param key, param result must be a slice, other params see FindOne()

func (*Mongo) FindOne

func (m *Mongo) FindOne(query interface{}, result interface{}, options ...bson.M) error

FindOne retrieve the first document that match the query, query can be a map or bson compatible struct, such as bson.M or properly typed map, nil query is equivalent to empty query such as bson.M{}. result is pointer to interface{}, map, bson.M or bson compatible struct, if interface{} type is provided, the output result is a bson.M. options provided optional query option listed as follows: fields: bson.M, set output fields, eg. bson.M{"_id":0, "name":1}, sort: string or []string, set sort order, eg. "key1" or []string{"key1", "-key2"}, skip: int, set skip number, eg. 100, limit: int, set result limit, eg. 1, hint: string or []string, set index hint, eg. []string{"key1", "key2"}

for example:

var v1 interface{} // type of output v1 is bson.M
m.FindOne(bson.M{"_id":"k1"}, &v1)

var v2 struct {
    Id    string `bson:"_id"`
    Name  string `bson:"name"`
    Value string `bson:"value"`
}
m.FindOne(bson.M{"_id": "k1"}, &v2)

func (*Mongo) GetClient

func (m *Mongo) GetClient() *mongo.Client

func (*Mongo) InsertAll

func (m *Mongo) InsertAll(docs []interface{}) error

InsertAll insert all documents provided by params docs into collection, for example:

docs := []interface{}{
    bson.M{"_id":1, "name":"v1"},
    bson.M{"_id":2, "name":"v2"},
}
m.InsertAll(docs)

func (*Mongo) InsertOne

func (m *Mongo) InsertOne(doc interface{}) error

InsertOne insert one document into collection, param doc can be a map, bson.M, bson compatible struct, for example:

m.InsertOne(bson.M{"field1":"value1", "field2":"value2"})

doc := struct {
    Field1 string `bson:"field1"`
    Field2 string `bson:"field2"`
} {"value1", "value2"}
m.InsertOne(doc)

func (*Mongo) MapReduce

func (m *Mongo) MapReduce(query interface{}, job *mgo.MapReduce, result interface{}, options ...bson.M) error

MapReduce execute map/reduce job that match the query. param result is a slice(interface{}, map, bson.M, bson compatible struct), param query and options see FindOne(). for example:

job := &mgo.MapReduce{
    Map: "function() { emit(this.n, 1) }",
    Reduce: "function(key, values) { return Array.sum(values) }",
}
result := []bson.M{}
m.MapReduce(query, job, &result)

func (*Mongo) PipeAll

func (m *Mongo) PipeAll(pipeline interface{}, result interface{}) error

PipeAll execute aggregation queries and get all item from result set. param result must be slice(interface{}, map, bson.M or bson compatible struct). see PipeOne().

func (*Mongo) PipeOne

func (m *Mongo) PipeOne(pipeline interface{}, result interface{}) error

PipeOne execute aggregation queries and get the first item from result set. param pipeline must be a slice, such as []bson.M, param result is a pointer to interface{}, map, bson.M or bson compatible struct. for example:

pipeline := []bson.M{
    bson.M{"$match": bson.M{"status":"A"}},
    bson.M{"$group": bson.M{"_id":"$field1", "total":"$field2"}},
}
m.PipeOne(pipeline, &result)

func (*Mongo) Prepare added in v0.1.131

func (m *Mongo) Prepare(args ...interface{})

GetObjPool, GetObjBox fetch is performed automatically

func (*Mongo) UpdateAll

func (m *Mongo) UpdateAll(query interface{}, update interface{}) error

UpdateAll update all documents that match the query, see UpdateOne()

func (*Mongo) UpdateOne

func (m *Mongo) UpdateOne(query interface{}, update interface{}) error

UpdateOne update one document that match the query, mgo.ErrNotFound is returned if a document not found, a value of *LastError is returned if other error occurred.

func (*Mongo) UpdateOrInsert

func (m *Mongo) UpdateOrInsert(query interface{}, update interface{}) error

UpdateOrInsert update a existing document that match the query, or insert a new document base on the update document if no document match, an error of *LastError is returned if error is detected.

type Mongodb added in v0.1.134

type Mongodb struct {
	pgo2.Object

	*qmgo.Collection
	// contains filtered or unexported fields
}

func NewMongodb added in v0.1.134

func NewMongodb(db, coll string, componentId ...string) *Mongodb

NewMongodb of Mongodb Client, add context support. usage: Mongodb := this.GetObj(adapter.NewMongodb(db, coll)).(adapter.IMongodb)/(*adapter.Mongodb)

func (*Mongodb) Aggregate added in v0.1.134

func (m *Mongodb) Aggregate(pipeline interface{}) IMongodbAggregate

Aggregate executes an aggregate command against the collection and returns a AggregateI to get resulting documents.

func (*Mongodb) AggregateCtx added in v0.1.134

func (m *Mongodb) AggregateCtx(ctx context.Context, pipeline interface{}) IMongodbAggregate

func (*Mongodb) CloneCollection added in v0.1.134

func (m *Mongodb) CloneCollection() (*mongo.Collection, error)

func (*Mongodb) CreateIndexes added in v0.1.134

func (m *Mongodb) CreateIndexes(indexes []opts.IndexModel) (err error)

CreateIndexes creates multiple indexes in collection If the Key in opts.IndexModel is []string{"name"}, means create index: name If the Key in opts.IndexModel is []string{"name","-age"} means create Compound indexes: name and -age

func (*Mongodb) CreateIndexesCtx added in v0.1.134

func (m *Mongodb) CreateIndexesCtx(ctx context.Context, indexes []opts.IndexModel) (err error)

func (*Mongodb) CreateOneIndex added in v0.1.134

func (m *Mongodb) CreateOneIndex(index opts.IndexModel) error

CreateOneIndex creates one index If the Key in opts.IndexModel is []string{"name"}, means create index name If the Key in opts.IndexModel is []string{"name","-age"} means create Compound index: name and -age

func (*Mongodb) CreateOneIndexCtx added in v0.1.134

func (m *Mongodb) CreateOneIndexCtx(ctx context.Context, index opts.IndexModel) (err error)

func (*Mongodb) DoTransaction added in v0.1.134

func (m *Mongodb) DoTransaction(ctx context.Context, callback func(sessCtx context.Context) (interface{}, error)) (interface{}, error)

func (*Mongodb) DropAllIndexes added in v0.1.134

func (m *Mongodb) DropAllIndexes() (err error)

DropAllIndexes drop all indexes on the collection except the index on the _id field if there is only _id field index on the collection, the function call will report an error

func (*Mongodb) DropAllIndexesCtx added in v0.1.134

func (m *Mongodb) DropAllIndexesCtx(ctx context.Context) (err error)

func (*Mongodb) DropCollection added in v0.1.134

func (m *Mongodb) DropCollection() error

DropCollection drops collection it's safe even collection is not exists

func (*Mongodb) DropCollectionCtx added in v0.1.134

func (m *Mongodb) DropCollectionCtx(ctx context.Context) error

func (*Mongodb) DropIndex added in v0.1.134

func (m *Mongodb) DropIndex(indexes []string) error

DropIndex drop indexes in collection, indexes that be dropped should be in line with inputting indexes The indexes is []string{"name"} means drop index: name The indexes is []string{"name","-age"} means drop Compound indexes: name and -age

func (*Mongodb) DropIndexCtx added in v0.1.134

func (m *Mongodb) DropIndexCtx(ctx context.Context, indexes []string) error

func (*Mongodb) EnsureIndexes added in v0.1.134

func (m *Mongodb) EnsureIndexes(uniques []string, indexes []string) (err error)

EnsureIndexes Deprecated Recommend to use CreateIndexes / CreateOneIndex for more function) EnsureIndexes creates unique and non-unique indexes in collection the combination of indexes is different from CreateIndexes: if uniques/indexes is []string{"name"}, means create index "name" if uniques/indexes is []string{"name,-age","uid"} means create Compound indexes: name and -age, then create one index: uid

func (*Mongodb) EnsureIndexesCtx added in v0.1.134

func (m *Mongodb) EnsureIndexesCtx(ctx context.Context, uniques []string, indexes []string) (err error)

func (*Mongodb) Find added in v0.1.134

func (m *Mongodb) Find(filter interface{}, options ...opts.FindOptions) IMongodbQuery

func (*Mongodb) FindCtx added in v0.1.134

func (m *Mongodb) FindCtx(ctx context.Context, filter interface{}, options ...opts.FindOptions) IMongodbQuery

func (*Mongodb) GetClient added in v0.1.134

func (m *Mongodb) GetClient() *mongodb.Client

func (*Mongodb) GetCollectionName added in v0.1.134

func (m *Mongodb) GetCollectionName() string

func (*Mongodb) InsertMany added in v0.1.134

func (m *Mongodb) InsertMany(docs interface{}, opts ...opts.InsertManyOptions) (result *qmgo.InsertManyResult, err error)

InsertMany executes an insert command to insert multiple documents into the collection. If InsertHook in opts is set, hook works on it, otherwise hook try the doc as hook Reference: https://docs.mongodb.com/manual/reference/command/insert/

func (*Mongodb) InsertManyCtx added in v0.1.134

func (m *Mongodb) InsertManyCtx(ctx context.Context, docs interface{}, opts ...opts.InsertManyOptions) (result *qmgo.InsertManyResult, err error)

func (*Mongodb) InsertOne added in v0.1.134

func (m *Mongodb) InsertOne(doc interface{}, opts ...opts.InsertOneOptions) (result *qmgo.InsertOneResult, err error)

InsertOne insert one document into the collection If InsertHook in opts is set, hook works on it, otherwise hook try the doc as hook Reference: https://docs.mongodb.com/manual/reference/command/insert/

func (*Mongodb) InsertOneCtx added in v0.1.134

func (m *Mongodb) InsertOneCtx(ctx context.Context, doc interface{}, opts ...opts.InsertOneOptions) (result *qmgo.InsertOneResult, err error)

func (*Mongodb) Prepare added in v0.1.134

func (m *Mongodb) Prepare(db, coll string, componentId ...string)

GetObjBox fetch is performed automatically

func (*Mongodb) Remove added in v0.1.134

func (m *Mongodb) Remove(filter interface{}, opts ...opts.RemoveOptions) (err error)

Remove executes a delete command to delete at most one document from the collection. if filter is bson.M{},DeleteOne will delete one document in collection Reference: https://docs.mongodb.com/manual/reference/command/delete/

func (*Mongodb) RemoveAll added in v0.1.134

func (m *Mongodb) RemoveAll(filter interface{}, opts ...opts.RemoveOptions) (result *qmgo.DeleteResult, err error)

func (*Mongodb) RemoveAllCtx added in v0.1.134

func (m *Mongodb) RemoveAllCtx(ctx context.Context, filter interface{}, opts ...opts.RemoveOptions) (result *qmgo.DeleteResult, err error)

func (*Mongodb) RemoveCtx added in v0.1.134

func (m *Mongodb) RemoveCtx(ctx context.Context, filter interface{}, opts ...opts.RemoveOptions) (err error)

func (*Mongodb) RemoveId added in v0.1.134

func (m *Mongodb) RemoveId(id interface{}, opts ...opts.RemoveOptions) (err error)

RemoveId executes a delete command to delete at most one document from the collection.

func (*Mongodb) RemoveIdCtx added in v0.1.134

func (m *Mongodb) RemoveIdCtx(ctx context.Context, id interface{}, opts ...opts.RemoveOptions) (err error)

func (*Mongodb) ReplaceOne added in v0.1.134

func (m *Mongodb) ReplaceOne(filter interface{}, doc interface{}, opts ...opts.ReplaceOptions) (err error)

ReplaceOne executes an update command to update at most one document in the collection. If UpdateHook in opts is set, hook works on it, otherwise hook try the doc as hook Expect type of the doc is the define of user's document

func (*Mongodb) ReplaceOneCtx added in v0.1.134

func (m *Mongodb) ReplaceOneCtx(ctx context.Context, filter interface{}, doc interface{}, opts ...opts.ReplaceOptions) (err error)

func (*Mongodb) Session added in v0.1.134

func (m *Mongodb) Session() (*qmgo.Session, error)

func (*Mongodb) UpdateAll added in v0.1.134

func (m *Mongodb) UpdateAll(filter interface{}, update interface{}, opts ...opts.UpdateOptions) (result *qmgo.UpdateResult, err error)

UpdateAll executes an update command to update documents in the collection. The matchedCount is 0 in UpdateResult if no document updated Reference: https://docs.mongodb.com/manual/reference/operator/update/

func (*Mongodb) UpdateAllCtx added in v0.1.134

func (m *Mongodb) UpdateAllCtx(ctx context.Context, filter interface{}, update interface{}, opts ...opts.UpdateOptions) (result *qmgo.UpdateResult, err error)

func (*Mongodb) UpdateId added in v0.1.134

func (m *Mongodb) UpdateId(id interface{}, update interface{}, opts ...opts.UpdateOptions) (err error)

UpdateId executes an update command to update at most one document in the collection. Reference: https://docs.mongodb.com/manual/reference/operator/update/

func (*Mongodb) UpdateIdCtx added in v0.1.134

func (m *Mongodb) UpdateIdCtx(ctx context.Context, id interface{}, update interface{}, opts ...opts.UpdateOptions) (err error)

func (*Mongodb) UpdateOne added in v0.1.134

func (m *Mongodb) UpdateOne(filter interface{}, update interface{}, opts ...opts.UpdateOptions) (err error)

UpdateOne executes an update command to update at most one document in the collection. Reference: https://docs.mongodb.com/manual/reference/operator/update/

func (*Mongodb) UpdateOneCtx added in v0.1.134

func (m *Mongodb) UpdateOneCtx(ctx context.Context, filter interface{}, update interface{}, opts ...opts.UpdateOptions) (err error)

func (*Mongodb) Upsert added in v0.1.134

func (m *Mongodb) Upsert(filter interface{}, replacement interface{}, opts ...opts.UpsertOptions) (result *qmgo.UpdateResult, err error)

Upsert updates one documents if filter match, inserts one document if filter is not match, Error when the filter is invalid The replacement parameter must be a document that will be used to replace the selected document. It cannot be nil and cannot contain any update operators Reference: https://docs.mongodb.com/manual/reference/operator/update/ If replacement has "_id" field and the document is exist, please initial it with existing id(even with Qmgo default field feature). Otherwise "the (immutable) field '_id' altered" error happens.

func (*Mongodb) UpsertCtx added in v0.1.134

func (m *Mongodb) UpsertCtx(ctx context.Context, filter interface{}, replacement interface{}, opts ...opts.UpsertOptions) (result *qmgo.UpdateResult, err error)

func (*Mongodb) UpsertId added in v0.1.134

func (m *Mongodb) UpsertId(id interface{}, replacement interface{}, opts ...opts.UpsertOptions) (result *qmgo.UpdateResult, err error)

UpsertId updates one documents if id match, inserts one document if id is not match and the id will inject into the document The replacement parameter must be a document that will be used to replace the selected document. It cannot be nil and cannot contain any update operators Reference: https://docs.mongodb.com/manual/reference/operator/update/

func (*Mongodb) UpsertIdCtx added in v0.1.134

func (m *Mongodb) UpsertIdCtx(ctx context.Context, id interface{}, replacement interface{}, opts ...opts.UpsertOptions) (result *qmgo.UpdateResult, err error)

type Orm added in v0.1.132

type Orm struct {
	pgo2.Object

	*gorm.DB
	// contains filtered or unexported fields
}

func NewOrm added in v0.1.132

func NewOrm(ctr iface.IContext, componentId ...string) *Orm

NewDb of db Client, add context support. usage: db := this.GetObj(adapter.NewOrm(ctr)).(*adapter.Orm/adapter.IOrm)

func (*Orm) Assign added in v0.1.132

func (o *Orm) Assign(attrs ...interface{}) (tx IOrm)

func (*Orm) Attrs added in v0.1.132

func (o *Orm) Attrs(attrs ...interface{}) (tx IOrm)

func (*Orm) Begin added in v0.1.132

func (o *Orm) Begin(opts ...*sql.TxOptions) (tx IOrm)

func (*Orm) Clauses added in v0.1.132

func (o *Orm) Clauses(conds ...clause.Expression) (tx IOrm)

func (*Orm) Commit added in v0.1.132

func (o *Orm) Commit() (tx IOrm)

func (*Orm) Count added in v0.1.132

func (o *Orm) Count(count *int64) (tx IOrm)

func (*Orm) Create added in v0.1.132

func (o *Orm) Create(value interface{}) (tx IOrm)

func (*Orm) CreateInBatches added in v0.1.132

func (o *Orm) CreateInBatches(value interface{}, batchSize int) (tx IOrm)

func (*Orm) Debug added in v0.1.132

func (o *Orm) Debug() (tx IOrm)

func (*Orm) Delete added in v0.1.132

func (o *Orm) Delete(value interface{}, conds ...interface{}) (tx IOrm)

func (*Orm) Distinct added in v0.1.132

func (o *Orm) Distinct(args ...interface{}) (tx IOrm)

func (*Orm) Exec added in v0.1.132

func (o *Orm) Exec(sql string, values ...interface{}) (tx IOrm)

func (*Orm) Find added in v0.1.132

func (o *Orm) Find(dest interface{}, conds ...interface{}) (tx IOrm)

func (*Orm) FindInBatches added in v0.1.132

func (o *Orm) FindInBatches(dest interface{}, batchSize int, fc func(pTx *gorm.DB, batch int) error) (tx IOrm)

func (*Orm) First added in v0.1.132

func (o *Orm) First(dest interface{}, conds ...interface{}) (tx IOrm)

func (*Orm) FirstOrCreate added in v0.1.132

func (o *Orm) FirstOrCreate(dest interface{}, conds ...interface{}) (tx IOrm)

func (*Orm) FirstOrInit added in v0.1.132

func (o *Orm) FirstOrInit(dest interface{}, conds ...interface{}) (tx IOrm)

func (*Orm) GetConfig added in v0.1.132

func (o *Orm) GetConfig() *gorm.Config

func (*Orm) GetError added in v0.1.132

func (o *Orm) GetError() error

func (*Orm) GetRowsAffected added in v0.1.132

func (o *Orm) GetRowsAffected() int64

func (*Orm) GetStatement added in v0.1.132

func (o *Orm) GetStatement() *gorm.Statement

func (*Orm) Group added in v0.1.132

func (o *Orm) Group(name string) (tx IOrm)

func (*Orm) Having added in v0.1.132

func (o *Orm) Having(query interface{}, args ...interface{}) (tx IOrm)

func (*Orm) InstanceSet added in v0.1.132

func (o *Orm) InstanceSet(key string, value interface{}) (tx IOrm)

func (*Orm) Joins added in v0.1.132

func (o *Orm) Joins(query string, args ...interface{}) (tx IOrm)

func (*Orm) Last added in v0.1.132

func (o *Orm) Last(dest string, conds ...interface{}) (tx IOrm)

func (*Orm) Limit added in v0.1.132

func (o *Orm) Limit(limit int) (tx IOrm)

func (*Orm) Model added in v0.1.132

func (o *Orm) Model(value interface{}) (tx IOrm)

func (*Orm) Not added in v0.1.132

func (o *Orm) Not(query interface{}, args ...interface{}) (tx IOrm)

func (*Orm) Offset added in v0.1.132

func (o *Orm) Offset(offset int) (tx IOrm)

func (*Orm) Omit added in v0.1.132

func (o *Orm) Omit(columns ...string) (tx IOrm)

func (*Orm) Or added in v0.1.132

func (o *Orm) Or(query interface{}, args ...interface{}) (tx IOrm)

func (*Orm) Order added in v0.1.132

func (o *Orm) Order(value interface{}) (tx IOrm)

func (*Orm) Pluck added in v0.1.132

func (o *Orm) Pluck(column string, dest interface{}) (tx IOrm)

func (*Orm) Preload added in v0.1.132

func (o *Orm) Preload(query string, args ...interface{}) (tx IOrm)

func (*Orm) Prepare added in v0.1.132

func (o *Orm) Prepare(componentId ...interface{})

NewDb of db Client, add context support. usage: db := this.GetObjBox(adapter.OrmClass).(*adapter.Orm/adapter.IOrm)

func (*Orm) Raw added in v0.1.132

func (o *Orm) Raw(sql string, values ...interface{}) (tx IOrm)

func (*Orm) Rollback added in v0.1.132

func (o *Orm) Rollback() (tx IOrm)

func (*Orm) RollbackTo added in v0.1.132

func (o *Orm) RollbackTo(name string) (tx IOrm)

func (*Orm) Row added in v0.1.132

func (o *Orm) Row() *sql.Row

func (*Orm) Rows added in v0.1.132

func (o *Orm) Rows() (*sql.Rows, error)

func (*Orm) Save added in v0.1.132

func (o *Orm) Save(value interface{}) (tx IOrm)

func (*Orm) SavePoint added in v0.1.132

func (o *Orm) SavePoint(name string) (tx IOrm)

func (*Orm) Scan added in v0.1.132

func (o *Orm) Scan(dest interface{}) (tx IOrm)

func (*Orm) Scopes added in v0.1.132

func (o *Orm) Scopes(funcs ...func(*gorm.DB) *gorm.DB) (tx IOrm)

func (*Orm) Select added in v0.1.132

func (o *Orm) Select(query interface{}, args ...interface{}) (tx IOrm)

func (*Orm) Session added in v0.1.132

func (o *Orm) Session(config *gorm.Session) (tx IOrm)

func (*Orm) Set added in v0.1.132

func (o *Orm) Set(key string, value interface{}) (tx IOrm)

func (*Orm) SqlDB added in v0.1.132

func (o *Orm) SqlDB() (*sql.DB, error)

func (*Orm) Table added in v0.1.132

func (o *Orm) Table(name string, args ...interface{}) (tx IOrm)

func (*Orm) Take added in v0.1.132

func (o *Orm) Take(dest interface{}, conds ...interface{}) (tx IOrm)

func (*Orm) Unscoped added in v0.1.132

func (o *Orm) Unscoped() (tx IOrm)

func (*Orm) Update added in v0.1.132

func (o *Orm) Update(column string, value interface{}) (tx IOrm)

func (*Orm) UpdateColumn added in v0.1.132

func (o *Orm) UpdateColumn(column string, value interface{}) (tx IOrm)

func (*Orm) UpdateColumns added in v0.1.132

func (o *Orm) UpdateColumns(values interface{}) (tx IOrm)

func (*Orm) Updates added in v0.1.132

func (o *Orm) Updates(values interface{}) (tx IOrm)

func (*Orm) Where added in v0.1.132

func (o *Orm) Where(query interface{}, args ...interface{}) (tx IOrm)

func (*Orm) WithContext added in v0.1.132

func (o *Orm) WithContext(ctx context.Context) (tx IOrm)

type RabbitMq

type RabbitMq struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewRabbitMq

func NewRabbitMq(dftConfig ...string) *RabbitMq

NewRabbitMq of RabbitMq Client, add context support. usage: rabbitMq := this.GetObj(adapter.NewRabbitMq()).(adapter.IRabbitMq)/(*adapter.RabbitMq)

func (*RabbitMq) ChannelBox added in v0.1.103

func (r *RabbitMq) ChannelBox() *rabbitmq.ChannelBox

func (*RabbitMq) Consume

func (r *RabbitMq) Consume(queueName string, opCodes []string, limit int, autoAck, noWait, exclusive bool) <-chan amqp.Delivery

消费,返回chan 可以不停取数据 queueName 队列名字 opCodes 绑定队列的code limit 每次接收多少条 autoAck 是否自动答复 如果为false 需要手动调用Delivery.ack(false) noWait 是否一直等待 exclusive 是否独占队列

func (*RabbitMq) ConsumeExchange added in v0.1.99

func (r *RabbitMq) ConsumeExchange(exchangeName, exchangeType, queueName string, opCodes []string, limit int, autoAck, noWait, exclusive bool) <-chan amqp.Delivery

消费,返回chan 可以不停取数据 exchangeName 交换机名 exchangeType 交换机type queueName 队列名字 opCodes 绑定队列的code limit 每次接收多少条 autoAck 是否自动答复 如果为false 需要手动调用Delivery.ack(false) noWait 是否一直等待 exclusive 是否独占队列

func (*RabbitMq) DecodeBody

func (r *RabbitMq) DecodeBody(d amqp.Delivery, ret interface{}) error

func (*RabbitMq) DecodeHeaders

func (r *RabbitMq) DecodeHeaders(d amqp.Delivery) *rabbitmq.RabbitHeaders

func (*RabbitMq) ExchangeDeclare

func (r *RabbitMq) ExchangeDeclare(dftExchange ...*rabbitmq.ExchangeData)

func (*RabbitMq) GetClient

func (r *RabbitMq) GetClient() *rabbitmq.Client

func (*RabbitMq) GetConsumeChannelBox

func (r *RabbitMq) GetConsumeChannelBox(queueName string, opCodes []string, dftExchange ...*rabbitmq.ExchangeData) *rabbitmq.ChannelBox

func (*RabbitMq) Prepare added in v0.1.131

func (r *RabbitMq) Prepare(dftConfig ...interface{})

GetObjPool, GetObjBox fetch is performed automatically

func (*RabbitMq) Publish

func (r *RabbitMq) Publish(opCode string, data interface{}, dftOpUid ...string) bool

func (*RabbitMq) PublishExchange added in v0.1.99

func (r *RabbitMq) PublishExchange(serviceName, exchangeName, exchangeType, opCode string, data interface{}, dftOpUid ...string) bool

func (*RabbitMq) PublishExchangeDelivery added in v0.1.118

func (r *RabbitMq) PublishExchangeDelivery(serviceName, exchangeName, exchangeType, opCode string, data interface{}, deliveryMode uint8, dftOpUid ...string) bool

func (*RabbitMq) SetPanicRecover

func (r *RabbitMq) SetPanicRecover(v bool)

type Redis

type Redis struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis(componentId ...string) *Redis

NewRedis of Redis Client, add context support. usage: redis := this.GetObject(adapter.NewRedis()).(*adapter.Redis)

func (*Redis) Add

func (r *Redis) Add(key string, value interface{}, expire ...time.Duration) bool

func (*Redis) Del

func (r *Redis) Del(key string) bool

func (*Redis) Do

func (r *Redis) Do(cmd string, args ...interface{}) interface{}

支持的命令请查阅:Redis.allRedisCmd args = [0:"key"] Example: redis := t.GetObjBox(Redis.AdapterClass).(*Redis.Adapter) retI := redis.Do("SADD","myTest", "test1" ret := retI.(int64) fmt.Println(ret) = 1 retList :=redis.Do("SMEMBERS","myTest" retListI,_:=ret.([]interface{})

for _,v:=range retListI{
   vv :=value.New(v) // 写入的时候有value.Encode(),如果存入的是结构体或slice map 需要decode,其他类型直接断言类型
   fmt.Println(vv.String()) // test1
}

func (*Redis) Exists

func (r *Redis) Exists(key string) bool

func (*Redis) Expire added in v0.1.137

func (r *Redis) Expire(key string, expire time.Duration) bool

func (*Redis) ExpireAt added in v0.1.137

func (r *Redis) ExpireAt(key string, timestamp int64) bool

func (*Redis) Get

func (r *Redis) Get(key string) *value.Value

func (*Redis) GetClient

func (r *Redis) GetClient() *redis.Client

func (*Redis) HDel added in v0.1.137

func (r *Redis) HDel(key string, fields ...interface{}) int64

func (*Redis) HExists added in v0.1.137

func (r *Redis) HExists(key, field string) bool

func (*Redis) HGet added in v0.1.137

func (r *Redis) HGet(key, field string) *value.Value

func (*Redis) HGetAll added in v0.1.137

func (r *Redis) HGetAll(key string) map[string]*value.Value

func (*Redis) HIncrBy added in v0.1.137

func (r *Redis) HIncrBy(key, field string, delta int64) (int64, error)

func (*Redis) HMGet added in v0.1.137

func (r *Redis) HMGet(key string, fields ...interface{}) map[string]*value.Value

func (*Redis) HMSet added in v0.1.137

func (r *Redis) HMSet(key string, fv ...interface{}) bool

func (*Redis) HSet added in v0.1.137

func (r *Redis) HSet(key string, fv ...interface{}) bool

func (*Redis) Incr

func (r *Redis) Incr(key string, delta int) int

func (*Redis) IncrBy added in v0.1.138

func (r *Redis) IncrBy(key string, delta int64) (int64, error)

func (*Redis) LLen added in v0.1.137

func (r *Redis) LLen(key string) int64

func (*Redis) LPop added in v0.1.137

func (r *Redis) LPop(key string) *value.Value

func (*Redis) LPush added in v0.1.137

func (r *Redis) LPush(key string, values ...interface{}) bool

func (*Redis) MAdd

func (r *Redis) MAdd(items map[string]interface{}, expire ...time.Duration) bool

func (*Redis) MDel

func (r *Redis) MDel(keys []string) bool

func (*Redis) MGet

func (r *Redis) MGet(keys []string) map[string]*value.Value

func (*Redis) MSet

func (r *Redis) MSet(items map[string]interface{}, expire ...time.Duration) bool

func (*Redis) Prepare added in v0.1.131

func (r *Redis) Prepare(componentId ...interface{})

GetObjPool, GetObjBox fetch is performed automatically

func (*Redis) RPop added in v0.1.137

func (r *Redis) RPop(key string) *value.Value

func (*Redis) RPush added in v0.1.137

func (r *Redis) RPush(key string, values ...interface{}) bool

func (*Redis) Set

func (r *Redis) Set(key string, value interface{}, expire ...time.Duration) bool

func (*Redis) SetPanicRecover

func (r *Redis) SetPanicRecover(v bool)

func (*Redis) ZAdd added in v0.1.137

func (r *Redis) ZAdd(key string, members ...*redis.Z) int64

func (*Redis) ZAddOpt added in v0.1.137

func (r *Redis) ZAddOpt(key string, opts []string, members ...*redis.Z) (int64, error)

func (*Redis) ZCard added in v0.1.137

func (r *Redis) ZCard(key string) int64

func (*Redis) ZRange added in v0.1.137

func (r *Redis) ZRange(key string, start, end int) []*value.Value

func (*Redis) ZRangeWithScores added in v0.1.137

func (r *Redis) ZRangeWithScores(key string, start, end int) []*redis.ZV

func (*Redis) ZRem added in v0.1.137

func (r *Redis) ZRem(key string, members ...interface{}) int64

func (*Redis) ZRevRange added in v0.1.137

func (r *Redis) ZRevRange(key string, start, end int) []*value.Value

func (*Redis) ZRevRangeWithScores added in v0.1.137

func (r *Redis) ZRevRangeWithScores(key string, start, end int) []*redis.ZV

type Row

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

Row wrapper for sql.Row

func (*Row) Scan

func (r *Row) Scan(dest ...interface{}) error

Scan copies the columns in the current row into the values pointed at by dest.

type Stmt

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

Stmt wrap sql.Stmt, add context support

func (*Stmt) Close

func (s *Stmt) Close()

Close close sql.Stmt and return instance to pool

func (*Stmt) Exec

func (s *Stmt) Exec(args ...interface{}) sql.Result

Exec perform exec using a default timeout context.

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) sql.Result

ExecContext perform exec using a specified context.

func (*Stmt) Query

func (s *Stmt) Query(args ...interface{}) *sql.Rows

Query perform query using a default timeout context.

func (*Stmt) QueryContext

func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) *sql.Rows

QueryContext perform query using a specified context.

func (*Stmt) QueryOne

func (s *Stmt) QueryOne(args ...interface{}) IRow

QueryOne perform one row query using a default timeout context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Stmt) QueryOneContext

func (s *Stmt) QueryOneContext(ctx context.Context, args ...interface{}) IRow

QueryOneContext perform one row query using a specified context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

type Tx

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

Tx wrapper for sql.Tx

func (*Tx) Commit

func (t *Tx) Commit() bool

Commit commit transaction that previously started.

func (*Tx) Exec

func (t *Tx) Exec(query string, args ...interface{}) sql.Result

Exec perform exec using a default timeout context.

func (*Tx) ExecContext

func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) sql.Result

ExecContext perform exec using a specified context.

func (*Tx) PrepareContext

func (t *Tx) PrepareContext(ctx context.Context, query string) IStmt

PrepareContext creates a prepared statement for later queries or executions, the Close method must be called by caller.

func (*Tx) PrepareSql added in v0.1.109

func (t *Tx) PrepareSql(query string) IStmt

PrepareSql creates a prepared statement for later queries or executions, the Close method must be called by caller.

func (*Tx) Query

func (t *Tx) Query(query string, args ...interface{}) *sql.Rows

Query perform query using a default timeout context.

func (*Tx) QueryContext

func (t *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) *sql.Rows

QueryContext perform query using a specified context.

func (*Tx) QueryOne

func (t *Tx) QueryOne(query string, args ...interface{}) IRow

QueryOne perform one row query using a default timeout context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Tx) QueryOneContext

func (t *Tx) QueryOneContext(ctx context.Context, query string, args ...interface{}) IRow

QueryOneContext perform one row query using a specified context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Tx) Rollback

func (t *Tx) Rollback() bool

Rollback roll back transaction that previously started.

Jump to

Keyboard shortcuts

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