mdb

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TxNil = &Session{} // 空事务对象

	ErrNameRepeated     = errors.New("ErrMdbNameRepeated")
	ErrSelectFieldsNone = errors.New("ErrSelectFieldsZero")
)

Functions

func ConnDBStats

func ConnDBStats(dbName string) sql.DBStats

ConnDBStats 获取指定db连接统计状态

func Connector

func Connector(dbName string) *xorm.Engine

Connector 获取指定连接器(引擎)

func CreateTable

func CreateTable(tabs ...IEntity) error

创建DBTables

func DeleteTable

func DeleteTable(tabs ...IEntity) error

清空DBTables

func DropTable

func DropTable(tbls ...IEntity) error

删除表(包括索引)

func ExistTable

func ExistTable(tbl IEntity) (bool, error)

检测表是否存在

func Install

func Install(confs []*Config) ctl.IControler

安装控制器

func MTable

func MTable(tbl IEntity) *table

主(Master) Table

func SQLExec

func SQLExec(tx *Session, query interface{}, args ...interface{}) (int64, error)

原生SQL执行(delete|update)[query:语句(支持?), args:语句参数]

func SQLExecute

func SQLExecute(dbName string, query interface{}, args ...interface{}) (int64, error)

原生SQL执行(delete|update)[query:语句(支持?), args:语句参数]

func SQLFind

func SQLFind(dbName string, rowsSlicePtr interface{}, query interface{}, args ...interface{}) error

原生SQL执行(multi)[rowsSlicePtr:输出slice或map, query:语句(支持?), args:语句参数]

func SQLFindPage

func SQLFindPage(dbName string, rowsSlicePtr interface{}, query interface{}, args ...interface{}) (int64, error)

原生SQL执行(page)[rowsSlicePtr:输出slice或map, query:语句(支持?), args:语句参数]

func SQLGet

func SQLGet(dbName string, beans []interface{}, query interface{}, args ...interface{}) (bool, error)

原生SQL执行(one)[beans:输出, query:语句(支持?), args:语句参数]

func STable

func STable(tbl IEntity) *table

从(Slave) Table

func SynchTable

func SynchTable(tbls ...IEntity) error

同步表结构

func TTable

func TTable(tx *Session, tbl IEntity) *table

事务(Transaction) Table

func Table

func Table(e EDB, tbl IEntity, tx ...*xorm.Session) *table

Types

type CondOpter

type CondOpter interface {
	ApplyOpt(s *xorm.Session) *xorm.Session
}

type CondOpterFunc

type CondOpterFunc func(s *xorm.Session) *xorm.Session

> 查询条件选项

func COAndOr

func COAndOr(e EAndOr, query string, args ...interface{}) CondOpterFunc

查询选项[SQL]-自定义SQL条件(支持?)

func COCompare

func COCompare(field string, e ECompare, val interface{}) CondOpterFunc

查询选项[ORM]-比较

func COGroup

func COGroup(fields ...string) CondOpterFunc

查询选项[ORM]-分组

func COHaving

func COHaving(selAlias string, e ECompare, val interface{}) CondOpterFunc

查询选项[ORM]-过滤 (selAlias:select 中的聚合别名)

func COInNotIn

func COInNotIn(field string, e EContain, args ...interface{}) CondOpterFunc

查询选项[ORM]-集合

func COLike

func COLike(field string, val string) CondOpterFunc

查询选项[ORM]-匹配

func COLimit

func COLimit(num int) CondOpterFunc

查询选项[ORM]-限量

func COOrder

func COOrder(e ESort, fields ...string) CondOpterFunc

查询选项[ORM]-排序

func COPage

func COPage(page, pnum int) CondOpterFunc

查询选项[ORM]-分页

func COWhere

func COWhere(query string, args ...interface{}) CondOpterFunc

查询选项[SQL]-自定义SQL条件(支持?)

func (CondOpterFunc) ApplyOpt

func (f CondOpterFunc) ApplyOpt(s *xorm.Session) *xorm.Session

type Config

