ppgorm

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

ppgorm

This package instruments the go-gorm/gorm package.

Installation

$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/gorm
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/gorm"

Usage

PkgGoDev

This package instruments the go-gorm/gorm calls. Use the Open as the gorm.Open.

g, err := ppgorm.Open(mysql.New(mysql.Config{Conn: db}), &gorm.Config{})

It is necessary to pass the context containing the pinpoint.Tracer to gorm.DB.

g = g.WithContext(pinpoint.NewContext(context.Background(), tracer))
g.Create(&Product{Code: "D42", Price: 100})
package main

import (
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/gorm"
    _ "github.com/pinpoint-apm/pinpoint-go-agent/plugin/mysql"
    "gorm.io/driver/mysql"
    "gorm.io/gorm"
)

func gormQuery(w http.ResponseWriter, r *http.Request) {
    db, err := sql.Open("mysql-pinpoint", "root:p123@tcp(127.0.0.1:3306)/testdb")
    gormdb, err := ppgorm.Open(mysql.New(mysql.Config{Conn: db}), &gorm.Config{})
    gormdb = gormdb.WithContext(r.Context())

    gormdb.AutoMigrate(&Product{})
    gormdb.Create(&Product{Code: "D42", Price: 100})

    var product Product
    gormdb.First(&product, "code = ?", "D42")

    ...
}

Full Example Source

Documentation

Overview

Package ppgorm instruments the go-gorm/gorm package (https://github.com/go-gorm/gorm).

This package instruments the go-gorm/gorm calls. Use the Open as the gorm.Open.

g, err := ppgorm.Open(mysql.New(mysql.Config{Conn: db}), &gorm.Config{})

It is necessary to pass the context containing the pinpoint.Tracer to gorm.DB.

g = g.WithContext(pinpoint.NewContext(context.Background(), tracer))
g.Create(&Product{Code: "D42", Price: 100})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(dialector gorm.Dialector, opts ...gorm.Option) (*gorm.DB, error)

Open returns a new *gorm.DB ready to instrument.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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