sqlcommentergorm

package module
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 6 Imported by: 1

README

sqlcommenter-gorm

gorm plugin for https://github.com/google/sqlcommenter

go report card test status MIT license Go.Dev reference visitor badge

sqlcommenter is a suite of middlewares/plugins that enable your ORMs to augment SQL statements before execution, with comments containing information about the code that caused its execution. This helps in easily correlating slow performance with source code and giving insights into backend database performance. In short it provides some observability into the state of your client-side applications and their impact on the database’s server-side.

Usage

    ...
    db.Use(sqlcommentergorm.Default())
    ...
    sess := DB.Scopes(sqlcommentergorm.ContextInject(ctx)).Session(&gorm.Session{})
    sess.Create(&user)
    // inject the following comments
    /* action='mockHandler',db_driver='mysql',framework='gorm',route='GET--%2Fmytest%2F%3Aid' */

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissSQLCommenterOptions = errors.New("missing sqlcommenter options")

Functions

func ContextInject

func ContextInject(ctx context.Context) func(*gorm.DB) *gorm.DB

Types

type Config

type Config struct {
	Application string

	DisableRoute       bool
	DisableFramework   bool
	DisableController  bool
	DisableAction      bool
	DisableTraceparent bool
}

type SQLCommenter

type SQLCommenter struct {
	Prefix  string
	Content string
	Suffix  string
}

func (*SQLCommenter) Build

func (c *SQLCommenter) Build(builder clause.Builder)

Build

func (*SQLCommenter) MergeClause

func (c *SQLCommenter) MergeClause(clause *clause.Clause)

MergeClause merge With clauses

func (*SQLCommenter) Name

func (*SQLCommenter) Name() string

Name clause name

type SQLCommenterPlugin

type SQLCommenterPlugin struct {
	Options core.CommenterOptions
}

SQLCommenterPlugin gorm plugin

func Default

func Default() *SQLCommenterPlugin

func New

func New(config *Config) *SQLCommenterPlugin

func (*SQLCommenterPlugin) Initialize

func (p *SQLCommenterPlugin) Initialize(db *gorm.DB) error

Initialize gorm plugin initialize

func (*SQLCommenterPlugin) Name

func (*SQLCommenterPlugin) Name() string

Name gorm plugin name

Directories

Path Synopsis
tests module

Jump to

Keyboard shortcuts

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