Documentation ¶
Index ¶
- func Config(name ...string) *mysqlConfig
- func Exists(table interface{}, where ...interface{}) (bool, error)
- func Select(table string, fields []string, where []interface{}, order string) ([]xorm.Data, error)
- func SelectPage(table string, fields []string, where []interface{}, order string, ...) (rows []xorm.Data, count int64, pageCount int, err error)
- func SelectTop(table string, fields string, where []interface{}, order string, count int) ([]xorm.Data, error)
- type IMysqlClient
- type MysqlConfigType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exists ¶
检查数据库中是否存在记录
Example ¶
b, err := Exists("admins", "user_id", 1) fmt.Printf("result:%v err:%v\n", b, err)
Output:
func Select ¶
普通查询
Example ¶
rows1, err1 := Select("admins", []string{"*"}, []interface{}{"user_id", 1}, "") fmt.Printf("rows:%v, err:%v\n", xjson.ToString(rows1, "", "\t"), err1) rows2, count, pageCount, err2 := SelectPage("admins", []string{"*"}, []interface{}{"user_id", ">", 0}, "", 0, 10) fmt.Printf("rows:%v, count:%v, pagecount:%v, err:%v\n", xjson.ToString(rows2, "", "\t"), count, pageCount, err2) rows3, err3 := SelectTop("admins", "*", []interface{}{"user_id", ">", 0}, "", 10) fmt.Printf("rows:%v, error:%v", xjson.ToString(rows3, "", "\t"), err3)
Output:
Types ¶
type IMysqlClient ¶
type IMysqlClient interface { // 配置数据库连接 Config(c map[string]interface{}) error // 从文件加载数据库配置 ConfigFromFile(fileName string) error // 连接数据库 Open(cfg ...interface{}) error // 关闭数据库连接 Close() error // 获取数据库连接操作会话 DB() xorm.IOrm // 获取数据库连接配置 GetConfig(configType ...MysqlConfigType) interface{} FullTableName(tableName string) string }
mysql客户端接口
type MysqlConfigType ¶
type MysqlConfigType string
const MYSQL_CONFIG_TYPE_CLUSTER MysqlConfigType = "cluster"
数据库集群配置类型
const MYSQL_CONFIG_TYPE_SINGLE MysqlConfigType = "single"
单数据库配置类型
Click to show internal directories.
Click to hide internal directories.