basedboperat

package
v0.0.0-...-bda4ec2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

通用基本数据库操作

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(model interface{}, intPrt *int64, condition interface{}, conditionArgs ...interface{}) error

func Create

func Create(model interface{}) (int64, error)

创建记录

func Delete

func Delete(model interface{}, PrimaryKeyID interface{}, condition interface{}, conditionArgs ...interface{}) (int64, error)

删除记录

func First

func First(destModel interface{}, PrimaryKey string, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

获取第一条记录

func GenerateCacheKey

func GenerateCacheKey(params ...any) string

func Get

func Get(destModel interface{}, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

获取记录

func Last

func Last(destModel interface{}, PrimaryKey string, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

获取最后条记录

func ListScan

func ListScan(l *List, model interface{}, destModels interface{})

func QueryScan

func QueryScan(destModel interface{}, extra interface{}, condition interface{}, args ...interface{}) error

func ReflectStructID

func ReflectStructID(obj interface{}) interface{}

func SetGlobalCacheExpire

func SetGlobalCacheExpire(expire int64)

func SetOrmEngine

func SetOrmEngine(engineName string) error

设定orm引擎 gorm|xorm|...

func SqlExec

func SqlExec(sql interface{}, args ...interface{}) error

执行原生sql语句

func SqlQuery

func SqlQuery(sql interface{}, args ...interface{}) (resultsSlice []map[string]interface{}, err error)

原生sql查询

func SqlQueryScan

func SqlQueryScan(destModel interface{}, sql interface{}, args ...interface{}) error

原生sql查询解析到结构体或MAP

func Sync

func Sync(beans ...any)

func Update

func Update(model interface{}, fields any, condition interface{}, conditionArgs ...interface{}) error

更新记录

Types

type Condition

type Condition struct {
	Field    string      `json:"field"`
	Operator string      `json:"operator"`
	Value    interface{} `json:"value"`
}

type DbContext

type DbContext interface {
	WithValue(key, value any)
	Value(key any) any
}

type DbOperat

type DbOperat interface {
	DbContext
	//获取第一条记录
	First(destModel interface{}, PrimaryKey string, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

	//获取最后一条记录
	Last(destModel interface{}, PrimaryKey string, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

	//列表查询
	ListScan(l *List, model interface{}, destModels interface{})

	//获取一条记录
	Get(destModel interface{}, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

	//修改记录
	Update(model interface{}, fields any, condition interface{}, conditionArgs ...interface{}) error

	//删除记录
	Delete(model interface{}, PrimaryKeyID interface{}, condition interface{}, conditionArgs ...interface{}) (int64, error)

	//创建记录
	Create(model interface{}) (int64, error)

	//执行原生sql命令
	SqlExec(sql interface{}, args ...interface{}) error

	//执行原生sql查询
	SqlQuery(sql interface{}, args ...interface{}) (resultsSlice []map[string]interface{}, err error)

	//执行原生sql查询并将结果解析到结构体、map等结构中
	SqlQueryScan(destModel interface{}, sql interface{}, args ...interface{}) error

	//执行根据条件查询
	QueryScan(destModel interface{}, order interface{}, condition interface{}, args ...interface{}) error

	//获取记录数
	Count(model interface{}, intPrt *int64, condition interface{}, conditionArgs ...interface{}) error

	//获取当前选择的字段
	GetCurrentSelectFields() []string

	//当前是否选中该字段
	IsCurrentSelectedField(field string) bool

	//同步结构到数据库
	Sync(beans ...any)
}

通用数据库基本操作接口

type DbTransactionSession

type DbTransactionSession interface {
	Begin() error
	Commit() error
	Rollback() error
	DbOperat
}

事务接口

func NewTransaction

func NewTransaction() (DbTransactionSession, error)

新建事务

func WithContext

func WithContext(ctx context.Context) (DbTransactionSession, error)

type Gorm

type Gorm struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Gorm) Begin

func (orm *Gorm) Begin() error

func (*Gorm) Commit

func (orm *Gorm) Commit() error

func (*Gorm) Count

func (orm *Gorm) Count(model interface{}, intPtr *int64, condition interface{}, args ...interface{}) error

func (*Gorm) Create

func (orm *Gorm) Create(model interface{}) (int64, error)

创建记录

func (*Gorm) Delete

func (orm *Gorm) Delete(model interface{}, PrimaryKeyID interface{}, condition interface{}, conditionArgs ...interface{}) (int64, error)

删除记录

func (*Gorm) First

func (orm *Gorm) First(destModel interface{}, PrimaryKey string, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

func (*Gorm) Get

func (orm *Gorm) Get(destModel interface{}, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

获取记录

func (*Gorm) GetCurrentSelectFields

func (orm *Gorm) GetCurrentSelectFields() []string

func (*Gorm) IsCurrentSelectedField

func (orm *Gorm) IsCurrentSelectedField(field string) bool

func (*Gorm) Last

func (orm *Gorm) Last(destModel interface{}, PrimaryKey string, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

获取最后条记录

func (*Gorm) ListScan

func (orm *Gorm) ListScan(l *List, model interface{}, destModels interface{})

func (*Gorm) QueryScan

func (orm *Gorm) QueryScan(destModel interface{}, extra interface{}, condition interface{}, args ...interface{}) error

执行根据条件查询

func (*Gorm) Rollback

func (orm *Gorm) Rollback() error

func (*Gorm) SqlExec

func (orm *Gorm) SqlExec(sql interface{}, args ...interface{}) error

执行原生sql语句

func (*Gorm) SqlQuery

func (orm *Gorm) SqlQuery(sql interface{}, args ...interface{}) (resultsSlice []map[string]interface{}, err error)

原生sql查询

func (*Gorm) SqlQueryScan

func (orm *Gorm) SqlQueryScan(destModel interface{}, sql interface{}, args ...interface{}) error

原生sql查询解析到结构体或MAP

func (*Gorm) Sync

func (orm *Gorm) Sync(beans ...any)

func (*Gorm) Update

func (orm *Gorm) Update(model interface{}, fields any, condition interface{}, conditionArgs ...interface{}) error

更新记录

func (*Gorm) Value

func (orm *Gorm) Value(key any) any

func (*Gorm) WithValue

func (orm *Gorm) WithValue(key, value any)

type List

type List struct {
	CacheExpireLimit int64
	Count            int64 `json:"count"`
	Error            error `json:"-"`
	// contains filtered or unexported fields
}

type ListSimple

type ListSimple struct {
	In      map[string][]interface{} `json:"and"`
	Table   string                   `json:"table"`
	Count   int64                    `json:"count"`
	Error   error                    `json:"-"`
	Field   []string                 `json:"field"`
	Orderby []map[string]string      `json:"orderby"`
}

type Xorm

type Xorm struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Xorm) Begin

func (orm *Xorm) Begin() error

func (*Xorm) Commit

func (orm *Xorm) Commit() error

func (*Xorm) Count

func (orm *Xorm) Count(model interface{}, intPrt *int64, condition interface{}, conditionArgs ...interface{}) error

获取记录

func (*Xorm) Create

func (orm *Xorm) Create(model interface{}) (int64, error)

创建记录

func (*Xorm) Delete

func (orm *Xorm) Delete(model interface{}, PrimaryKeyID interface{}, condition interface{}, conditionArgs ...interface{}) (int64, error)

删除记录

func (*Xorm) First

func (orm *Xorm) First(destModel interface{}, PrimaryKey string, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

func (*Xorm) Get

func (orm *Xorm) Get(destModel interface{}, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

获取记录

func (*Xorm) GetCurrentSelectFields

func (orm *Xorm) GetCurrentSelectFields() []string

func (*Xorm) IsCurrentSelectedField

func (orm *Xorm) IsCurrentSelectedField(field string) bool

func (*Xorm) Last

func (orm *Xorm) Last(destModel interface{}, PrimaryKey string, selectFields []string, condition interface{}, conditionArgs ...interface{}) error

获取最后条记录

func (*Xorm) ListScan

func (orm *Xorm) ListScan(l *List, model interface{}, destModels interface{})

func (*Xorm) QueryScan

func (orm *Xorm) QueryScan(destModel interface{}, extra interface{}, condition interface{}, args ...interface{}) error

执行根据条件查询

func (*Xorm) Rollback

func (orm *Xorm) Rollback() error

func (*Xorm) SqlExec

func (orm *Xorm) SqlExec(sql interface{}, args ...interface{}) error

执行原生sql语句

func (*Xorm) SqlQuery

func (orm *Xorm) SqlQuery(sql interface{}, args ...interface{}) (resultsSlice []map[string]interface{}, err error)

原生sql查询

func (*Xorm) SqlQueryScan

func (orm *Xorm) SqlQueryScan(destModel interface{}, sql interface{}, args ...interface{}) error

原生sql查询解析到结构体或MAP

func (*Xorm) Sync

func (orm *Xorm) Sync(beans ...any)

func (*Xorm) Update

func (orm *Xorm) Update(model interface{}, fields any, condition interface{}, conditionArgs ...interface{}) error

更新记录

func (*Xorm) Value

func (orm *Xorm) Value(key any) any

func (*Xorm) WithValue

func (orm *Xorm) WithValue(key, value any)

Jump to

Keyboard shortcuts

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