sqld

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SAVE          = 1
	UPDATE        = 2
	DELETE        = 3
	UPDATE_BY_CND = 4
)
View Source
const (
	JID      = "id"
	BID      = "_id"
	COUNT_BY = "COUNT_BY"
)

Variables

View Source
var (
	ZERO  = int64(0)
	TRUE  = true
	FALSE = false
)

Functions

func GetValue

func GetValue(obj interface{}, elem *FieldElem) (interface{}, error)

func Model

func Model(v interface{}) func() interface{}

func ModelDriver

func ModelDriver(objects ...sqlc.Object) error

func OutDest

func OutDest(rows *sql.Rows, flen int) ([][][]byte, error)

输出查询结果集

func SetValue

func SetValue(obj interface{}, elem *FieldElem, b []byte) error

Types

type CountResult

type CountResult struct {
	Total int64 `bson:"COUNT_BY"`
}

type DBConfig

type DBConfig struct {
	Option
	Host        string // 地址IP
	Port        int    // 数据库端口
	Username    string // 账号
	Password    string // 密码
	SlowQuery   int64  // 0.不开启筛选 >0开启筛选查询 毫秒
	SlowLogPath string // 慢查询写入地址
}

数据库配置

type DBManager

type DBManager struct {
	Option
	CacheManager cache.Cache    // 缓存管理器
	MGOSyncData  []*MGOSyncData // 同步数据对象
	Errors       []error        // 错误异常记录
}

数据库管理器

func (*DBManager) BuilGroupBy

func (self *DBManager) BuilGroupBy(cnd *sqlc.Cnd) string

func (*DBManager) BuilSortBy

func (self *DBManager) BuilSortBy(cnd *sqlc.Cnd) string

func (*DBManager) BuildCondKey

func (self *DBManager) BuildCondKey(cnd *sqlc.Cnd, key string) []byte

func (*DBManager) BuildPagination

func (self *DBManager) BuildPagination(cnd *sqlc.Cnd, sql string, values []interface{}) (string, error)

func (*DBManager) BuildWhereCase

func (self *DBManager) BuildWhereCase(cnd *sqlc.Cnd) (*bytes.Buffer, []interface{})

func (*DBManager) Close

func (self *DBManager) Close() error

func (*DBManager) Count

func (self *DBManager) Count(cnd *sqlc.Cnd) (int64, error)

func (*DBManager) Delete

func (self *DBManager) Delete(datas ...sqlc.Object) error

func (*DBManager) Error

func (self *DBManager) Error(data ...interface{}) error

func (*DBManager) FindById

func (self *DBManager) FindById(data sqlc.Object) error

func (*DBManager) FindList

func (self *DBManager) FindList(cnd *sqlc.Cnd, data interface{}) error

func (*DBManager) FindListComplex

func (self *DBManager) FindListComplex(cnd *sqlc.Cnd, data interface{}) error

func (*DBManager) FindOne

func (self *DBManager) FindOne(cnd *sqlc.Cnd, data sqlc.Object) error

func (*DBManager) FindOneComplex

func (self *DBManager) FindOneComplex(cnd *sqlc.Cnd, data sqlc.Object) error

func (*DBManager) GetDB

func (self *DBManager) GetDB(option ...Option) error

func (*DBManager) InitConfig

func (self *DBManager) InitConfig(input interface{}) error

func (*DBManager) Save

func (self *DBManager) Save(datas ...sqlc.Object) error

func (*DBManager) Update

func (self *DBManager) Update(datas ...sqlc.Object) error

func (*DBManager) UpdateByCnd

func (self *DBManager) UpdateByCnd(cnd *sqlc.Cnd) error

type FieldElem

type FieldElem struct {
	Primary       bool
	Ignore        bool
	IsDate        bool
	FieldName     string
	FieldJsonName string
	FieldBsonName string
	FieldKind     reflect.Kind
	FieldType     string
	ValueKind     interface{}
	FieldDBType   string
	FieldOffset   uintptr
}

