xmysql

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config(name ...string) *mysqlConfig

获取mysql数据库配置

func Exists

func Exists(table interface{}, where ...interface{}) (bool, error)

检查数据库中是否存在记录

Example
b, err := Exists("admins", "user_id", 1)
fmt.Printf("result:%v err:%v\n", b, err)
Output:

func Select

func Select(table string, fields []string, where []interface{}, order string) ([]xorm.Data, error)

普通查询

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:

func SelectPage

func SelectPage(table string, fields []string, where []interface{}, order string, pageIndex, pageSize int) (rows []xorm.Data, count int64, pageCount int, err error)

分页查询

func SelectTop

func SelectTop(table string, fields string, where []interface{}, order string, count int) ([]xorm.Data, error)

获取指定条数的记录

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客户端接口

func InitMySql

func InitMySql(c *gcfg.Config) (IMysqlClient, error)

初始化mysql数据库

func Mysql

func Mysql(name ...string) IMysqlClient

mysql单一实例

type MysqlConfigType

type MysqlConfigType string
const MYSQL_CONFIG_TYPE_CLUSTER MysqlConfigType = "cluster"

数据库集群配置类型

const MYSQL_CONFIG_TYPE_SINGLE MysqlConfigType = "single"

单数据库配置类型

Jump to

Keyboard shortcuts

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