gorm_explain

package
v0.0.0-...-a5c2be1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 9 Imported by: 0

README

gorm-explain

利用Gorm Callback在执行Select SQL之后再执行 Explain SQL ,之后将结果以不同的方式输出。现在支持控制台,csv文件,浏览器。

输出

控制台

code:

func TestExplain(t *testing.T) {
    // 初始化db
    dao := db.InitDebug(&db.MysqlConfig{})

    // ExplainOutDefault 在控制台输出
    SqlExplain(dao.db, 3, ExplainOutDefault)
    // 输出
    defer OutExplain()
    // 下面为需要查看explain的方法
    dao.GetWorkXx(0)
    dao.GetWorkXxx(0, "a")
    dao.GetWorkXxx("a")
}

结果:

web

CSV

code:

func TestExplain(t *testing.T) {
    // 初始化db
    dao := db.InitDebug(&db.MysqlConfig{})

    // ExplainOutCsv 输出csv文件
    SqlExplain(dao.db, 3, ExplainOutCsv)
    // 输出
    defer OutExplain()
    // 下面为需要查看explain的方法
    dao.GetWorkXx(0)
    dao.GetWorkXxx(0, "a")
    dao.GetWorkXxx("a")
}

结果:

web

Web

code:

func TestExplain(t *testing.T) {
    // 初始化db
    dao := db.InitDebug(&db.MysqlConfig{})

    // ExplainOutWeb 输出到浏览器
    SqlExplain(dao.DB, 3, ExplainOutWeb)
    // 输出
    defer OutExplain()
    // 下面为需要查看explain的方法
    dao.GetWorkXx(0)
    dao.GetWorkXxx(0, "a")
    dao.GetWorkXxx("a")
}

结果:

web

支持

  • MySQL

感谢

gotabulate

gorm

kyokomi/gorm-explain

License

Licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OutExplain

func OutExplain()

func SqlExplain

func SqlExplain(db *gorm.DB, num int, out ExplainType)

Types

type Explain

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

func (*Explain) CallbackSelect

func (e *Explain) CallbackSelect(scope *gorm.Scope)

type ExplainType

type ExplainType int
const (
	ExplainOutDefault ExplainType = iota
	ExplainOutCsv
	ExplainOutWeb
)

Jump to

Keyboard shortcuts

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