db

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 21 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInitResource = errors.New("ezorm/db: failed to initial mongo resource")
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 MysqlInitByField

func MysqlInitByField(cfg *MysqlFieldConfig)

func MysqlQuery

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

func MysqlQueryContext

func MysqlQueryContext(ctx context.Context, 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 SetupIdleSessionRefresher

func SetupIdleSessionRefresher(config *MongoConfig, instances []*mgo.Session, every time.Duration)

SetupIdleSessionRefresher will always refresh idle sessions if it is possible

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 ContextQueryer

type ContextQueryer func(ctx context.Context, query string, args ...interface{}) (interface{}, error)

func SQLServerTracerWrapper

func SQLServerTracerWrapper(ctx context.Context, queryer ContextQueryer, query string, args ...interface{}) ContextQueryer

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
	MaxSession 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 MysqlFieldConfig

type MysqlFieldConfig struct {
	Addr     string
	UserName string
	Password string
	Database string

	PoolSize        int
	ConnMaxLifeTime time.Duration

	Options map[string]string
}

MysqlFieldConfig uses fields to config mysql, it can be converted to DSN style.

func (*MysqlFieldConfig) Convert

func (cfg *MysqlFieldConfig) Convert() *MysqlConfig

type QueryContextWrapper

type QueryContextWrapper func(ctx context.Context, queryer ContextQueryer, query string, args ...interface{}) ContextQueryer

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) AddQueryContextWrapper

func (s *SqlServer) AddQueryContextWrapper(wrapper QueryContextWrapper)

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) ExecContext

func (s *SqlServer) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*SqlServer) GetContextWrappers

func (s *SqlServer) GetContextWrappers() []QueryContextWrapper

func (*SqlServer) GetWrappers

func (s *SqlServer) GetWrappers() []QueryWrapper

func (*SqlServer) Query

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

func (*SqlServer) QueryContext

func (s *SqlServer) QueryContext(ctx context.Context, 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