db

package
v0.0.0-...-8e1329c Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDBConfig

func InitDBConfig(maxOpenConns, maxIdleConns int)

InitDBConfig 初始化数据库配置

func Now

func Now() (now int64)

Now 当前unix时间

Types

type BaseDao

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

BaseDao 基础Dao BaseDao 中Must开头的函数, 如果出错会抛出Panic, 错误信息为: baselib.errors.ApiError{Reason: 'ERR_SERVER_ERROR', Errmsg: '错误的具体信息'}

func NewBaseDao

func NewBaseDao(dialect, dbURL string, sqlDebug bool, model interface{}) (dao *BaseDao)

NewBaseDao 创建新的BaseDao, model指定对应的模型类

func NewSharedBaseDao

func NewSharedBaseDao(shared *SharedDao, model interface{}) (dao *BaseDao)

func (*BaseDao) Begin

func (p *BaseDao) Begin() (err error)

Begin 开启事务

func (*BaseDao) Commit

func (p *BaseDao) Commit() (err error)

Commit 提交事务

func (*BaseDao) DB

func (p *BaseDao) DB() (db *gorm.DB)

func (*BaseDao) Delete

func (p *BaseDao) Delete(query interface{}, args ...interface{}) (effectRows int64)

Delete 根据查询及参数删除

func (*BaseDao) DeleteBy

func (p *BaseDao) DeleteBy(fieldName string, value interface{}) (effectRows int64)

DeleteBy 按指定的字段及值删除

func (*BaseDao) DeleteByID

func (p *BaseDao) DeleteByID(id interface{}) (effectRows int64)

DeleteByID 根据id删除.

func (*BaseDao) Exec

func (p *BaseDao) Exec(sql string, args ...interface{}) (affectedRows int64, err error)

Exec 执行Update更新语句.

func (*BaseDao) Find

func (p *BaseDao) Find(query interface{}, args ...interface{}) (result interface{}, err error)

Find 简单查询

func (*BaseDao) Get

func (p *BaseDao) Get(query interface{}, args ...interface{}) (result interface{})

Get 功能同GetSimple, 如果出错会导致panic.

func (*BaseDao) GetShared

func (p *BaseDao) GetShared() (shared *SharedDao)

func (*BaseDao) GetSimple

func (p *BaseDao) GetSimple(query interface{}, args ...interface{}) (result interface{}, err error)

GetSimple 简单查询

func (*BaseDao) Insert

func (p *BaseDao) Insert(value interface{}) (err error)

func (*BaseDao) MustBegin

func (p *BaseDao) MustBegin()

MustBegin 开始事务, 如果出错会导致panic.

func (*BaseDao) MustCommit

func (p *BaseDao) MustCommit()

func (*BaseDao) MustCount

func (p *BaseDao) MustCount(query string, args ...interface{}) (count int64)

MustCount 执行Count查询. 如果出错会导致panic.

func (*BaseDao) MustExec

func (p *BaseDao) MustExec(sql string, args ...interface{}) (affectedRows int64)

MustExec 功能周Exec, 如果出错会导致panic.

func (*BaseDao) MustGet

func (p *BaseDao) MustGet(query interface{}, args ...interface{}) (result interface{})

MustGet 功能同Get, 如果未查询到对象, 会panic(ErrObjectNotFound)

func (*BaseDao) MustInsert

func (p *BaseDao) MustInsert(value interface{})

func (*BaseDao) MustPagingFind

func (p *BaseDao) MustPagingFind(orderBy interface{}, page int, pageSize int, query interface{}, args ...interface{}) (result interface{})

MustPagingFind 功能同PagingFind, 如果出错会导致panic.

func (*BaseDao) MustQueryInt

func (p *BaseDao) MustQueryInt(sql string, args ...interface{}) (value int64)

MustQueryInt 功能同QueryInt, 如果出错会导致panic.

func (*BaseDao) MustRawFind

func (p *BaseDao) MustRawFind(rawQuery string, args ...interface{}) (result interface{})

MustRawFind 功能同RawFind, 如果出错会导致panic.

func (*BaseDao) MustRawFindModel

func (p *BaseDao) MustRawFindModel(model interface{}, rawQuery string, args ...interface{}) (result interface{})

MustRawFindModel 功能同RawFindModel, 如果出错会导致panic.

func (*BaseDao) MustRawGet

func (p *BaseDao) MustRawGet(model interface{}, rawQuery string, args ...interface{}) (result interface{})

MustRawGet 使用原始查询,查询单个对象

func (*BaseDao) MustRollback

func (p *BaseDao) MustRollback()

func (*BaseDao) MustSave

func (p *BaseDao) MustSave(value interface{})

func (*BaseDao) PagingFind

func (p *BaseDao) PagingFind(orderBy interface{}, page int, pageSize int, query interface{}, args ...interface{}) (result interface{}, err error)

PagingFind 支持分页的查询, 返回值result 类型为: *[]Object

func (*BaseDao) QueryInt

func (p *BaseDao) QueryInt(sql string, args ...interface{}) (value int64, err error)

QueryInt 执行查询,返回Int结果

func (*BaseDao) RawFind

func (p *BaseDao) RawFind(rawQuery string, args ...interface{}) (result interface{}, err error)

RawFind 使用原生SQL查询(使用当前dao的模型)

func (*BaseDao) RawFindModel

func (p *BaseDao) RawFindModel(model interface{}, rawQuery string, args ...interface{}) (result interface{}, err error)

RawFindModel 使用原生SQL查询(指定结果Model)

func (*BaseDao) Rollback

func (p *BaseDao) Rollback() (err error)

Rollback 回滚事务

func (*BaseDao) Save

func (p *BaseDao) Save(value interface{}) (err error)

func (*BaseDao) TableName

func (p *BaseDao) TableName() (tableName string)

TableName 获取表名

func (*BaseDao) UpdateBy

func (p *BaseDao) UpdateBy(update interface{}, query interface{}, args ...interface{}) (effectRows int64)

UpdateBy 根据查询,更新对象, 结构体中为空("")的字段不会被重置为空

func (*BaseDao) Upsert

func (p *BaseDao) Upsert(obj interface{}) (operator string, effectRows int64)

有设置主键时才可以使用. 唯一键不行.

type ITableName

type ITableName interface {
	TableName() string
}

ITableName 表名获取接口

type SharedDao

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

SharedDao 共享数据库链接对象的Dao

Jump to

Keyboard shortcuts

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