type IDBase

type IDBase interface {
	// 初始化数据库配置
	InitConfig(input interface{}) error
	// 获取数据库管理器
	GetDB(option ...Option) error
	// 保存数据
	Save(datas ...sqlc.Object) error
	// 更新数据
	Update(datas ...sqlc.Object) error
	// 按条件更新数据
	UpdateByCnd(cnd *sqlc.Cnd) error
	// 删除数据
	Delete(datas ...sqlc.Object) error
	// 统计数据
	Count(cnd *sqlc.Cnd) (int64, error)
	// 按ID查询单条数据
	FindById(data sqlc.Object) error
	// 按条件查询单条数据
	FindOne(cnd *sqlc.Cnd, data sqlc.Object) error
	// 按条件查询数据
	FindList(cnd *sqlc.Cnd, data interface{}) error
	// 按复杂条件查询数据
	FindOneComplex(cnd *sqlc.Cnd, data sqlc.Object) error
	// 按复杂条件查询数据列表
	FindListComplex(cnd *sqlc.Cnd, data interface{}) error
	// 构建数据表别名
	BuildCondKey(cnd *sqlc.Cnd, key string) []byte
	// 构建逻辑条件
	BuildWhereCase(cnd *sqlc.Cnd) (*bytes.Buffer, []interface{})
	// 构建分组条件
	BuilGroupBy(cnd *sqlc.Cnd) string
	// 构建排序条件
	BuilSortBy(cnd *sqlc.Cnd) string
	// 构建分页条件
	BuildPagination(cnd *sqlc.Cnd, sql string, values []interface{}) (string, error)
	// 数据库操作缓存异常
	Error(data ...interface{}) error
}

orm数据库接口

type MGOConfig

type MGOConfig struct {
	DBConfig
	Addrs          []string
	Direct         bool
	ConnectTimeout int64
	SocketTimeout  int64
	Database       string
	Username       string
	Password       string
	PoolLimit      int
	ConnectionURI  string
}

数据库配置

type MGOManager

type MGOManager struct {
	DBManager
	Session *mgo.Session
}

数据库管理器

func NewMongo

func NewMongo(option ...Option) (*MGOManager, error)

func (*MGOManager) Close

func (self *MGOManager) Close() error

func (*MGOManager) Count

func (self *MGOManager) Count(cnd *sqlc.Cnd) (int64, error)

func (*MGOManager) Delete

func (self *MGOManager) Delete(data ...sqlc.Object) error

func (*MGOManager) FindList

func (self *MGOManager) FindList(cnd *sqlc.Cnd, data interface{}) error

查询多条数据

func (*MGOManager) FindOne

func (self *MGOManager) FindOne(cnd *sqlc.Cnd, data sqlc.Object) error

func (*MGOManager) Get

func (self *MGOManager) Get(option ...Option) (*MGOManager, error)

func (*MGOManager) GetDB

func (self *MGOManager) GetDB(options ...Option) error

func (*MGOManager) GetDatabase

func (self *MGOManager) GetDatabase(copySession *mgo.Session, tb string) (*mgo.Collection, error)

获取mongo的数据库连接

func (*MGOManager) InitConfig

func (self *MGOManager) InitConfig(input ...MGOConfig) error

func (*MGOManager) InitConfigAndCache

func (self *MGOManager) InitConfigAndCache(manager cache.Cache, input ...MGOConfig) error

func (*MGOManager) Save

func (self *MGOManager) Save(data ...sqlc.Object) error

保存数据到mongo集合

func (*MGOManager) Update

func (self *MGOManager) Update(data ...sqlc.Object) error

更新数据到mongo集合

func (*MGOManager) UpdateByCnd

func (self *MGOManager) UpdateByCnd(cnd *sqlc.Cnd) error

根据条件更新数据

type MGOSyncData

type MGOSyncData struct {
	CacheOption int           // 1.save 2.update 3.delete
	CacheModel  sqlc.Object   // 对象模型
	CacheCnd    *sqlc.Cnd     // 需要缓存的数据 CacheSync为true时有效
	CacheObject []sqlc.Object // 需要缓存的数据 CacheSync为true时有效
}

