gxdriver

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

2016-09-11 19:30 Package gxdriver provides a MySQL driver for Go's database/sql package code example: https://github.com/alexstocks/go-practice/blob/master/mysql/stmt.go

Index

Constants

View Source
const (
	GettyMySQLDriver = "getty_mysql_driver"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MySQL

type MySQL struct {
	*sql.DB //数据库操作

	sync.Once
	// contains filtered or unexported fields
}

feature list: 1 读写分离 2 长连接有效性检测和自动重连 3 mysql prepared statement 重用 ! Note: 在执行sql操作之前请执行CheckSQl & CheckAcitve

func Open

func Open(schema string) *MySQL

创建一个默认的mysql操作实例

func OpenQuery

func OpenQuery(schema string) *MySQL

创建一个默认的mysql查询实例

func (*MySQL) Begin

func (m *MySQL) Begin() error

开始一个事务,开始一个事务和提交、回滚事务必须一一对应

func (*MySQL) CheckActive

func (m *MySQL) CheckActive()

检查MySQL实例的连接是否还在活跃时间范围内 ! note: 这个函数的实际意义在于更新active时间,实际的sql.DB下面有一个连接池, 完全没必要因为超时就更换conn对象。

func (*MySQL) CheckSQL

func (m *MySQL) CheckSQL(sql string) error

保证修改、写入类的操作不在slave上执行

func (*MySQL) Close

func (m *MySQL) Close()

func (*MySQL) Commit

func (m *MySQL) Commit() error

提交一个事务

func (*MySQL) FetchRows

func (m *MySQL) FetchRows(rows *sql.Rows) ([]map[string]string, error)

根据db.Query的查询结果,组装成一个关联key的数据集,数据类型[]map[string]string

func (*MySQL) Rollback

func (m *MySQL) Rollback() error

事务回滚

type MySQLDriver

type MySQLDriver struct {
}

func (MySQLDriver) Open

func (d MySQLDriver) Open(dsn string) (driver.Conn, error)

Jump to

Keyboard shortcuts

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