database

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: Apache-2.0 Imports: 17 Imported by: 6

Documentation

Index

Constants

View Source
const (
	DEBUG_ENV = "DEBUG_MONITOR"
)

Variables

View Source
var (
	// RawQueryOption enable the raw query option
	// raw query option will convert the ? placeHolders to real data.
	// Once enabled, "SELECT a FROM b WHERE c = ?" will be "SELECT a FROM b WHERE c = d"
	RawQueryOption = rawQueryOption{}
	// IgnoreSelectColumnsOption enable the ignore select columns option
	// ignore select column option will ignore the select columns
	// Once enabled, "SELECT a,b FROM c WHERE d = ?" will be "SELECT ... FROM c WHERE d = ?"
	IgnoreSelectColumnsOption = ignoreSelectColumnsOption{}
)

Functions

func NewMongoDriverMonitor

func NewMongoDriverMonitor(m Monitor) *event.PoolMonitor

Types

type ConnOperation

type ConnOperation uint8
const (
	ConnCreate ConnOperation = iota + 1
	ConnClose
	Connoccupy
	ConnRelease
)

type DefaultPoolMonitor

type DefaultPoolMonitor struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*DefaultPoolMonitor) Conn

func (*DefaultPoolMonitor) Log

func (c *DefaultPoolMonitor) Log(w io.Writer, a interface{})

func (*DefaultPoolMonitor) Pool

type ExecContextFunc

type ExecContextFunc func(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContextFunc defines the Exec function with context

type Logger

type Logger interface {
	Log(io.Writer, interface{})
}

type Monitor

type Monitor interface {
	Logger
	Pool(PoolOperation) error
	Conn(ConnOperation) error
}

func NewMongoPoolMonitor

func NewMongoPoolMonitor(t MonitorType) Monitor

type MonitorType

type MonitorType uint8
const (
	StatsD MonitorType = iota + 1
	Prometheus
)

type PoolOperation

type PoolOperation uint8
const (
	PoolCreate PoolOperation = iota + 1
	PoolClear
)

type PrometheusPoolMonitor

type PrometheusPoolMonitor struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PrometheusMonitor is the prometheus based monitor but must be used with prometheus pushgateway

func NewPrometheusPoolMonitor

func NewPrometheusPoolMonitor(appName string, gatewayAddress string) *PrometheusPoolMonitor

func (*PrometheusPoolMonitor) Conn

func (*PrometheusPoolMonitor) Log

func (m *PrometheusPoolMonitor) Log(w io.Writer, args interface{})

func (*PrometheusPoolMonitor) Pool

type QueryContextFunc

type QueryContextFunc func(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContextFunc defines the Query function with context

type StatsDPoolMonitor

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

func NewStatsDPoolMonitor

func NewStatsDPoolMonitor(appName string) *StatsDPoolMonitor

func (*StatsDPoolMonitor) Conn

func (*StatsDPoolMonitor) Log

func (m *StatsDPoolMonitor) Log(w io.Writer, args interface{})

func (*StatsDPoolMonitor) Pool

type TracerOption

type TracerOption interface {
	QueryBuilder() func(query string, args ...interface{}) string
}

TracerOption defines the wrapper's option

type TracerWrapper

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

TracerWrapper defines a tracer wrapper which impls WrapQueryContext and WrapExecContext

func NewMongoQueryTracer

func NewMongoQueryTracer(options ...TracerOption) *TracerWrapper

func NewMsSQLTracerWrapper

func NewMsSQLTracerWrapper() *TracerWrapper

NewMsSQLTracerWrapper init a default TracerWrapper with ignoreSelectColumnsOption

func NewMsSQLTracerWrapperWithOpts

func NewMsSQLTracerWrapperWithOpts(options ...TracerOption) *TracerWrapper

NewMsSQLTracerWrapperWithOpts init a pure TracerWrapper with set options

func NewMySQLTracerWrapper

func NewMySQLTracerWrapper() *TracerWrapper

NewMySQLTracerWrapper init a default TracerWrapper with ignoreSelectColumnsOption

func NewMySQLTracerWrapperWithOpts

func NewMySQLTracerWrapperWithOpts(options ...TracerOption) *TracerWrapper

NewMySQLTracerWrapperWithOpts init a pure TracerWrapper with set options

func NewTracerWrapper

func NewTracerWrapper(dbType string) *TracerWrapper

NewTracerWrapper new a default tracer wrapper with * ignore select columns option

func (*TracerWrapper) WrapExecContext

func (t *TracerWrapper) WrapExecContext(fn ExecContextFunc, query string, args ...interface{}) ExecContextFunc

WrapExecContext impls wrapper's WrapExecContext

func (*TracerWrapper) WrapQueryContext

func (t *TracerWrapper) WrapQueryContext(fn QueryContextFunc, query string, args ...interface{}) QueryContextFunc

WrapQueryContext impls wrapper's WrapQueryContext

type Wrapper

type Wrapper interface {
	WrapQueryContext(fn QueryContextFunc, sql string, args ...interface{}) QueryContextFunc
	WrapExecContext(fn ExecContextFunc, sql string, args ...interface{}) ExecContextFunc
}

Wrapper defines database common operations

Jump to

Keyboard shortcuts

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