db

package
v0.0.0-...-0150db3 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOperaBeforeInit = errors.New("please set db.SetOnFinishInit when needed operating db in init()")

Functions

func EnsureAllIndex

func EnsureAllIndex()

func GetCol

func GetCol(dbName, col string) (session *mgo.Session, collection *mgo.Collection)

func IsFinishInit

func IsFinishInit() bool

func IsMgoDup

func IsMgoDup(err error) bool

func IsMgoNotFound

func IsMgoNotFound(err error) bool

func MustNewMgoSessions

func MustNewMgoSessions(config *MongoConfig) []*mgo.Session

func MysqlExec

func MysqlExec(query string, args ...interface{}) (sql.Result, error)

func MysqlInit

func MysqlInit(cfg *MysqlConfig)

func MysqlQuery

func MysqlQuery(query string, args ...interface{}) (*sql.Rows, error)

func NewCollection

func NewCollection(session *mgo.Session, dbName, name string) *mgo.Collection

func NewObjectId

func NewObjectId() bson.ObjectId

func NewSession

func NewSession() (session *mgo.Session)

func ObjectIds

func ObjectIds(ids []string) (ret []bson.ObjectId)

func SetOnEnsureIndex

func SetOnEnsureIndex(f func())

func SetOnFinishInit

func SetOnFinishInit(f func())

func Setup

func Setup(c *MongoConfig)

func ShareSession

func ShareSession() *mgo.Session

func TimeFormat

func TimeFormat(t time.Time) string

func TimeParse

func TimeParse(s string) time.Time

func TimeParseLocalTime

func TimeParseLocalTime(s string) time.Time

func TimeToLocalTime

func TimeToLocalTime(c time.Time) string

Types

type M

type M bson.M

func In

func In(ids []string) M

func InID

func InID(ids []string) (ret M)

func (M) Update

func (m M) Update(qs ...M) M

type MongoConfig

type MongoConfig struct {
	MongoDB   string
	DBName    string
	PoolLimit int
}

type Mysql

type Mysql struct {
	*sql.DB
	// contains filtered or unexported fields
}

func GetMysql

func GetMysql() *Mysql

func NewMysql

func NewMysql(cfg *MysqlConfig) (*Mysql, error)

type MysqlConfig

type MysqlConfig struct {
	DataSource      string
	PoolSize        int
	ConnMaxLifeTime time.Duration
}

type QueryWrapper

type QueryWrapper func(queryer Queryer, query string, args ...interface{}) Queryer

type Queryer

type Queryer func(query string, args ...interface{}) (interface{}, error)

type RedisStore

type RedisStore struct {
	redis.Cmdable
}

func NewRedisStore

func NewRedisStore(host string, port int, password string, db int) (*RedisStore, error)

func (*RedisStore) StringScan

func (r *RedisStore) StringScan(str string, val interface{}) error

! functions

type SqlServer

type SqlServer struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

func GetSqlServer

func GetSqlServer(dataSourceName string) *SqlServer

func (*SqlServer) AddQueryWrapper

func (s *SqlServer) AddQueryWrapper(wrapper QueryWrapper)

func (*SqlServer) Exec

func (s *SqlServer) Exec(query string, args ...interface{}) (sql.Result, error)

func (*SqlServer) Query

func (s *SqlServer) Query(dest interface{}, query string, args ...interface{}) error

Jump to

Keyboard shortcuts

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