orm

package
v0.0.0-...-7f871ab Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2017 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

* * sql builder for mysql

Index

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
)
View Source
var ValidOp = map[string]bool{`>`: true, `>=`: true, `<`: true, `<=`: true}

Functions

func IfcToSqlValue

func IfcToSqlValue(ifc interface{}) string

func Init

func Init(cim ConnConfig, km map[string]string) (err error)

func InitWithFile

func InitWithFile(file string) (err error)

使用配置文件初始化orm

func InterfaceToInt

func InterfaceToInt(ifc interface{}) (value int, stype uint8)

not support int8/uint8 please use int16/uint16

func InterfaceToString

func InterfaceToString(ifc interface{}) (value string, stype uint8)

not support int8/uint8 please use int16/uint16

func RegisterModel

func RegisterModel(model interface{})

*

  • 注册model对象。通过model解析一些表+对象的信息

func ShowColumns

func ShowColumns(db, table string) string

func ToCamel

func ToCamel(underlined string) string

convert underlined string to camel, aa_bb to AaBb

func ToUnderline

func ToUnderline(cameled string) string

convert camel string to underlined, XxYy to xx_yy

Types

type ApdGroup

type ApdGroup struct {
	// contains filtered or unexported fields
}

func (*ApdGroup) Add

func (this *ApdGroup) Add(fields ...string)

func (*ApdGroup) GetSql

func (this *ApdGroup) GetSql() string

func (*ApdGroup) Values

func (this *ApdGroup) Values() []interface{}

type ApdLimit

type ApdLimit struct {
	// contains filtered or unexported fields
}

func (*ApdLimit) GetSql

func (this *ApdLimit) GetSql() string

func (*ApdLimit) Values

func (this *ApdLimit) Values() []interface{}

type ApdOrder

type ApdOrder struct {
	// contains filtered or unexported fields
}

func (*ApdOrder) Add

func (this *ApdOrder) Add(field string, d direct)

func (*ApdOrder) GetSql

func (this *ApdOrder) GetSql() string

func (*ApdOrder) Values

func (this *ApdOrder) Values() []interface{}

type Appends

type Appends struct {
	// contains filtered or unexported fields
}

func NewAppends

func NewAppends() *Appends

func (*Appends) GetSql

func (this *Appends) GetSql() string

func (*Appends) GroupBy

func (this *Appends) GroupBy(fields ...string) *Appends

func (*Appends) Limit

func (this *Appends) Limit(offset, num int) *Appends

func (*Appends) OrderBy

func (this *Appends) OrderBy(field string, d direct) *Appends

func (*Appends) Values

func (this *Appends) Values() []interface{}

type BaseModel

type BaseModel struct {
	IModel
	// contains filtered or unexported fields
}

func (*BaseModel) DbName

func (this *BaseModel) DbName() string

func (*BaseModel) Delete

func (this *BaseModel) Delete(condition ICondition) int

func (*BaseModel) IRowToConds

func (this *BaseModel) IRowToConds(irow IRow) *Condition

func (*BaseModel) IRowToFields

func (this *BaseModel) IRowToFields(irow IRow) *FieldsWrite

func (*BaseModel) IRowsToFieldsMI

func (this *BaseModel) IRowsToFieldsMI(irows []IRow) *FieldsMultiInsert

func (*BaseModel) Insert

func (this *BaseModel) Insert(fields IFields) int

func (*BaseModel) InsertOrUpdate

func (this *BaseModel) InsertOrUpdate(fields IFields) int

func (*BaseModel) LastSql

func (this *BaseModel) LastSql() string

func (*BaseModel) MultiInsert

func (this *BaseModel) MultiInsert(fields IFields) int

func (*BaseModel) PartitionKey

func (this *BaseModel) PartitionKey() []string

func (*BaseModel) Read

func (this *BaseModel) Read(irow IRow) bool

func (*BaseModel) ReadMulti

func (this *BaseModel) ReadMulti(result []IRow, cond IRow) bool

func (*BaseModel) Remove

func (this *BaseModel) Remove(irow IRow) int

func (*BaseModel) Save

func (this *BaseModel) Save(irow IRow) int

func (*BaseModel) SaveMulti

func (this *BaseModel) SaveMulti(irows []IRow) int

func (*BaseModel) Select

func (this *BaseModel) Select(condition ICondition, appends IAppends, fields IFields) bool

func (*BaseModel) TableName

func (this *BaseModel) TableName(elems ...ISqlElem) string

func (*BaseModel) Update

func (this *BaseModel) Update(fields IFields, condition ICondition) int

type ColumnInfo

type ColumnInfo struct {
	// contains filtered or unexported fields
}

type Condition

type Condition struct {
	// contains filtered or unexported fields
}

func NewConds

func NewConds() *Condition

func NewCondsOr

func NewCondsOr() *Condition

func (*Condition) AddConds

func (this *Condition) AddConds(c ICondition) *Condition