type Config struct {
	Name    string `json:"name"`
	Host    string `json:"host"`
	Store   string `json:"store"`
	User    string `json:"user"`
	Passwd  string `json:"passwd"`
	IdleMax int64  `json:"idle_max"`
	OpenMax int64  `json:"open_max"`
	ShowSql bool   `json:"show_sql"`
}

> DB配置

type EAndOr

type EAndOr int //

> 并且或者

const (
	EAO_And EAndOr = iota + 1 // and
	EAO_Or                    // or
)

type ECompare

type ECompare int //

> 比较类型

const (
	ECompare_LT   ECompare = iota + 1 // <  value
	ECompare_LTE                      // <= value
	ECompare_GT                       // >  value
	ECompare_GTE                      // >= value
	ECompare_NotE                     // != value
	ECompare_EQ                       // = value
)

func (ECompare) String

func (e ECompare) String() string

type EContain

type EContain int //

> 集合包含

const (
	EContain_In    EContain = iota + 1 // in
	EContain_NotIn                     // not in
)

type EDB

type EDB int //

> Engine类型

const (
	EDB_Maste EDB = iota + 1 // 主库
	EDB_Slave                // 从库
)

type ESort

type ESort int //

> 排序类型

const (
	ESort_Asc  ESort = iota + 1 // 正序 从小到大
	ESort_Desc                  // 倒序 从大到小
)

type IContrler

type IContrler interface {
	ctl.IControler

	// 使用指定DB引擎
	Use(name string) *xorm.Engine

	// 表存在不存在
	Exist(name string, tbl IEntity) (bool, error)

	// 同步表结构
	Sync(name string, tbls ...IEntity) error

	// 移除表
	Drop(name string, tbls ...IEntity) error
}

控制器接口

var Ctl IContrler // 默认DB控制器

func Controller

func Controller() IContrler

type IEntity

type IEntity interface {

	// 连接名
	DBName(e EDB) string

	// 表名
	TableName() string
}

> 实体接口

type IFieldData

type IFieldData = core.Conversion

> DB表字段字节数据转换接口

type Join

type Join struct {
	Type      string      // INNER(default)|LEFT JOIN|RIGHT JOIN
	Tablename interface{} // Tablename
	OnCond    string      //  eg: on detail.user_id = user.id
}

> join

type Session

type Session struct {
	*xorm.Session
	// contains filtered or unexported fields
}

事务类型

func Transation

func Transation(dbName string) *Session

创建事务(Transation session)(当不需要真正的事务时可以使用 mdb.TxNil)

func (*Session) Begin

func (tx *Session) Begin() error

事务开启和关闭(配合 defer)

func (*Session) Close

func (tx *Session) Close(err error)

func (*Session) Defer

func (tx *Session) Defer(f func())

添加 DeferFun when Commit

func (*Session) DeferBack

func (tx *Session) DeferBack(f func())

添加 DeferBackFun when Rollback

func (*Session) Error

func (tx *Session) Error(err error) error

设置错误

type XormLogger

type XormLogger struct {
	Lv      xlog.LogLevel
	ShowSql bool

} //

==================== XormLogger

func (*XormLogger) Debug

func (this *XormLogger) Debug(v ...interface{})

func (*XormLogger) Debugf

func (this *XormLogger) Debugf(format string, v ...interface{})

func (*XormLogger) Error

func (this *XormLogger) Error(v ...interface{})

func (*XormLogger) Errorf

func (this *XormLogger) Errorf(format string, v ...interface{})

func (*XormLogger) Info

func (this *XormLogger) Info(v ...interface{})

func (*XormLogger) Infof

func (this *XormLogger) Infof(format string, v ...interface{})

func (*XormLogger) IsShowSQL

func (this *XormLogger) IsShowSQL() bool

func (*XormLogger) Level

func (this *XormLogger) Level() xlog.LogLevel

func (*XormLogger) SetLevel

func (this *XormLogger) SetLevel(l xlog.LogLevel)

func (*XormLogger) ShowSQL

func (this *XormLogger) ShowSQL(show ...bool)

func (*XormLogger) Warn

func (this *XormLogger) Warn(v ...interface{})

func (*XormLogger) Warnf

func (this *XormLogger) Warnf(format string, v ...interface{})

Jump to

Keyboard shortcuts

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