db

package
v0.0.0-...-5870b03 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

默认是mysql +build mysql mariadb

Index

Constants

View Source
const DefaultPageSize = 1000

Variables

View Source
var ErrDaoNotInited = errors.New("dao not inited")

Functions

func GetCacher

func GetCacher(config configs.AllConfig, dbConfig configs.DbConfig) (cacher *caches.LRUCacher, err error)

func InitDb

func InitDb(config configs.AllConfig, dbConfig configs.DbConfig) (engine xorm.EngineInterface, err error)

Types

type Cond

type Cond map[string]interface{}

type Dao

type Dao interface {
	GetConf() configs.DbConfig

	IsTableExist(interface{}) (bool, error)
	UpdateByIds(Model, interface{}, []interface{}, ...string) (int64, error)
	UpdateByWhere(Model, Cond, Cond) (int64, error)
	Insert(Model, Model) (int64, error)
	InsertMulti(Model, interface{}) (int64, error)
	SearchOne(Model, Cond) (bool, error)
	Search(Model, interface{}, Cond) error
	SearchAndCount(Model, interface{}, Cond) (int64, error)
	GetByIds(Model, interface{}, []interface{}, ...string) error
	Count(Model, Cond) (int64, error)

	DeleteByIds(Model, interface{}) (int64, error)
	DeleteByWhere(Model, Cond) (int64, error)

	EnableCache(Model)
	DisableCache(Model)
	ClearCache(Model)
}
var DefaultDao Dao

type Model

type Model interface {
	AutoIncrColName() string
	AutoIncrColValue() int64
	TableName() string
}

type Models

type Models struct {
	Id        int       `json:"id" xorm:"not null pk autoincr INT(10)"`
	IsDeleted int       `json:"is_deleted" xorm:"not null default 0 TINYINT(1)"`
	UpdatedAt time.Time `json:"updated_at" xorm:"not null default 'CURRENT_TIMESTAMP' TIMESTAMP updated"`
	CreatedAt time.Time `json:"created_at" xorm:"not null default 'CURRENT_TIMESTAMP' TIMESTAMP created"`
}

func (*Models) GetCreatedAt

func (m *Models) GetCreatedAt() (val time.Time)

func (*Models) GetId

func (m *Models) GetId() (val int)

func (*Models) GetIsDeleted

func (m *Models) GetIsDeleted() (val int)

func (*Models) GetUpdatedAt

func (m *Models) GetUpdatedAt() (val time.Time)

type XormDao

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

func NewXormDao

func NewXormDao(config configs.AllConfig, dbConfig configs.DbConfig) (instance *XormDao, err error)

config用于缓存,dbConfig用于数据库配置

func (*XormDao) Begin

func (d *XormDao) Begin() error

func (*XormDao) ClearCache

func (d *XormDao) ClearCache(t Model)

用于清理缓存

func (*XormDao) Close

func (d *XormDao) Close()

func (*XormDao) Commit

func (d *XormDao) Commit() error

func (*XormDao) Count

func (d *XormDao) Count(t Model, cond Cond) (total int64, err error)

func (*XormDao) DeleteByIds

func (d *XormDao) DeleteByIds(t Model, ids interface{}) (affected int64, err error)

func (*XormDao) DeleteByWhere

func (d *XormDao) DeleteByWhere(t Model, where Cond) (affected int64, err error)

func (*XormDao) DisableCache

func (d *XormDao) DisableCache(t Model)

func (*XormDao) EnableCache

func (d *XormDao) EnableCache(t Model)

func (*XormDao) Exec

func (d *XormDao) Exec(sqlStr string, args ...interface{}) (rs sql.Result, err error)

调用方必须确保执行Exec后,再执行ClearCache

func (*XormDao) GetByIds

func (d *XormDao) GetByIds(t Model, ts interface{}, ids []interface{}, cols ...string) (err error)

func (*XormDao) GetConf

func (d *XormDao) GetConf() configs.DbConfig

func (*XormDao) Insert

func (d *XormDao) Insert(m, t Model) (affected int64, err error)

func (*XormDao) InsertMulti

func (d *XormDao) InsertMulti(m Model, t interface{}) (affected int64, err error)

func (*XormDao) IsTableExist

func (d *XormDao) IsTableExist(beanOrTableName interface{}) (bool, error)

func (*XormDao) Iterate

func (d *XormDao) Iterate(t Model, cond Cond, f xorm.IterFunc) (err error)

func (*XormDao) NewSession

func (d *XormDao) NewSession()

以下主要用于事务 用法 首先NewSession,然后defer Close 然后Begin,如果不Commit,会自动在Close里Rollback掉 Notice: 注意并发不安全,请勿在全局上使用

func (*XormDao) Query

func (d *XormDao) Query(t Model, args ...interface{}) (rs []map[string][]byte, err error)

func (*XormDao) QueryInterface

func (d *XormDao) QueryInterface(t Model, args ...interface{}) (rs []map[string]interface{}, err error)

func (*XormDao) QueryString

func (d *XormDao) QueryString(t Model, args ...interface{}) (rs []map[string]string, err error)

func (*XormDao) Replace

func (d *XormDao) Replace(t Model, cond Cond) (id int64, err error)

func (*XormDao) Rollback

func (d *XormDao) Rollback() error

func (*XormDao) Rows

func (d *XormDao) Rows(t Model, cond Cond) (rows *xorm.Rows, err error)

func (*XormDao) Search

func (d *XormDao) Search(t Model, ts interface{}, cond Cond) (err error)

func (*XormDao) SearchAndCount

func (d *XormDao) SearchAndCount(t Model, ts interface{}, cond Cond) (total int64, err error)

func (*XormDao) SearchOne

func (d *XormDao) SearchOne(t Model, cond Cond) (has bool, err error)

func (*XormDao) UpdateByIds

func (d *XormDao) UpdateByIds(t Model, params interface{},
	ids []interface{}, cols ...string) (affected int64, err error)

paramskey是Cond,也可以是Model

func (*XormDao) UpdateByWhere

func (d *XormDao) UpdateByWhere(t Model, params Cond,
	where Cond) (affected int64, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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