data

package
v0.0.0-...-3839eb7 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const LikeDelim = "%"

Variables

View Source
var SupportDrivers = map[string]DBDriver{
	"mysql":      MysqlDriver,
	"postgres":   PostGreDriver,
	"sqlite":     SqlLiteDriver,
	"sqlserver":  SqlServerDriver,
	"clickhouse": ClickHouseDriver,
	"tidb":       TiDBDriver,
}

Functions

func ClickHouseDriver

func ClickHouseDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)

func ClickHouseDsn

func ClickHouseDsn(cfg *conf.DatabaseConf) string

ClickHouseDsn eg: tcp://localhost:9000?database=gorm&username=gorm&password=gorm&read_timeout=10&write_timeout=20

func DialTestDB

func DialTestDB() (*gorm.DB, error)

func HasRecordFound

func HasRecordFound(db *gorm.DB) (bool, error)

func Like

func Like(pattern string) string

func LikePrefix

func LikePrefix(pattern string) string

func LikeSuffix

func LikeSuffix(pattern string) string

func MysqlDriver

func MysqlDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)

func MysqlDsn

func MysqlDsn(cfg *conf.DatabaseConf) string

MysqlDsn eg: user:password@tcp(ip:port)/db?params

func NewDBClient

func NewDBClient(ctx context.Context, conf *conf.DatabaseConf) (*gorm.DB, error)

NewDBClient return a new db client due to gorm not support open with cancel context, so we need to implement it by self

func NewRedisClient

func NewRedisClient(ctx context.Context, conf *conf.RedisConf) (*redis.Client, error)

func PostGreDriver

func PostGreDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)

func PostGreDsn

func PostGreDsn(cfg *conf.DatabaseConf) string

PostGreDsn eg: host=localhost port=9920 user=gorm password=gorm dbname=gorm sslmode=disable TimeZone=Asia/Shanghai

func SqlLiteDriver

func SqlLiteDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)

func SqlLiteDsn

func SqlLiteDsn(cfg *conf.DatabaseConf) string

SqlLiteDsn eg: file:test.db?cache=shared&mode=memory

func SqlServerDriver

func SqlServerDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)

func SqlServerDsn

func SqlServerDsn(cfg *conf.DatabaseConf) string

SqlServerDsn eg: sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm

func TiDBDriver

func TiDBDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)

TiDBDriver TiDB is compatible with Mysql protocol

Types

type DBDriver

type DBDriver func(cfg *conf.DatabaseConf) (gorm.Dialector, error)

type DataSource

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

func NewDataSource

func NewDataSource(ctx context.Context, databaseConf *conf.DataConf) (*DataSource, error)

func (*DataSource) Close

func (d *DataSource) Close() error

func (*DataSource) ORM

func (d *DataSource) ORM() *gorm.DB

func (*DataSource) Redis

func (d *DataSource) Redis() *redis.Client

type Dsn

type Dsn func(conf *conf.DatabaseConf) string

type GormLogger

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

GormLogger an adaptor between gorm and logrus

func (*GormLogger) Error

func (g *GormLogger) Error(ctx context.Context, s string, i ...interface{})

func (*GormLogger) Info

func (g *GormLogger) Info(ctx context.Context, s string, i ...interface{})

func (*GormLogger) LogMode

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

func (*GormLogger) Trace

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

func (*GormLogger) Warn

func (g *GormLogger) Warn(ctx context.Context, s string, i ...interface{})

type GormOption

type GormOption func(*gorm.DB) *gorm.DB

func Order

func Order(column string, desc bool) GormOption

func Pages

func Pages(page, size int) GormOption

type GormOptions

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

func (GormOptions) AfterInitialize

func (l GormOptions) AfterInitialize(db *gorm.DB) error

func (GormOptions) Apply

func (l GormOptions) Apply(config *gorm.Config) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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