Documentation ¶
Index ¶
- Constants
- Variables
- func ClickHouseDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)
- func ClickHouseDsn(cfg *conf.DatabaseConf) string
- func DialTestDB() (*gorm.DB, error)
- func HasRecordFound(db *gorm.DB) (bool, error)
- func Like(pattern string) string
- func LikePrefix(pattern string) string
- func LikeSuffix(pattern string) string
- func MysqlDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)
- func MysqlDsn(cfg *conf.DatabaseConf) string
- func NewDBClient(ctx context.Context, conf *conf.DatabaseConf) (*gorm.DB, error)
- func NewRedisClient(ctx context.Context, conf *conf.RedisConf) (*redis.Client, error)
- func PostGreDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)
- func PostGreDsn(cfg *conf.DatabaseConf) string
- func SqlLiteDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)
- func SqlLiteDsn(cfg *conf.DatabaseConf) string
- func SqlServerDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)
- func SqlServerDsn(cfg *conf.DatabaseConf) string
- func TiDBDriver(cfg *conf.DatabaseConf) (gorm.Dialector, error)
- type DBDriver
- type DataSource
- type Dsn
- type GormLogger
- func (g *GormLogger) Error(ctx context.Context, s string, i ...interface{})
- func (g *GormLogger) Info(ctx context.Context, s string, i ...interface{})
- func (g *GormLogger) LogMode(level logger.LogLevel) logger.Interface
- func (g *GormLogger) Trace(ctx context.Context, begin time.Time, ...)
- func (g *GormLogger) Warn(ctx context.Context, s string, i ...interface{})
- type GormOption
- type GormOptions
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 LikePrefix ¶
func LikeSuffix ¶
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 ¶
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 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 DataSource ¶
type DataSource struct {
// contains filtered or unexported fields
}
func NewDataSource ¶
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{})
type GormOption ¶
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
Click to show internal directories.
Click to hide internal directories.