Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewORM ¶
NewORM returns a new gorm DB instance. Create a dialector by calling e.g. https://pkg.go.dev/gorm.io/driver/mysql#New
Example (Standard) ¶
package main
import (
"context"
ddGorm "github.com/coopnorge/go-datadog-lib/v2/middleware/gorm"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type User struct{}
func main() {
ctx := context.Background()
dsn := "example.com/users"
gormDB, err := ddGorm.NewORM(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
user := &User{}
tx := gormDB.WithContext(ctx).Select("*").First(user)
println(tx)
}
Example (WithDriver) ¶
package main
import (
"context"
ddDatabase "github.com/coopnorge/go-datadog-lib/v2/middleware/database"
ddGorm "github.com/coopnorge/go-datadog-lib/v2/middleware/gorm"
mysqlDriver "github.com/go-sql-driver/mysql"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type User struct{}
func main() {
ctx := context.Background()
dsn := "example.com/users"
db, err := ddDatabase.RegisterDriverAndOpen("mysql", mysqlDriver.MySQLDriver{}, dsn)
if err != nil {
panic(err)
}
gormDB, err := ddGorm.NewORM(mysql.New(mysql.Config{Conn: db}), &gorm.Config{})
if err != nil {
panic(err)
}
user := &User{}
tx := gormDB.WithContext(ctx).Select("*").First(user)
println(tx)
}
Types ¶
type Option ¶
type Option func(cfg *config)
Option allows for overriding our default-config.
func WithCustomTag ¶
WithCustomTag will attach the value to the span tagged by the key.
func WithServiceName ¶
WithServiceName overrides the service-name set in environment-variable "DD_SERVICE".
Click to show internal directories.
Click to hide internal directories.