dao

package
v0.0.0-...-1eded09 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: GPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChDocu

type ChDocu struct {
	Uid   int
	Email string
}

type DBConf

type DBConf struct {
	Client Machine
	// User 用户名
	User string
	// Password 密码
	Password  string
	Databases []string
	FromHost  []string
	Keys      []string
	Tables    map[string]interface{}
	Dbtype    DbType
	Sql       SqlType
}

func GetAllSqlInfo

func GetAllSqlInfo() (allConfig []*DBConf, err error)

type DbType

type DbType int
const (
	Mysqlexport DbType = 1 << iota
	Mysqlimport
	Mongoexport
	Mongoimport
	UnKnowType
)

type IMongoDao

type IMongoDao interface {
	ConnectMongo(dt DbType) (err error)
	DisconnectMongo(dt DbType)
	GetHosts(dt DbType) (hosts []Machine)
	GetHostConf(dt DbType, host Machine) *DBConf
	UseDatabase(host Machine, dbname string) (db *mongo.Database, err error)
	GetCollectionData(host Machine, db string, coll string, value []int64) (result []bson.M, err error)
	GetDataByUniqueKey(host Machine, db string, coll string, key string, value string) (result []bson.M, err error)
	UpdateData(host Machine, dbname string, collection string, srcUid int64, dstUid int64) error
	InsertData(host Machine, c string, dbname string, doc interface{}) error
	DeleteData(host Machine, dbname, collection string, u int64) error
	ImportByJsfile(host Machine, jsfile *os.File, dbname string) error
	GetHostTable(dt DbType, host Machine, key string) (tables map[string]interface{}, err error)
	GetHostDatabseInfo(dt DbType, host Machine) (databases []string, u string, p string, err error)
}

type IMysqlDao

type IMysqlDao interface {
	ConnectMySql(dt DbType) (err error)
	DisconnectMysql(dt DbType)
	GetHosts(dt DbType) (hosts []Machine)
	SwitchDB(host Machine, dbName string)
	DisForeignKey(host Machine) error
	GetMysqlTableData(host Machine, table string, value []int64) (res []map[string]interface{}, err error)
	GetDataByUniqueKey(host Machine, table string, key string, value string) (res []map[string]interface{}, err error)
	ModifyData(host Machine, table string, field int64, uid int64) error
	ImportByShell(host Machine, dbname string, path string) error
	DeleteData(host Machine, table string, u int64) error
	GetConstraint(host Machine, dbname string, value []int64, path string) (err error)
	DeleteConstraint(host Machine, dbname string, uid []int64) (err error)
	GetHostConf(dt DbType, host Machine) *DBConf
	GetHostTable(dt DbType, host Machine, key string) (tables map[string]interface{}, err error)
	GetHostDatabseInfo(dt DbType, host Machine) (databases []string, u string, p string, err error)
}

实现这四个函数,用于封装服务

type Machine

type Machine struct {
	// Host 主机地址
	Host string
	// Port 主机端口
	Port string
}

type MongoDao

type MongoDao struct {
	Conf []*DBConf
}

func (*MongoDao) ConnectMongo

func (m *MongoDao) ConnectMongo(dt DbType) (err error)

ConnectMongo 连接所有的mongo server

func (*MongoDao) DeleteData

func (m *MongoDao) DeleteData(host Machine, dbname, collection string, u int64) error

func (*MongoDao) DisconnectMongo

func (m *MongoDao) DisconnectMongo(dt DbType)

func (*MongoDao) GetCollectionData

func (m *MongoDao) GetCollectionData(host Machine, db string, coll string, value []int64) (result []bson.M, err error)

GetCollectionData 获取collection中的数据

func (*MongoDao) GetDataByUniqueKey

func (m *MongoDao) GetDataByUniqueKey(host Machine, db string, coll string, key string, value string) (result []bson.M, err error)

func (*MongoDao) GetHostConf

func (m *MongoDao) GetHostConf(dt DbType, host Machine) *DBConf

func (*MongoDao) GetHostDatabseInfo

func (m *MongoDao) GetHostDatabseInfo(dt DbType, host Machine) (databases []string, u string, p string, err error)

func (*MongoDao) GetHostTable

func (m *MongoDao) GetHostTable(dt DbType, host Machine, key string) (tables map[string]interface{}, err error)

func (*MongoDao) GetHosts

func (m *MongoDao) GetHosts(dt DbType) (hosts []Machine)

GetHosts 获取某一类型的数据库server的所有ip以及port

func (*MongoDao) ImportByJsfile

func (m *MongoDao) ImportByJsfile(host Machine, jsfile *os.File, dbname string) error

func (*MongoDao) InsertData

func (m *MongoDao) InsertData(host Machine, c string, dbname string, doc interface{}) error

func (*MongoDao) UpdateData

func (m *MongoDao) UpdateData(host Machine, dbname string, collection string, srcUid int64, destUid int64) error

func (*MongoDao) UseDatabase

func (m *MongoDao) UseDatabase(host Machine, dbname string) (db *mongo.Database, err error)

Database 选择库

type MysqlDao

type MysqlDao struct {
	//DB   *sqlx.DB
	Conf []*DBConf
}

func (*MysqlDao) ConnectMySql

func (m *MysqlDao) ConnectMySql(dt DbType) (err error)

ConnectMysql 创建mysql的连接

func (*MysqlDao) DeleteConstraint

func (m *MysqlDao) DeleteConstraint(host Machine, dbname string, uid []int64) (err error)

func (*MysqlDao) DeleteData

func (m *MysqlDao) DeleteData(host Machine, table string, uid int64) error

func (*MysqlDao) DisForeignKey

func (m *MysqlDao) DisForeignKey(host Machine) error

DisForeignKey 禁用外键约束

func (*MysqlDao) DisconnectMysql

func (m *MysqlDao) DisconnectMysql(dt DbType)

func (*MysqlDao) GetConstraint

func (m *MysqlDao) GetConstraint(host Machine, dbname string, value []int64, path string) (err error)

GetConstraint 导出外键关联的数据

func (*MysqlDao) GetDataByUniqueKey

func (m *MysqlDao) GetDataByUniqueKey(host Machine, table string, key string, value string) (tableData []map[string]interface{}, err error)

func (*MysqlDao) GetHostConf

func (m *MysqlDao) GetHostConf(dt DbType, host Machine) *DBConf

func (*MysqlDao) GetHostDatabseInfo

func (m *MysqlDao) GetHostDatabseInfo(dt DbType, host Machine) (databases []string, u string, p string, err error)

func (*MysqlDao) GetHostTable

func (m *MysqlDao) GetHostTable(dt DbType, host Machine, key string) (tables map[string]interface{}, err error)

func (*MysqlDao) GetHosts

func (m *MysqlDao) GetHosts(dt DbType) (hosts []Machine)

func (*MysqlDao) GetMysqlTableData

func (m *MysqlDao) GetMysqlTableData(host Machine, table string, value []int64) (tableData []map[string]interface{}, err error)

GetMysqlTableData 获取table中符合要求的数据

func (*MysqlDao) ImportByShell

func (m *MysqlDao) ImportByShell(host Machine, dbname string, path string) error

func (*MysqlDao) ModifyData

func (m *MysqlDao) ModifyData(host Machine, table string, field int64, uid int64) (err error)

func (*MysqlDao) SwitchDB

func (m *MysqlDao) SwitchDB(host Machine, dbName string)

type SqlType

type SqlType struct {
	Mysql *sqlx.DB
	Mongo *mongo.Client
}

Jump to

Keyboard shortcuts

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