ormx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 7 Imported by: 0

README

ormx

链路追踪(v0.0.6)

package test

import (
	"context"
	"git.cht-group.net/cht-group-go/engine/tracex"
	"git.cht-group.net/cht-group-go/ormx"
	"testing"
	"time"
)

func TestOrmTrace(t *testing.T) {
	lg := ormx.NewLog("info")
	//设置回调函数
	lg.SetTrace(tracex.OrmTrace)
	//打开开关
	//ormx.JaegerEnable = true
	lg.Trace(context.Background(), time.Now().Add(time.Millisecond*-100), func() (sql string, rowsAffected int64) {
		return "select * from users limit 10", 10
	}, nil)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DbSplit

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

func NewDbSplit

func NewDbSplit(cfg MysqlConfig) *DbSplit

func (*DbSplit) Close

func (sp *DbSplit) Close() error

func (*DbSplit) Create

func (sp *DbSplit) Create(v interface{}) *gorm.DB

func (*DbSplit) CreateWithContext

func (sp *DbSplit) CreateWithContext(ctx context.Context, v interface{}) *gorm.DB

func (*DbSplit) GetLogger

func (sp *DbSplit) GetLogger() *GormLogger

func (*DbSplit) Model

func (sp *DbSplit) Model(v interface{}) *gorm.DB

func (*DbSplit) Read

func (sp *DbSplit) Read() *gorm.DB

func (*DbSplit) ReadWithContext

func (sp *DbSplit) ReadWithContext(ctx context.Context) *gorm.DB

func (*DbSplit) Save

func (sp *DbSplit) Save(v interface{}) *gorm.DB

func (*DbSplit) SaveWithContext

func (sp *DbSplit) SaveWithContext(ctx context.Context, v interface{}) *gorm.DB

func (*DbSplit) Table

func (sp *DbSplit) Table(v string) *gorm.DB

func (*DbSplit) Transaction

func (sp *DbSplit) Transaction(fc func(tx *gorm.DB) error, opts ...*sql.TxOptions) error

func (*DbSplit) TransactionWithContext

func (sp *DbSplit) TransactionWithContext(ctx context.Context, fc func(tx *gorm.DB) error, opts ...*sql.TxOptions) error

func (*DbSplit) Write

func (sp *DbSplit) Write() *gorm.DB

func (*DbSplit) WriteWithContext

func (sp *DbSplit) WriteWithContext(ctx context.Context) *gorm.DB

type GormLogger

type GormLogger struct {
	logger.LogLevel
	TracerFunc func(ctx context.Context, begin time.Time, sql string, rowsAffected int64, err error)
	CallerSkip int
}

func NewLog

func NewLog(level string) *GormLogger

func (*GormLogger) Error

func (l *GormLogger) Error(ctx context.Context, format string, params ...interface{})

func (*GormLogger) Info

func (l *GormLogger) Info(ctx context.Context, format string, params ...interface{})

func (*GormLogger) LogMode

func (l *GormLogger) LogMode(level logger.LogLevel) logger.Interface

func (*GormLogger) SetTrace

func (l *GormLogger) SetTrace(fn func(ctx context.Context, begin time.Time, sql string, rowsAffected int64, err error))

func (*GormLogger) SetTraceFunc

func (l *GormLogger) SetTraceFunc(fn func(ctx context.Context, begin time.Time, sql string, rowsAffected int64, err error))

func (*GormLogger) Trace

func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*GormLogger) Warn

func (l *GormLogger) Warn(ctx context.Context, format string, params ...interface{})

type MysqlConfig

type MysqlConfig struct {
	DataSourceWrite string // mysql链接地址,满足 $user:$password@tcp($ip:$port)/$db?$queries 格式即可
	DataSourceRead  string
	MaxConnIdle     int    `json:",default=20"`
	MaxIdleTime     int64  `json:",default=3600"`
	MaxLeftTime     int64  `json:",default=3600"`
	MaxOpen         int    `json:",default=30"`
	LogLevel        string `json:",default=info"`
}

Jump to

Keyboard shortcuts

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