func (*Condition) Between

func (this *Condition) Between(column string, start, end interface{}) *Condition

func (*Condition) Columns

func (this *Condition) Columns() []string

func (*Condition) Del

func (this *Condition) Del(key string) bool

func (*Condition) Equal

func (this *Condition) Equal(column string, value interface{}) *Condition

func (*Condition) Get

func (this *Condition) Get(key string) (value interface{}, exist bool)

func (*Condition) GetSql

func (this *Condition) GetSql() string

func (*Condition) In

func (this *Condition) In(column string, elements ...interface{}) *Condition

func (*Condition) InitWithMap

func (this *Condition) InitWithMap(condMap map[string]interface{}) *Condition

func (*Condition) InitWithSlice

func (this *Condition) InitWithSlice(columns []string, values []interface{}) *Condition

func (*Condition) Like

func (this *Condition) Like(column string, value string) *Condition

func (*Condition) Op

func (this *Condition) Op(column string, value interface{}, op string) *Condition

func (*Condition) Values

func (this *Condition) Values() []interface{}

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func (*Conn) Begin

func (this *Conn) Begin() error

func (*Conn) Close

func (this *Conn) Close() error

func (*Conn) Commit

func (this *Conn) Commit() error

func (*Conn) Exec

func (this *Conn) Exec(query string, args ...interface{}) int

func (*Conn) Prepare

func (this *Conn) Prepare(query string) *sql.Stmt

func (*Conn) Query

func (this *Conn) Query(query string, args ...interface{}) (columns []string, rrows []RawRow)

func (*Conn) Rollback

func (this *Conn) Rollback() error

type ConnConfig

type ConnConfig map[string]map[string]string

type ConnInfo

type ConnInfo struct {
	// contains filtered or unexported fields
}

func NewConnInfo

func NewConnInfo(ci map[string]string) (c *ConnInfo)

func (*ConnInfo) BindMap

func (this *ConnInfo) BindMap(ci map[string]string)

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 ExprEqual

type ExprEqual struct {
	// contains filtered or unexported fields
}

func (*ExprEqual) Column

func (this *ExprEqual) Column() string

func (*ExprEqual) Sql

func (this *ExprEqual) Sql(prepare bool) string

func (*ExprEqual) Values

func (this *ExprEqual) Values() []interface{}

type ExprIn

type ExprIn struct {
	// contains filtered or unexported fields
}

func (*ExprIn) Column

func (this *ExprIn) Column() string

func (*ExprIn) Sql

func (this *ExprIn) Sql(prepare bool) string

func (*ExprIn) Values

func (this *ExprIn) Values() []interface{}

type ExprLike

type ExprLike struct {
	// contains filtered or unexported fields
}

func (*ExprLike) Column

func (this *ExprLike) Column() string

func (*ExprLike) Sql

func (this *ExprLike) Sql(prepare bool) string

func (*ExprLike) Values

func (this *ExprLike) Values() []interface{}

type ExprOp

type ExprOp struct {
	// contains filtered or unexported fields
}

func (*ExprOp) Column

func (this *ExprOp) Column() string

func (*ExprOp) Sql

func (this *ExprOp) Sql(prepare bool) string

func (*ExprOp) Values

func (this *ExprOp) Values() []interface{}

type Field

type Field struct {
	// contains filtered or unexported fields
}

type FieldsMultiInsert

type FieldsMultiInsert struct {
	// contains filtered or unexported fields
}

func NewFieldsMultiInsert

func NewFieldsMultiInsert() *FieldsMultiInsert

* * MultiInsert

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 IAppends

type IAppends interface {
	GetSql() string
	Values() []interface{}
}

type ICondition

type ICondition interface {
	GetSql() string
	Columns() []string
	Values() []interface{}
	Get(key string) (value interface{}, exist bool)
	Del(key string) bool
}

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

func NewMysqlConn(ci *ConnInfo) IConn

type IFields

type IFields interface {
	GetSql() string
	Columns() []string
	Values() []interface{}
	Get(key string) (value interface{}, exist bool)
	Del(key string) bool
}

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 ISqlElem

type ISqlElem interface {
	GetSql() string
	Columns() []string
	Values() []interface{}
	Get(key string) (value interface{}, exist bool)
	Del(key string) bool
}

type ISubExpr

type ISubExpr interface {
	Sql(prepare bool) string
	Values() []interface{}
	Column() string
}

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

type MysqlConn

type MysqlConn struct {
	Conn
}

type RawRow

type RawRow [][]byte

type TableInfo

type TableInfo struct {
	// contains filtered or unexported fields
}

func (*TableInfo) Columns

func (this *TableInfo) Columns() []string

func (*TableInfo) Negligible

func (this *TableInfo) Negligible() []string

插入时可以忽略的键

Directories

Path Synopsis
* * sql builder for mysql
* * sql builder for mysql

Jump to

Keyboard shortcuts

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