Documentation ¶
Index ¶
- func Connect(configs ...*Config) (err error)
- func DB(alias ...string) *sqlx.DB
- func Delete(query string, args ...interface{}) (int64, error)
- func Exec(query string, args ...interface{}) (sql.Result, error)
- func GetError(code ErrorCode) error
- func Insert(query string, args ...interface{}) (int64, error)
- func InsertAll(query string, datas ...[]interface{}) error
- func Query(query string, args ...interface{}) (*sql.Rows, error)
- func QueryRow(query string, args ...interface{}) (*sql.Row, error)
- func Update(query string, args ...interface{}) (int64, error)
- type Builder
- func (builder *Builder) Add(data interface{}) (int64, error)
- func (builder *Builder) AddAll(datas ...interface{}) error
- func (builder *Builder) Delete() (int64, error)
- func (builder *Builder) Distinct(distinct bool) *Builder
- func (builder *Builder) Field(field ...string) *Builder
- func (builder *Builder) Find(dest interface{}) error
- func (builder *Builder) Group(cols ...string) *Builder
- func (builder *Builder) Having(having string) *Builder
- func (builder *Builder) Join(join Join) *Builder
- func (builder *Builder) LastSQL() string
- func (builder *Builder) Limit(rowCount, offset uint) *Builder
- func (builder *Builder) Order(order map[string]bool) *Builder
- func (builder *Builder) Select(dest interface{}) error
- func (builder *Builder) Table(tablename, alias string) *Builder
- func (builder *Builder) Union(selectSQL []string, all bool) *Builder
- func (builder *Builder) Update(data map[string]interface{}) (int64, error)
- func (builder *Builder) Where(condition string, args ...interface{}) *Builder
- type Config
- type Data
- type Error
- type ErrorCode
- type IDB
- type IModel
- type ITable
- type JOINTYPE
- type Join
- type Limit
- type Order
- type SQLBuilder
- type SQLTYPE
- type Table
- type Union
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Insert ¶
Insert 插入数据操作 /mysqlgo.Insert("insert into user(username, password) values(?,?)", "admin", "123456")
func Query ¶
Query 原生查询多条数据操作 /mysqlgo.Query("select * from user where username = ? and status = ?", "admin", 1)
Types ¶
type Builder ¶
type Builder struct { SQLBuilder // contains filtered or unexported fields }
Builder Model Builder
func (*Builder) Order ¶
Order 对查询的结果排序 /For Example (id desc, name asc) => map { 'id' : true, 'name' : false}
type Config ¶
type Config struct { Alias string HostName string HostPort string DBName string UserName string Password string Charset string Prefix string MaxOpenConns int MaxIdleConns int MaxLifetime int Enable bool }
Config is database connection configuration
type ErrorCode ¶
type ErrorCode int
ErrorCode 错误信息编码
const ( //TypeError 类型错误 TypeError ErrorCode = 30001 //TableNull 表为空 TableNull ErrorCode = 40001 //FieldNull 字段为空 FieldNull ErrorCode = 40002 //WhereNull 条件为空 WhereNull ErrorCode = 40003 //SQLNull SQL为空 SQLNull ErrorCode = 40004 //ModelNull Model为空 ModelNull ErrorCode = 40005 //UsernameNull 用户名为空 UsernameNull ErrorCode = 40006 //HostNameNull hostname为空 HostNameNull ErrorCode = 40007 //DBNameNull 数据库名为空 DBNameNull ErrorCode = 40008 //ConfigNull 数据库配置为空 ConfigNull ErrorCode = 40009 //DBAliasNull 数据库别名为空 DBAliasNull ErrorCode = 40010 //HostPortNull hostport为空 HostPortNull ErrorCode = 40011 //KeyNull key为空 KeyNull ErrorCode = 40012 //DBNull DB为空 DBNull ErrorCode = 40013 //DataNull Data为空 DataNull ErrorCode = 40014 )
type Join ¶
Join 表之间关系 /Join语句,不用加join前缀 /Join类型,默认0 /0为INNER JOIN: 如果表中有至少一个匹配,则返回行,等同于 JOIN /1为LEFT JOIN: 即使右表中没有匹配,也从左表返回所有的行 /2为RIGHT JOIN: 即使左表中没有匹配,也从右表返回所有的行 /3为FULL JOIN: 只要其中一个表中存在匹配,就返回行
type SQLBuilder ¶
type SQLBuilder struct {
// contains filtered or unexported fields
}
SQLBuilder SQL生成工具类
func (*SQLBuilder) BuildSQL ¶
func (sql *SQLBuilder) BuildSQL(t SQLTYPE, data map[string]interface{}) string
BuildSQL 构造SQL
func (*SQLBuilder) Where ¶
func (sql *SQLBuilder) Where(condition string, args ...interface{})
Where add where
Click to show internal directories.
Click to hide internal directories.