mysql

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

README

可参照uploader服务

import (
    "github.com/joshqu1985/fireman/pkg/mysql"
)

// 全局初始化调用一次
func init() {
    if err := mysql.Init(Conf.Mysql); err != nil {
        panic(err)
    }
}

// 使用示例
func DemoGetMysqlData(state int) ([]TmpData, error) {
    items := []TmpData{}
    handle := func(orm *gorm.DB) error {
        return orm.Where("state=?", state).Find(&items).Error
    }
    //下面的语句没有指定表名, test是库名,可以在TmpData处指定表名, 参见GORM
    return items, mysql.Master("test").Doit(handle)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*gorm.DB
}

func (*Client) Doit

func (c *Client) Doit(ctx context.Context, h func(*gorm.DB) error) error

type Config

type Config struct {
	Name   string
	Opts   string
	Master ConfigNode
	Slaves []ConfigNode
}

type ConfigNode

type ConfigNode struct {
	Host    string
	Auth    string
	MaxIdle int `toml:"max_idle"`
	MaxOpen int `toml:"max_open"`
	MaxLife int `toml:"max_life"`
}

type Pool

type Pool struct {
	Instances map[string]dbInstance
}

func NewPool

func NewPool(confs []Config) *Pool

func (*Pool) Master

func (p *Pool) Master(dbname string) *Client

func (*Pool) Slave

func (p *Pool) Slave(dbname string) *Client

Jump to

Keyboard shortcuts

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