dbhelper

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Begin

func Begin(ctx context.Context) context.Context

Begin 开启数据库的事务,通常在service中使用

func Call

func Call(ctx context.Context, handle func(*gorm.DB) *gorm.DB) context.Context

Call 注册配置库连接池实例的回调,可注册事件处理,修改连接配置等

func Commit

func Commit(ctx context.Context) context.Context

Commit 提交数据库的事务,通常在service中使用

func Count

func Count(db *gorm.DB, v interface{}, filter ...interface{}) error

func Create

func Create(db *gorm.DB, m interface{}) error

func DB

func DB(ctx context.Context) *gorm.DB

DB 从context中获取数据库连接实例,通常在repository层使用

func Delete

func Delete(db *gorm.DB, m interface{}, filter ...interface{}) error

func Find

func Find(db *gorm.DB, m interface{}, filter ...interface{}) error

func First

func First(db *gorm.DB, m interface{}, filter ...interface{}) error

func Pluck

func Pluck(db *gorm.DB, m interface{}, c string, v interface{}, filter ...interface{}) error

func Register

func Register(ctx context.Context) context.Context

Register 注册数据库连接的回调和上下文信息,通常在拦截器中使用

func Rollback

func Rollback(ctx context.Context) context.Context

Rollback 回滚数据库的事务,通常在service中使用

func Save

func Save(db *gorm.DB, m interface{}) error

func Scan

func Scan(db *gorm.DB, v interface{}) error

func Update

func Update(db *gorm.DB, m interface{}) error

Types

type DBHelper

type DBHelper struct {
}

DBHelper 简化获取数据库db的操作

func (*DBHelper) Count

func (r *DBHelper) Count(ctx context.Context, m, v interface{}, filter ...interface{}) error

func (*DBHelper) Create

func (r *DBHelper) Create(ctx context.Context, m interface{}) error

func (*DBHelper) Delete

func (r *DBHelper) Delete(ctx context.Context, m interface{}, filter ...interface{}) error

func (*DBHelper) Find

func (r *DBHelper) Find(ctx context.Context, m interface{}, filter ...interface{}) error

func (*DBHelper) First

func (r *DBHelper) First(ctx context.Context, m interface{}, filter ...interface{}) error

func (*DBHelper) Pluck

func (r *DBHelper) Pluck(ctx context.Context, m interface{}, c string, v interface{}, filter ...interface{}) error

func (*DBHelper) Save

func (r *DBHelper) Save(ctx context.Context, m interface{}) error

func (*DBHelper) Scan

func (r *DBHelper) Scan(ctx context.Context, v interface{}) error

func (*DBHelper) Update

func (r *DBHelper) Update(ctx context.Context, m interface{}) error

Jump to

Keyboard shortcuts

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