yeesql

package
v0.0.0-...-fce8f56 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeginTx

func BeginTx() (*yeeTx, error)

func ClearRegisterTable

func ClearRegisterTable()

ClearRegisterTable 清除系统中注册的全部数据库表 不能并发调用

func Debug

func Debug(b bool)

设置是否打印sql语句,默认不打印

func DeleteByID

func DeleteByID(tableName, fieldName, value string) error

DeleteByID 通过字段删除某条值

func Exec

func Exec(query string, args ...interface{}) (sql.Result, error)

Exec 执行语句

func GetAllInTable

func GetAllInTable(tableName string) ([]map[string]string, error)

GetAllInTable 获取表中全部数据

func GetDb

func GetDb() *sqlx.DB

func GetDbWithoutDbName

func GetDbWithoutDbName() *sqlx.DB

func GetOneWhere

func GetOneWhere(tableName, fieldName, value string) (map[string]string, error)

GetOneWhere 通过某个字段的值查找一条数据

func InitDb

func InitDb()

InitDb 初始化DB

func InitDbWithoutDbName

func InitDbWithoutDbName()

func Insert

func Insert(tableName string, row map[string]string) (lastInsertID int, err error)

Insert 插入语句 通常返回的是主键的自增id

func IsExist

func IsExist(tableName string, row map[string]string) bool

IsExist 根据传入的map判断表中是否存在

func MustAddField

func MustAddField(table Table, filedName string)

MustAddField 添加字段

func MustCreateDb

func MustCreateDb()

MustCreateDb 根据传入的配置创建数据库DB

func MustCreateTable

func MustCreateTable(table Table)

MustCreateTable 根据table建表

CREATE TABLE IF NOT EXISTS `test`
(
	ID int(11) unsigned AUTO_INCREMENT,
	Name varchar(255) COLLATE utf8_bin DEFAULT "" NOT NULL,
	Account varchar(255) COLLATE utf8_bin DEFAULT "" NOT NULL,
	PRIMARY KEY (`ID`),
	UNIQUE INDEX (`Account`,`Name`)
) engine=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin

func MustDeleteByID

func MustDeleteByID(tableName, fieldName, value string)

func MustDropDb

func MustDropDb()

func MustDropTable

func MustDropTable(tableName string)

MustDropTable 删除表

func MustExec

func MustExec(query string, args ...interface{})

func MustForceModifyTable

func MustForceModifyTable(table Table)

MustForceModifyTable 强制更新

func MustForceSyncRegisterTable

func MustForceSyncRegisterTable()

MustForceSyncRegisterTable 强制同步注册进去的表(可能会缺失字段,保证字段达到配置的样子) 不能并发调用

func MustForceSyncTable

func MustForceSyncTable(table Table)

MustForceSyncTable 强制更新表 可能会缺失字段,保证字段达到配置的样子

func MustGetAllInTable

func MustGetAllInTable(tableName string) []map[string]string

func MustGetOneWhere

func MustGetOneWhere(tableName, fieldName, value string) map[string]string

func MustInsert

func MustInsert(tableName string, row map[string]string) (lastInsertID int)

func MustIsTableExist

func MustIsTableExist(tableName string) bool

MustIsTableExist 检测这个table是否存在

func MustModifyTable

func MustModifyTable(table Table)

MustModifyTable 更新表数据

func MustQuery

func MustQuery(query string, args ...interface{}) (output []map[string]string)

func MustQueryOne

func MustQueryOne(query string, args ...interface{}) map[string]string

func MustRegisterTable

func MustRegisterTable(table Table)

MustRegisterTable 向系统中注册表 不能重复注册 不能并发调用

func MustRunSelectCommand

func MustRunSelectCommand(selectCommand *ast.SelectCommand) (mapValue []map[string]string)

func MustSetDbConfig

func MustSetDbConfig(conf *DbConfig)

func MustSetTableDataToml

func MustSetTableDataToml(data string)

MustSetTableDataToml 为数据库table设置数据 toml格式 需要注意: 1.会清除表的数据 2.需要设置好自增字段的值(比数据库最大的+1)

func MustSyncRegisterTable

func MustSyncRegisterTable()

MustSyncRegisterTable 同步注册进去的表(只会增加字段,保证不掉数据,会使用fmt显示有哪些字段存在问题.) 不能并发调用

func MustSyncTable

func MustSyncTable(table Table)

