gorm

package module
v0.0.0-...-1db7dc6 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

README

Go2Sky with Gorm

Installation

go get -u github.com/SkyAPM/go2sky-plugins/gorm

Usage

import (
	gormPlugin "github.com/SkyAPM/go2sky-plugins/gorm"

	"github.com/SkyAPM/go2sky"
	"github.com/SkyAPM/go2sky/reporter"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

// init reporter
re, err := reporter.NewLogReporter()
defer re.Close()

// init tracer
tracer, err := go2sky.NewTracer("service-name", go2sky.WithReporter(re))
if err != nil {
    log.Fatalf("init tracer error: %v", err)
}

db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})

if err != nil {
  log.Fatalf("open db error: %v \n", err)
}
db.Use(gormPlugin.New(tracer, gormPlugin.WithPeerAddr("127.0.0.1:3306"), gormPlugin.WithSqlDBType(gormPlugin.MYSQL)))

// use with context
dbWithCtx := db.WithContext(ctx)
```(

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBType

type DBType string
const (
	UNKNOWN DBType = "unknown"
	MYSQL   DBType = "mysql"
)

type Option

type Option func(*options)

func WithParamReport

func WithParamReport() Option

func WithPeerAddr

func WithPeerAddr(addr string) Option

WithPeerAddr set the peer address to report

func WithQueryReport

func WithQueryReport() Option

func WithSqlDBType

func WithSqlDBType(t DBType) Option

WithSqlDBType set dbType option, dbType is used for parsing dsn string to peer address and setting componentID, if DB type is not support in DBType list, please use WithPeerAddr to set peer address manually

type SkyWalking

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

func New

func New(tracer *go2sky.Tracer, opts ...Option) *SkyWalking

func (*SkyWalking) AfterCallback

func (s *SkyWalking) AfterCallback() func(db *gorm.DB)

func (*SkyWalking) BeforeCallback

func (s *SkyWalking) BeforeCallback(operation string) func(db *gorm.DB)

func (*SkyWalking) Initialize

func (s *SkyWalking) Initialize(db *gorm.DB) (err error)

func (*SkyWalking) Name

func (s *SkyWalking) Name() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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