Documentation ¶
Index ¶
Constants ¶
View Source
const ( Postgresql DriverName = "postgresql" MySQL = "mysql" SQLite = "sqlite" SQLServer = "sqlserver" TiDB DriverName = "tidb" )
View Source
const ( // CallBackBeforeName sql执行之前tag CallBackBeforeName = "opentracing:before" // CallBackAfterName sql执行之后tag CallBackAfterName = "opentracing:after" )
View Source
const GormSpanKey = "__gorm_span"
GormSpanKey 包内静态变量
Variables ¶
This section is empty.
Functions ¶
func DBConnect ¶
func DBConnect(driver DriverName, dsn string, option options) (*gorm.DB, error)
DBConnect init database connect
func DBWhereExpression ¶
func DBWhereExpression(column string, value any, symbol string) clause.Expression
DBWhereExpression process field symbol expression
Types ¶
type BasicRepo ¶
type BasicRepo[T any] interface { // Create 创建一条数据 Create(ctx context.Context, ent *T) error // Creates 批量创建 Creates(ctx context.Context, ent []*T) error // Update 通过id更新数据 Update(ctx context.Context, id uint, ent *T) error // UpdateColumns 通过id更新部分字段数据 UpdateColumns(ctx context.Context, id uint, data any) error // UpdateColumnsBy 通过条件表达式更新数据 UpdateColumnsBy(ctx context.Context, expression []clause.Expression, data any) error // Find 查询 Find(ctx context.Context, expression ...clause.Expression) ([]*T, error) // FindOneBy 通过条件表达式查询一条数据 FindOneBy(ctx context.Context, expression []clause.Expression) (*T, error) // FindOne 通过id查询一条数据 FindOne(ctx context.Context, id uint) (*T, error) // DeleteOne 通过id删除一条数据 DeleteOne(ctx context.Context, id uint) error // DeleteBy 通过条件删除一条或者多条数据 DeleteBy(ctx context.Context, expression []clause.Expression) error // Count 进行统计数据 Count(ctx context.Context, expression ...clause.Expression) (count int64, err error) // ExecTX 开启事务 ExecTX(ctx context.Context, fc func(ctx context.Context) error) error // Database 获取db Database() Database // Model 获取模型 Model() *T }
BasicRepo 基本的存储库
func NewBasicRepository ¶
NewBasicRepository 新建基础存储库
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
type Database ¶
type Database interface { DB(ctx context.Context) *gorm.DB Close() error TranslateGormError(ctx context.Context, db *gorm.DB) error ExecTx(ctx context.Context, fc func(context.Context) error) error }
func NewDataBase ¶
func NewDataBase(driver DriverName, dsn string, opts ...Option) (Database, error)
NewDataBase new database
type Limit ¶
type Limit struct { All bool // true获取全部条目 PageSize uint // 每页数量 PageNum uint // 页数 Count bool // true获取总数 }
Limit 数据库数量查询限制
type OpentracingPlugin ¶
type OpentracingPlugin struct { }
OpentracingPlugin 追踪插件
func (*OpentracingPlugin) Initialize ¶
func (op *OpentracingPlugin) Initialize(db *gorm.DB) error
func (*OpentracingPlugin) Name ¶
func (op *OpentracingPlugin) Name() string
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithAutoMigrate ¶
func WithAutoMigrateDst ¶
func WithLogger ¶
func WithOpentracingPlugin ¶
func WithOpentracingPlugin(op *OpentracingPlugin) Option
func WithTablePrefix ¶
func WithTranslateError ¶
func WithTranslateError(translateError translateErrorFc) Option
Click to show internal directories.
Click to hide internal directories.