MustSyncTable 同步更新表数据 只会增加字段,保证不掉数据,会使用fmt显示有哪些字段存在问题

func MustUpdateByID

func MustUpdateByID(tableName string, primaryKeyName string, row map[string]string)

func MustVerifyDbConfig

func MustVerifyDbConfig()

MustVerifyDbConfig 验证参数是否正确

func MustVerifyTableConfig

func MustVerifyTableConfig(table Table)

MustVerifyTableConfig 检测table的字段正确性,不能有重复字段(忽略大小写)

func Query

func Query(query string, args ...interface{}) (output []map[string]string, err error)

Query 查询语句

func QueryOne

func QueryOne(query string, args ...interface{}) (output map[string]string, err error)

QueryOne 查询一条数据 如果有多条,则返回第一条 找不到返回err

func RowsToMapSlice

func RowsToMapSlice(rows *sql.Rows) (output []map[string]string)

RowsToMapSlice 将*yeesql.Row读取到[]map[string]string

func RowsToMapSliceFirst

func RowsToMapSliceFirst(rows *sql.Rows) (map[string]string, error)

func RunSelectCommand

func RunSelectCommand(selectCommand *ast.SelectCommand) (mapValue []map[string]string, err error)

RunSelectCommand 执行一条selectCommand

func UpdateByID

func UpdateByID(tableName string, primaryKeyName string, row map[string]string) error

UpdateByID 通过primaryKeyName的值去更新数据 通常是主键id 假设通过id=5去更新,id=5这条数据不存在,返回nil,不会报错

Types

type DbConfig

type DbConfig struct {
	UserName string // 用户名 example: root
	Password string // 密码 example: password
	Host     string // 数据库主机地址 example: 127.0.0.1
	Port     string // 数据库端口 example: 3306
	DbName   string // 数据库名称 example: yee_test
}

DbConfig 数据库配置

func GetDbConfig

func GetDbConfig() DbConfig

func (*DbConfig) GetDsn

func (config *DbConfig) GetDsn() string

GetDsn

func (*DbConfig) GetDsnWithoutDbName

func (config *DbConfig) GetDsnWithoutDbName() string

GetDsnWithoutDbName

type DbType

type DbType string
const (
	DbTypeInt              DbType = `int(11) DEFAULT 0`
	DbTypeIntAutoIncrement DbType = `int(11) unsigned AUTO_INCREMENT`
	DbTypeString           DbType = `varchar(255) COLLATE utf8mb4_bin DEFAULT ""`
	DbTypeLongString       DbType = `longtext COLLATE utf8mb4_bin DEFAULT ""`
	DbTypeFloat            DbType = `float default 0`
	DbTypeDatetime         DbType = `datetime DEFAULT "1970-01-01 00:08:00"`
	DbTypeBool             DbType = `tinyint(4) DEFAULT 0`
	DbTypeLongBlob         DbType = `LONGBLOB`
)

func (DbType) GetMysqlFieldType

func (t DbType) GetMysqlFieldType() MysqlFieldType

type MysqlDataType

type MysqlDataType string
const (
	MysqlDataTypeVarchar  MysqlDataType = `varchar`
	MysqlDataTypeInt32    MysqlDataType = `int`
	MysqlDataTypeLongText MysqlDataType = `longtext`
	MysqlDataTypeFloat    MysqlDataType = `float`
	MysqlDataTypeDateTime MysqlDataType = `datetime`
	MysqlDataTypeInt8     MysqlDataType = `tinyint`
	MysqlDataTypeLongBlob MysqlDataType = `longblob`
)

type MysqlField

type MysqlField struct {
	Name string
	Type MysqlFieldType
}

type MysqlFieldType

type MysqlFieldType struct {
	DataType         MysqlDataType
	IsUnsigned       bool
	IsAutoIncrement  bool
	CharacterSetName string //utf8
	CollationName    string //utf8_bin
	Default          string
	StringLength     int
}

func (MysqlFieldType) Equal

func (t1 MysqlFieldType) Equal(t2 MysqlFieldType) bool

func (MysqlFieldType) String

func (t1 MysqlFieldType) String() string

type Table

type Table struct {
	Name       string
	FieldList  map[string]DbType
	PrimaryKey string
	UniqueKey  [][]string
	NotNull    []string
}

读取数据库的表字段,不区分大小写(某些系统的mysql不区分大小写) 写入数据库的表字段,区分大小写

func RegisterTables

func RegisterTables() []Table

RegisterTables 获取已注册的表

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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