type MdlDriver

type MdlDriver struct {
	//Hook       Hook
	TableName  string
	ToMongo    bool
	PkOffset   uintptr
	PkKind     reflect.Kind
	PkName     string
	PkBsonName string
	FieldElem  []*FieldElem
}

type MysqlConfig

type MysqlConfig struct {
	DBConfig
	MaxIdleConns    int
	MaxOpenConns    int
	ConnMaxLifetime int
	ConnMaxIdleTime int
}

mysql配置参数

type MysqlManager

type MysqlManager struct {
	RDBManager
}

mysql连接管理器

func NewMysql

func NewMysql(option ...Option) (*MysqlManager, error)

func (*MysqlManager) Get

func (self *MysqlManager) Get(option ...Option) (*MysqlManager, error)

func (*MysqlManager) InitConfig

func (self *MysqlManager) InitConfig(input ...MysqlConfig) error

func (*MysqlManager) InitConfigAndCache

func (self *MysqlManager) InitConfigAndCache(manager cache.Cache, input ...MysqlConfig) error

type Option

type Option struct {
	DsName      string // 数据源,分库时使用
	Database    string // 数据库名称
	OpenTx      bool   // 是否开启事务 true.是 false.否
	MongoSync   bool   // 是否自动同步mongo数据库写入
	Timeout     int64  // 请求超时设置/毫秒,默认10000
	SlowQuery   int64  // 0.不开启筛选 >0开启筛选查询 毫秒
	SlowLogPath string // 慢查询写入地址
}

数据选项

type RDBManager

type RDBManager struct {
	DBManager
	Db *sql.DB
	Tx *sql.Tx
}

关系数据库连接管理器

func (*RDBManager) BuilGroupBy

func (self *RDBManager) BuilGroupBy(cnd *sqlc.Cnd) string

构建分组命令

func (*RDBManager) BuilSortBy

func (self *RDBManager) BuilSortBy(cnd *sqlc.Cnd) string

构建排序命令

func (*RDBManager) BuildCondKey

func (self *RDBManager) BuildCondKey(cnd *sqlc.Cnd, key string) []byte

func (*RDBManager) BuildPagination

func (self *RDBManager) BuildPagination(cnd *sqlc.Cnd, sqlbuf string, values []interface{}) (string, error)

构建分页命令

func (*RDBManager) BuildWhereCase

func (self *RDBManager) BuildWhereCase(cnd *sqlc.Cnd) (*bytes.Buffer, []interface{})

构建where条件

func (*RDBManager) Close

func (self *RDBManager) Close() error

func (*RDBManager) Count

func (self *RDBManager) Count(cnd *sqlc.Cnd) (int64, error)

func (*RDBManager) Delete

func (self *RDBManager) Delete(data ...sqlc.Object) error

func (*RDBManager) FindById

func (self *RDBManager) FindById(data sqlc.Object) error

func (*RDBManager) FindList

func (self *RDBManager) FindList(cnd *sqlc.Cnd, data interface{}) error

func (*RDBManager) FindListComplex

func (self *RDBManager) FindListComplex(cnd *sqlc.Cnd, data interface{}) error

func (*RDBManager) FindOne

func (self *RDBManager) FindOne(cnd *sqlc.Cnd, data sqlc.Object) error

func (*RDBManager) FindOneComplex

func (self *RDBManager) FindOneComplex(cnd *sqlc.Cnd, data sqlc.Object) error

func (*RDBManager) GetDB

func (self *RDBManager) GetDB(options ...Option) error

func (*RDBManager) Save

func (self *RDBManager) Save(data ...sqlc.Object) error

func (*RDBManager) Update

func (self *RDBManager) Update(data ...sqlc.Object) error

func (*RDBManager) UpdateByCnd

func (self *RDBManager) UpdateByCnd(cnd *sqlc.Cnd) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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