gorm

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package gorm provides helper functions for tracing the jinzhu/gorm package (https://github.com/jinzhu/gorm).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(dialect, source string) (*gorm.DB, error)

Open opens a new (traced) database connection. The used dialect must be formerly registered using (github.com/signalfx/signalfx-go-tracing/contrib/database/sql).Register.

Example
package main

import (
	"log"

	"github.com/jinzhu/gorm"
	"github.com/lib/pq"

	sqltrace "github.com/signalfx/signalfx-go-tracing/contrib/database/sql"
	gormtrace "github.com/signalfx/signalfx-go-tracing/contrib/jinzhu/gorm"
)

func main() {
	// Register augments the provided driver with tracing, enabling it to be loaded by gormtrace.Open.
	sqltrace.Register("postgres", &pq.Driver{}, sqltrace.WithServiceName("my-service"))

	// Open the registered driver, allowing all uses of the returned *gorm.DB to be traced.
	db, err := gormtrace.Open("postgres", "postgres://pqgotest:password@localhost/pqgotest?sslmode=disable")
	defer db.Close()
	if err != nil {
		log.Fatal(err)
	}

	user := struct {
		gorm.Model
		Name string
	}{}

	// All calls through gorm.DB are now traced.
	db.Where("name = ?", "jinzhu").First(&user)
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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