Documentation ¶
Overview ¶
* * sql builder for mysql
Index ¶
- Constants
- Variables
- func IfcToSqlValue(ifc interface{}) string
- func Init(cim ConnConfig, km map[string]string) (err error)
- func InitWithFile(file string) (err error)
- func InterfaceToInt(ifc interface{}) (value int, stype uint8)
- func InterfaceToString(ifc interface{}) (value string, stype uint8)
- func RegisterModel(model interface{})
- func ShowColumns(db, table string) string
- func ToCamel(underlined string) string
- func ToUnderline(cameled string) string
- type ApdGroup
- type ApdLimit
- type ApdOrder
- type Appends
- type BaseModel
- func (this *BaseModel) DbName() string
- func (this *BaseModel) Delete(condition ICondition) int
- func (this *BaseModel) IRowToConds(irow IRow) *Condition
- func (this *BaseModel) IRowToFields(irow IRow) *FieldsWrite
- func (this *BaseModel) IRowsToFieldsMI(irows []IRow) *FieldsMultiInsert
- func (this *BaseModel) Insert(fields IFields) int
- func (this *BaseModel) InsertOrUpdate(fields IFields) int
- func (this *BaseModel) LastSql() string
- func (this *BaseModel) MultiInsert(fields IFields) int
- func (this *BaseModel) PartitionKey() []string
- func (this *BaseModel) Read(irow IRow) bool
- func (this *BaseModel) ReadMulti(result []IRow, cond IRow) bool
- func (this *BaseModel) Remove(irow IRow) int
- func (this *BaseModel) Save(irow IRow) int
- func (this *BaseModel) SaveMulti(irows []IRow) int
- func (this *BaseModel) Select(condition ICondition, appends IAppends, fields IFields) bool
- func (this *BaseModel) TableName(elems ...ISqlElem) string
- func (this *BaseModel) Update(fields IFields, condition ICondition) int
- type ColumnInfo
- type Condition
- func (this *Condition) AddConds(c ICondition) *Condition
- func (this *Condition) Between(column string, start, end interface{}) *Condition
- func (this *Condition) Columns() []string
- func (this *Condition) Del(key string) bool
- func (this *Condition) Equal(column string, value interface{}) *Condition
- func (this *Condition) Get(key string) (value interface{}, exist bool)
- func (this *Condition) GetSql() string
- func (this *Condition) In(column string, elements ...interface{}) *Condition
- func (this *Condition) InitWithMap(condMap map[string]interface{}) *Condition
- func (this *Condition) InitWithSlice(columns []string, values []interface{}) *Condition
- func (this *Condition) Like(column string, value string) *Condition
- func (this *Condition) Op(column string, value interface{}, op string) *Condition
- func (this *Condition) Values() []interface{}
- type Conn
- func (this *Conn) Begin() error
- func (this *Conn) Close() error
- func (this *Conn) Commit() error
- func (this *Conn) Exec(query string, args ...interface{}) int
- func (this *Conn) Prepare(query string) *sql.Stmt
- func (this *Conn) Query(query string, args ...interface{}) (columns []string, rrows []RawRow)
- func (this *Conn) Rollback() error
- type ConnConfig
- type ConnInfo
- type ExprBetween
- type ExprEqual
- type ExprIn
- type ExprLike
- type ExprOp
- type Field
- type FieldsMultiInsert
- func (this *FieldsMultiInsert) AddMap(fields map[string]interface{}) *FieldsMultiInsert
- func (this *FieldsMultiInsert) AddSlice(values []interface{}, columns ...string) *FieldsMultiInsert
- func (this *FieldsMultiInsert) Columns() []string
- func (this *FieldsMultiInsert) Del(key string) bool
- func (this *FieldsMultiInsert) Get(key string) (value interface{}, exist bool)
- func (this *FieldsMultiInsert) GetSql() string
- func (this *FieldsMultiInsert) InitWithMap(fields map[string]interface{}) *FieldsMultiInsert
- func (this *FieldsMultiInsert) InitWithSlice(columns []string, values []interface{}) *FieldsMultiInsert
- func (this *FieldsMultiInsert) Values() []interface{}
- type FieldsRead
- func (this *FieldsRead) Add(column string) *FieldsRead
- func (this *FieldsRead) Columns() []string
- func (this *FieldsRead) Del(key string) bool
- func (this *FieldsRead) Get(key string) (value interface{}, exist bool)
- func (this *FieldsRead) GetSql() string
- func (this *FieldsRead) Values() []interface{}
- type FieldsWrite
- func (this *FieldsWrite) Add(key string, value interface{}) *FieldsWrite
- func (this *FieldsWrite) AddSpl(key string, value interface{}, typ pSqlType) *FieldsWrite
- func (this *FieldsWrite) Columns() []string
- func (this *FieldsWrite) Del(key string) bool
- func (this *FieldsWrite) Get(key string) (value interface{}, exist bool)
- func (this *FieldsWrite) GetSql() string
- func (this *FieldsWrite) InitWithMap(fields map[string]interface{}) *FieldsWrite
- func (this *FieldsWrite) InitWithSlice(columns []string, values []interface{}) *FieldsWrite
- func (this *FieldsWrite) Values() []interface{}
- type IAppends
- type ICondition
- type IConn
- type IFields
- type IModel
- type IRow
- type ISqlBuilder
- type ISqlElem
- type ISubExpr
- type MysqlBuilder
- func (this *MysqlBuilder) Delete(condition ICondition) string
- func (this *MysqlBuilder) Insert(fields IFields) string
- func (this *MysqlBuilder) InsertOrUpdate(fields IFields) string
- func (this *MysqlBuilder) MultiInsert(fields IFields) string
- func (this *MysqlBuilder) Select(fields IFields, condition ICondition, appends IAppends) string
- func (this *MysqlBuilder) Update(fields IFields, condition ICondition) string
- type MysqlConn
- type RawRow
- type TableInfo
Constants ¶
View Source
const ( DEFAULT direct = 0 ASC direct = 1 DESC direct = -1 )
View Source
const ( AND = `AND` OR = `OR` )
View Source
const (
CONFIG_DB_MAPPING = `db-mapping`
)
Variables ¶
View Source
var (
NewConn func(*ConnInfo) IConn = NewMysqlConn
)
View Source
var (
NewSqlBuilder = NewMysqlBuilder
)
Functions ¶
func IfcToSqlValue ¶
func IfcToSqlValue(ifc interface{}) string
func InterfaceToInt ¶
not support int8/uint8 please use int16/uint16
func InterfaceToString ¶
not support int8/uint8 please use int16/uint16
func ShowColumns ¶
func ToUnderline ¶
convert camel string to underlined, XxYy to xx_yy
Types ¶
type Appends ¶
type Appends struct {
// contains filtered or unexported fields
}
func NewAppends ¶
func NewAppends() *Appends
type BaseModel ¶
type BaseModel struct { IModel // contains filtered or unexported fields }
func (*BaseModel) Delete ¶
func (this *BaseModel) Delete(condition ICondition) int
func (*BaseModel) IRowToConds ¶
func (*BaseModel) IRowToFields ¶
func (this *BaseModel) IRowToFields(irow IRow) *FieldsWrite
func (*BaseModel) IRowsToFieldsMI ¶
func (this *BaseModel) IRowsToFieldsMI(irows []IRow) *FieldsMultiInsert
func (*BaseModel) InsertOrUpdate ¶
func (*BaseModel) MultiInsert ¶
func (*BaseModel) PartitionKey ¶
type ColumnInfo ¶
type ColumnInfo struct {
// contains filtered or unexported fields
}
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
func NewCondsOr ¶
func NewCondsOr() *Condition
func (*Condition) AddConds ¶
func (this *Condition) AddConds(c ICondition) *Condition
func (*Condition) InitWithMap ¶
func (*Condition) InitWithSlice ¶
type ConnConfig ¶
type ConnInfo ¶
type ConnInfo struct {
// contains filtered or unexported fields
}
func NewConnInfo ¶
type ExprBetween ¶
type ExprBetween struct {
// contains filtered or unexported fields
}
func (*ExprBetween) Column ¶
func (this *ExprBetween) Column() string
func (*ExprBetween) Sql ¶
func (this *ExprBetween) Sql(prepare bool) string
func (*ExprBetween) Values ¶
func (this *ExprBetween) Values() []interface{}
type FieldsMultiInsert ¶
type FieldsMultiInsert struct {
// contains filtered or unexported fields
}
func (*FieldsMultiInsert) AddMap ¶
func (this *FieldsMultiInsert) AddMap(fields map[string]interface{}) *FieldsMultiInsert
增加一条记录。需要处理fields中字段数量跟现有字段数量不匹配的情况。
func (*FieldsMultiInsert) AddSlice ¶
func (this *FieldsMultiInsert) AddSlice(values []interface{}, columns ...string) *FieldsMultiInsert
增加一条记录,
func (*FieldsMultiInsert) Columns ¶
func (this *FieldsMultiInsert) Columns() []string
func (*FieldsMultiInsert) Del ¶
func (this *FieldsMultiInsert) Del(key string) bool
func (*FieldsMultiInsert) Get ¶
func (this *FieldsMultiInsert) Get(key string) (value interface{}, exist bool)
func (*FieldsMultiInsert) GetSql ¶
func (this *FieldsMultiInsert) GetSql() string
func (*FieldsMultiInsert) InitWithMap ¶
func (this *FieldsMultiInsert) InitWithMap(fields map[string]interface{}) *FieldsMultiInsert
func (*FieldsMultiInsert) InitWithSlice ¶
func (this *FieldsMultiInsert) InitWithSlice(columns []string, values []interface{}) *FieldsMultiInsert
func (*FieldsMultiInsert) Values ¶
func (this *FieldsMultiInsert) Values() []interface{}
type FieldsRead ¶
type FieldsRead struct {
// contains filtered or unexported fields
}
func NewFieldsRead ¶
func NewFieldsRead(columns ...string) *FieldsRead
func (*FieldsRead) Add ¶
func (this *FieldsRead) Add(column string) *FieldsRead
func (*FieldsRead) Columns ¶
func (this *FieldsRead) Columns() []string
func (*FieldsRead) Del ¶
func (this *FieldsRead) Del(key string) bool
func (*FieldsRead) Get ¶
func (this *FieldsRead) Get(key string) (value interface{}, exist bool)
func (*FieldsRead) GetSql ¶
func (this *FieldsRead) GetSql() string
func (*FieldsRead) Values ¶
func (this *FieldsRead) Values() []interface{}
type FieldsWrite ¶
type FieldsWrite struct {
// contains filtered or unexported fields
}
func NewFieldsWrite ¶
func NewFieldsWrite() *FieldsWrite
func (*FieldsWrite) Add ¶
func (this *FieldsWrite) Add(key string, value interface{}) *FieldsWrite
func (*FieldsWrite) AddSpl ¶
func (this *FieldsWrite) AddSpl(key string, value interface{}, typ pSqlType) *FieldsWrite
func (*FieldsWrite) Columns ¶
func (this *FieldsWrite) Columns() []string
func (*FieldsWrite) Del ¶
func (this *FieldsWrite) Del(key string) bool
func (*FieldsWrite) Get ¶
func (this *FieldsWrite) Get(key string) (value interface{}, exist bool)
func (*FieldsWrite) GetSql ¶
func (this *FieldsWrite) GetSql() string
func (*FieldsWrite) InitWithMap ¶
func (this *FieldsWrite) InitWithMap(fields map[string]interface{}) *FieldsWrite
func (*FieldsWrite) InitWithSlice ¶
func (this *FieldsWrite) InitWithSlice(columns []string, values []interface{}) *FieldsWrite
func (*FieldsWrite) Values ¶
func (this *FieldsWrite) Values() []interface{}
type ICondition ¶
type IConn ¶
type IConn interface { Query(sql string, args ...interface{}) (columns []string, rrows []RawRow) Exec(sql string, args ...interface{}) int Prepare(query string) *sql.Stmt Begin() error Rollback() error Commit() error Close() error }
func NewMysqlConn ¶
type IModel ¶
type IModel interface { DbName() string TableName(elems ...ISqlElem) string PartitionKey() []string //分表的字段,如果没有则返回空 CreateRow() IRow ResetResult() }
*
- 对应一个表
type IRow ¶
type IRow interface { Set(key string, val []byte) error Get(key string) interface{} Columns() []string }
*
- 对应表中的一行,以及代码中的一个对象
type ISqlBuilder ¶
type ISqlBuilder interface { Select(fields IFields, condition ICondition, appends IAppends) string Insert(fields IFields) string InsertOrUpdate(fields IFields) string MultiInsert(fields IFields) string Update(fields IFields, condition ICondition) string Delete(condition ICondition) string }
func NewMysqlBuilder ¶
func NewMysqlBuilder(db, table string) ISqlBuilder
type MysqlBuilder ¶
type MysqlBuilder struct {
// contains filtered or unexported fields
}
func (*MysqlBuilder) Delete ¶
func (this *MysqlBuilder) Delete(condition ICondition) string
func (*MysqlBuilder) Insert ¶
func (this *MysqlBuilder) Insert(fields IFields) string
func (*MysqlBuilder) InsertOrUpdate ¶
func (this *MysqlBuilder) InsertOrUpdate(fields IFields) string
func (*MysqlBuilder) MultiInsert ¶
func (this *MysqlBuilder) MultiInsert(fields IFields) string
func (*MysqlBuilder) Select ¶
func (this *MysqlBuilder) Select(fields IFields, condition ICondition, appends IAppends) string
func (*MysqlBuilder) Update ¶
func (this *MysqlBuilder) Update(fields IFields, condition ICondition) string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.