store

package
v0.0.0-...-60b7b37 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package store mysql database

Package store redis database

Package store redis hook for logging Redis commands

Package store sql hooks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitRedis

func InitRedis(conf storeconf.RedisConfig) (*redis.Client, error)

InitRedis initializes a Redis connection.

Types

type DB

type DB struct {
	*sqlx.DB
	DataSourceName string
}

DB represents a database connection with sqlx capabilities.

func InitDB

func InitDB(driverName, dataSourceName string, driver driver.Driver, opt ...DatabaseOption) (*DB, error)

InitDB initializes a database connection.

func InitMysql

func InitMysql(conf storeconf.MysqlConfig, opt ...DatabaseOption) (*DB, error)

InitMysql initializes a MySQL connection.

func (*DB) Close

func (db *DB) Close() error

Close db conn.

func (*DB) Transact

func (db *DB) Transact(fn func(*sqlx.Tx) error) (err error)

Transact executes a function within a transaction, handling commit and rollback automatically.

type DatabaseOption

type DatabaseOption struct {
	Hook               sqlhooks.Hooks
	ConnMaxLifetime    time.Duration
	MaxIdleConns       int
	MaxOpenConns       int
	RegisterHookDriver bool
}

DatabaseOption defines options for initializing a database connection.

type RedisHook

type RedisHook struct{}

RedisHook implements redis.Hook interface for logging Redis commands.

func (*RedisHook) AfterProcess

func (*RedisHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error

AfterProcess is called after Redis command is processed.

func (*RedisHook) AfterProcessPipeline

func (*RedisHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error

AfterProcessPipeline is called after a Redis pipeline is processed.

func (*RedisHook) BeforeProcess

func (*RedisHook) BeforeProcess(ctx context.Context, _ redis.Cmder) (context.Context, error)

BeforeProcess is called before Redis command is processed.

func (*RedisHook) BeforeProcessPipeline

func (*RedisHook) BeforeProcessPipeline(ctx context.Context, _ []redis.Cmder) (context.Context, error)

BeforeProcessPipeline is called before a Redis pipeline is processed.

type SQLHooks

type SQLHooks struct{}

SQLHooks is a hook collection.

func (*SQLHooks) After

func (h *SQLHooks) After(ctx context.Context, query string, args ...any) (context.Context, error)

After records SQL execution time.

func (*SQLHooks) Before

func (h *SQLHooks) Before(ctx context.Context, _ string, _ ...any) (context.Context, error)

Before records SQL execution time.

Jump to

Keyboard shortcuts

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